Expand description
Sandboxing primitives for shell commands run by flow-adapter-shell.
The module exposes a capability-declarative API: each shell node carries a
Capabilities struct (network access, write paths, read paths, env
policy). Given a Capabilities plus a cwd, resolve_layer picks the
enforcement strategy the host OS supports, and wrap_command returns a
tokio::process::Command already configured to run under that strategy.
Layers (in increasing order of enforcement):
SandboxLayer::Lightweight- always applied. Pins cwd, scrubs env perEnvPolicy. Output cap and timeout are enforced by the calling adapter (they live closer to the spawn loop).SandboxLayer::MacosSandboxExec- on macOS only, whenCapabilitiescarries non-empty write/read paths ornet == false. Wraps the user command withsandbox-exec -p '<generated SBPL>'. Apple deprecatedsandbox-execbut it still works on macOS 15; the comment block at the top ofbuild_macos_sbplcovers the migration path.SandboxLayer::LinuxLandlock- on Linux when the kernel exposes landlock (5.13+). v1 returns the layer marker so the adapter records it in the audit log; the actualprctl/landlock_create_rulesetsyscalls are wired in a follow-up so we don’t gate the whole build on a Linux-only crate.SandboxLayer::None- Windows, or when capability declarations are absent. The lightweight rails still apply; nothing OS-level enforces the declared capabilities.
See the project docs for the end-to-end story and the sandbox matrix.
Structs§
- Capabilities
- Per-node capability declaration. Defaults match the most permissive
“trust + log” baseline (network on, write to cwd, env scrubbed) so a node
without an explicit
capabilitiesfield still works the same as a manual shell invocation. - Path
Escape - Error returned by
confine_pathwhen a candidate path escapes the workspace root (traversal, absolute path outside the root, or a symlink pointing out). Carries human-readable detail for the adapter’s error.
Enums§
- EnvPolicy
- Environment forwarding policy.
Scrubbedis the default and matches the allow-list used by major sandboxing tools. - Sandbox
Layer - Strategy used to enforce a
Capabilitiesdeclaration on the host.
Functions§
- audit_
log_ path - Audit-log directory:
~/.flow-studio/logs/audit/. Created lazily. - build_
macos_ sbpl - Build a macOS Seatbelt (SBPL) profile string from the declared
capabilities. The profile starts from
(deny default)and grants only whatcapsexplicitly allows. - confine_
path - Confine
candidateto withinroot, returning the resolved absolute path orPathEscapeif it lands outside. - resolve_
layer - Pick the strongest enforcement layer the host supports for these
capabilities. Always returns at least
SandboxLayer::Lightweight. - scrub_
env - Build the env map a child should inherit per the declared policy.
- wrap_
command - Wrap a user-provided command + argv into a
tokio::process::Commandthat is ready to spawn under the resolved sandbox layer. Returns(Command, SandboxLayer)so the caller can record the actual layer in its audit log.