Repository navigation
feat(tools): OS-level sandbox for agent-spawned processes (macOS) - #386
Merged
Merged
Conversation
…belt) First half of the permission-model overhaul: build the enforcement floor. Nothing is wired into the spawn sites yet and no behaviour changes — this commit adds the mechanism and the coverage that the decision layer will later be allowed to rely on. Scope matches Codex's workspace-write: writes confined to the workspace, network denied, reads broad (toolchains need ~/.gitconfig and ~/.cargo). Reading a secret stays possible; the network denial is what stops it leaving. .git and .forge are read-only inside the writable root. Two reasons, not one: git is the recovery mechanism this model leans on for in-workspace damage, and .forge/permissions.toml would otherwise let a confined process widen its own permissions on the next load using an ordinary in-workspace write. Two defects found by writing the enforcement tests rather than trusting the profile text: * Paths were not canonicalised. The kernel resolves symlinks before matching, and /var is a symlink to /private/var, so a deny rule written against an unresolved path silently never fired. The sandbox still started and still blocked other things — only the .git rule was dead. Now every rule is built from the canonical root, and a workspace that cannot be resolved yields no profile at all. * The temp allowance was (subpath "/private/var/folders"), which grants the whole shared per-user tree and made "writes outside the workspace are denied" false for a large part of the filesystem. Replaced with an opt-in, session-scoped scratch directory. Tests: 10 unit tests over the profile (canonicalisation, SBPL rule ordering where last-match-wins makes .git writable if reversed, quote escaping, fail-closed on an unresolvable root) and 10 enforcement tests that spawn real confined processes and assert the kernel refuses. The latter are the replacement for the negative coverage that dies with readonly.rs: `ls | tee`, `cat f | sh` and `cd .. && write` are no longer recognised, they are contained.
Wires the sandbox into both agent shell-spawn paths. This is where behaviour changes: an agent command that escapes the workspace now fails at the kernel rather than succeeding. `sandboxing-followup.md` describes builtins.rs as "the single execution choke point". It is not — `unified_exec` spawns too, and its sessions outlive the turn that started them while `write_stdin` feeds them afterwards. `write_stdin` is in neither `is_shell_tool()` nor `default_shell_hitl_tools()`, so once a session exists the agent writes arbitrary commands into it with no further approval. Confining at spawn closes that structurally: a confined session stays confined regardless of what is later written to it. No amount of command classification could have fixed it, because the approval happens at session start and the dangerous content arrives later. When a host cannot confine, the command still runs here. The rule that a sandbox-less host falls back to asking the user belongs upstream where the permission mode is decided, and lands with mode inference; this commit does not claim it. Tests: three more enforcement tests driving the real `bash` tool — escaping the workspace fails, `.git` stays read-only, and ordinary in-workspace work is unaffected. Note for reviewers: `forge-tui`'s `approving_a_hitl_gated_tool_resumes_the_turn_instead_of_stalling_forever` fails on this machine. It also fails at 7fdb7a0, before any of this work, both standalone and in-suite, and it passes in CI. Pre-existing and unrelated; not caused by the sandbox and not fixed here.
mohitranka
added a commit
that referenced
this pull request
Aug 21, 2026
* feat(tools): OS-level sandbox for agent-spawned processes (macOS Seatbelt) First half of the permission-model overhaul: build the enforcement floor. Nothing is wired into the spawn sites yet and no behaviour changes — this commit adds the mechanism and the coverage that the decision layer will later be allowed to rely on. Scope matches Codex's workspace-write: writes confined to the workspace, network denied, reads broad (toolchains need ~/.gitconfig and ~/.cargo). Reading a secret stays possible; the network denial is what stops it leaving. .git and .forge are read-only inside the writable root. Two reasons, not one: git is the recovery mechanism this model leans on for in-workspace damage, and .forge/permissions.toml would otherwise let a confined process widen its own permissions on the next load using an ordinary in-workspace write. Two defects found by writing the enforcement tests rather than trusting the profile text: * Paths were not canonicalised. The kernel resolves symlinks before matching, and /var is a symlink to /private/var, so a deny rule written against an unresolved path silently never fired. The sandbox still started and still blocked other things — only the .git rule was dead. Now every rule is built from the canonical root, and a workspace that cannot be resolved yields no profile at all. * The temp allowance was (subpath "/private/var/folders"), which grants the whole shared per-user tree and made "writes outside the workspace are denied" false for a large part of the filesystem. Replaced with an opt-in, session-scoped scratch directory. Tests: 10 unit tests over the profile (canonicalisation, SBPL rule ordering where last-match-wins makes .git writable if reversed, quote escaping, fail-closed on an unresolvable root) and 10 enforcement tests that spawn real confined processes and assert the kernel refuses. The latter are the replacement for the negative coverage that dies with readonly.rs: `ls | tee`, `cat f | sh` and `cd .. && write` are no longer recognised, they are contained. * feat(tools): confine bash and exec_command at spawn Wires the sandbox into both agent shell-spawn paths. This is where behaviour changes: an agent command that escapes the workspace now fails at the kernel rather than succeeding. `sandboxing-followup.md` describes builtins.rs as "the single execution choke point". It is not — `unified_exec` spawns too, and its sessions outlive the turn that started them while `write_stdin` feeds them afterwards. `write_stdin` is in neither `is_shell_tool()` nor `default_shell_hitl_tools()`, so once a session exists the agent writes arbitrary commands into it with no further approval. Confining at spawn closes that structurally: a confined session stays confined regardless of what is later written to it. No amount of command classification could have fixed it, because the approval happens at session start and the dangerous content arrives later. When a host cannot confine, the command still runs here. The rule that a sandbox-less host falls back to asking the user belongs upstream where the permission mode is decided, and lands with mode inference; this commit does not claim it. Tests: three more enforcement tests driving the real `bash` tool — escaping the workspace fails, `.git` stays read-only, and ordinary in-workspace work is unaffected. Note for reviewers: `forge-tui`'s `approving_a_hitl_gated_tool_resumes_the_turn_instead_of_stalling_forever` fails on this machine. It also fails at 7fdb7a0, before any of this work, both standalone and in-suite, and it passes in CI. Pre-existing and unrelated; not caused by the sandbox and not fixed here.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
* feat(tools): OS-level sandbox for agent-spawned processes (macOS Seatbelt) First half of the permission-model overhaul: build the enforcement floor. Nothing is wired into the spawn sites yet and no behaviour changes — this commit adds the mechanism and the coverage that the decision layer will later be allowed to rely on. Scope matches Codex's workspace-write: writes confined to the workspace, network denied, reads broad (toolchains need ~/.gitconfig and ~/.cargo). Reading a secret stays possible; the network denial is what stops it leaving. .git and .forge are read-only inside the writable root. Two reasons, not one: git is the recovery mechanism this model leans on for in-workspace damage, and .forge/permissions.toml would otherwise let a confined process widen its own permissions on the next load using an ordinary in-workspace write. Two defects found by writing the enforcement tests rather than trusting the profile text: * Paths were not canonicalised. The kernel resolves symlinks before matching, and /var is a symlink to /private/var, so a deny rule written against an unresolved path silently never fired. The sandbox still started and still blocked other things — only the .git rule was dead. Now every rule is built from the canonical root, and a workspace that cannot be resolved yields no profile at all. * The temp allowance was (subpath "/private/var/folders"), which grants the whole shared per-user tree and made "writes outside the workspace are denied" false for a large part of the filesystem. Replaced with an opt-in, session-scoped scratch directory. Tests: 10 unit tests over the profile (canonicalisation, SBPL rule ordering where last-match-wins makes .git writable if reversed, quote escaping, fail-closed on an unresolvable root) and 10 enforcement tests that spawn real confined processes and assert the kernel refuses. The latter are the replacement for the negative coverage that dies with readonly.rs: `ls | tee`, `cat f | sh` and `cd .. && write` are no longer recognised, they are contained. * feat(tools): confine bash and exec_command at spawn Wires the sandbox into both agent shell-spawn paths. This is where behaviour changes: an agent command that escapes the workspace now fails at the kernel rather than succeeding. `sandboxing-followup.md` describes builtins.rs as "the single execution choke point". It is not — `unified_exec` spawns too, and its sessions outlive the turn that started them while `write_stdin` feeds them afterwards. `write_stdin` is in neither `is_shell_tool()` nor `default_shell_hitl_tools()`, so once a session exists the agent writes arbitrary commands into it with no further approval. Confining at spawn closes that structurally: a confined session stays confined regardless of what is later written to it. No amount of command classification could have fixed it, because the approval happens at session start and the dangerous content arrives later. When a host cannot confine, the command still runs here. The rule that a sandbox-less host falls back to asking the user belongs upstream where the permission mode is decided, and lands with mode inference; this commit does not claim it. Tests: three more enforcement tests driving the real `bash` tool — escaping the workspace fails, `.git` stays read-only, and ordinary in-workspace work is unaffected. Note for reviewers: `forge-tui`'s `approving_a_hitl_gated_tool_resumes_the_turn_instead_of_stalling_forever` fails on this machine. It also fails at 830d372, before any of this work, both standalone and in-suite, and it passes in CI. Pre-existing and unrelated; not caused by the sandbox and not fixed here.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
* feat(tools): OS-level sandbox for agent-spawned processes (macOS Seatbelt) First half of the permission-model overhaul: build the enforcement floor. Nothing is wired into the spawn sites yet and no behaviour changes — this commit adds the mechanism and the coverage that the decision layer will later be allowed to rely on. Scope matches Codex's workspace-write: writes confined to the workspace, network denied, reads broad (toolchains need ~/.gitconfig and ~/.cargo). Reading a secret stays possible; the network denial is what stops it leaving. .git and .forge are read-only inside the writable root. Two reasons, not one: git is the recovery mechanism this model leans on for in-workspace damage, and .forge/permissions.toml would otherwise let a confined process widen its own permissions on the next load using an ordinary in-workspace write. Two defects found by writing the enforcement tests rather than trusting the profile text: * Paths were not canonicalised. The kernel resolves symlinks before matching, and /var is a symlink to /private/var, so a deny rule written against an unresolved path silently never fired. The sandbox still started and still blocked other things — only the .git rule was dead. Now every rule is built from the canonical root, and a workspace that cannot be resolved yields no profile at all. * The temp allowance was (subpath "/private/var/folders"), which grants the whole shared per-user tree and made "writes outside the workspace are denied" false for a large part of the filesystem. Replaced with an opt-in, session-scoped scratch directory. Tests: 10 unit tests over the profile (canonicalisation, SBPL rule ordering where last-match-wins makes .git writable if reversed, quote escaping, fail-closed on an unresolvable root) and 10 enforcement tests that spawn real confined processes and assert the kernel refuses. The latter are the replacement for the negative coverage that dies with readonly.rs: `ls | tee`, `cat f | sh` and `cd .. && write` are no longer recognised, they are contained. * feat(tools): confine bash and exec_command at spawn Wires the sandbox into both agent shell-spawn paths. This is where behaviour changes: an agent command that escapes the workspace now fails at the kernel rather than succeeding. `sandboxing-followup.md` describes builtins.rs as "the single execution choke point". It is not — `unified_exec` spawns too, and its sessions outlive the turn that started them while `write_stdin` feeds them afterwards. `write_stdin` is in neither `is_shell_tool()` nor `default_shell_hitl_tools()`, so once a session exists the agent writes arbitrary commands into it with no further approval. Confining at spawn closes that structurally: a confined session stays confined regardless of what is later written to it. No amount of command classification could have fixed it, because the approval happens at session start and the dangerous content arrives later. When a host cannot confine, the command still runs here. The rule that a sandbox-less host falls back to asking the user belongs upstream where the permission mode is decided, and lands with mode inference; this commit does not claim it. Tests: three more enforcement tests driving the real `bash` tool — escaping the workspace fails, `.git` stays read-only, and ordinary in-workspace work is unaffected. Note for reviewers: `forge-tui`'s `approving_a_hitl_gated_tool_resumes_the_turn_instead_of_stalling_forever` fails on this machine. It also fails at bec9575, before any of this work, both standalone and in-suite, and it passes in CI. Pre-existing and unrelated; not caused by the sandbox and not fixed here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First half of the permission-model overhaul (
docs/permission-model-overhaul.md): build the enforcement floor. Nothing is deleted yet — per the plan's mandatory ordering, the sandbox must be enforced by default beforereadonly.rsgoes, never the reverse.What it does
Confines agent-spawned shells with Seatbelt on macOS. Scope matches Codex's
workspace-write:.git/.forge~/.gitconfig,~/.cargoReads being broad is deliberate, and pinned by a test so it stays visible: a secret can be read, and the network denial is what stops it leaving.
.git/.forgeare read-only for two reasons, not one. Git is the recovery mechanism this model leans on for in-workspace damage — and.forge/permissions.tomlwould otherwise let a confined process widen its own permissions on the next load using nothing but an ordinary in-workspace write, which this model permits by design.Two defects the enforcement tests caught
Both were invisible in the profile text and only showed up when spawning real processes.
Paths were not canonicalised. The kernel resolves symlinks before matching, and
/var→/private/var, so(deny file-write* (subpath "/var/…/.git"))silently never fired. The sandbox still started and still blocked other things — only the.gitrule was dead. Now every rule is built from the canonical root, and an unresolvable workspace yields no profile at all.The temp allowance was
(subpath "/private/var/folders")— the whole shared per-user tree, making "writes outside the workspace are denied" false across a large part of the filesystem. Replaced with an opt-in, session-scoped scratch directory.builtins.rsis not the single choke pointsandboxing-followup.mdsays it is. It isn't —unified_execspawns too, and its sessions outlive the turn whilewrite_stdinfeeds them.write_stdinis in neitheris_shell_tool()nordefault_shell_hitl_tools(), so today, once a session is approved, the agent writes arbitrary commands into it with no further approval. Command classification can never fix that: approval happens at session start, dangerous content arrives later. Confining at spawn closes it structurally.Tests
.gitbecomes writable if the deny is emitted before the allow), quote/backslash escaping, fail-closed on an unresolvable root.cd ..denied,.gitand.forgeread-only, network denied, broad reads permitted, in-workspace destruction permitted by design, and the realbashtool confined.The enforcement tests are the planned replacement for the negative coverage that dies with
readonly.rs.ls | tee out,cat f | sh,cd .. && writeare no longer recognised — they are contained. That is the whole point: the guarantee stops depending on parsing a shell command.Not in this PR
readonly.rsdeletion.Pre-existing local failure
forge-tui'sapproving_a_hitl_gated_tool_resumes_the_turn_instead_of_stalling_foreverfails on my machine. It also fails at7fdb7a0— before any of this work — both standalone and in-suite, and it passes in CI. Bisected, not caused here, not fixed here. Worth its own issue: it's environment-dependent and I could not root-cause it (ruled out userpermissions.toml,~/.config/forge, andFORGE_*env vars).Otherwise
cargo fmt --all -- --check,cargo clippy --all-targetsandcargo test --workspaceare clean — that one test is the only failure in the workspace.