safe-fs-tools is a Rust library and CLI for policy-bounded filesystem operations.
It provides read, list_dir, glob, grep, stat, edit, patch, mkdir, write, move, copy_file, and delete with explicit root boundaries, permission gates, deny rules, and resource limits.
- Library operation names use
snake_case(list_dir,copy_file). - CLI subcommands use
kebab-case(list-dir,copy-file).
MSRV: Rust 1.92.0.
The core objective is explicit safety contracts for local file tooling:
SandboxPolicy: what is allowed.Root: where access is anchored.SecretRules: what must be denied or redacted.Limits: how much work is allowed.metadata.policy_meta: optional shared/descriptive metadata, not an enforcement switch insafe-fs-tools.
This project is not an OS sandbox. See SECURITY.md and docs/security-guide.md.
For full documentation (Next.js-docs style structure), start here:
docs/index.md(full portal)docs/getting-started.mddocs/concepts.mddocs/policy-reference.mddocs/operations-reference.mddocs/cli-reference.mddocs/library-reference.mddocs/security-guide.mddocs/deployment-and-ops.mddocs/faq.mddocs/db-vfs.md
- Copy and edit a policy:
cp policy.example.toml ./policy.toml
# then replace <ABSOLUTE_PATH> with a real absolute path- Run help:
cargo run -p safe-fs-tools-cli -- --policy ./policy.toml --help- Read a file:
cargo run -p safe-fs-tools-cli -- \
--policy ./policy.toml \
read --root workspace README.mduse safe_fs_tools::{Context, ReadRequest, RootMode, SandboxPolicy};
let mut policy =
SandboxPolicy::single_root("workspace", "/abs/path/to/workspace", RootMode::ReadOnly);
policy.permissions.read = true;
let ctx = Context::new(policy)?;
let resp = ctx.read_file(ReadRequest {
root_id: "workspace".to_string(),
path: "README.md".into(),
start_line: None,
end_line: None,
})?;
println!("{}", resp.content);
# Ok::<(), safe_fs_tools::Error>(())SandboxPolicy can also carry optional [metadata.policy_meta] fields for cross-tool policy
annotations. In safe-fs-tools they are descriptive only and do not override
[[roots]].write_scope, permissions, or limits.
- Default:
glob,grep,patch - Optional:
policy-io
If a feature is disabled, the operation API remains available but returns Error::NotPermitted.
cargo fmt --all -- --check
cargo check --workspace --all-targets
cargo check -p safe-fs-tools --all-targets --no-default-features
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
./scripts/gate.shEnable hooks once per clone:
git config core.hooksPath githooks