Skip to content

fix: verify approved directories during Linux sandbox launch - #264

Merged
kevin-orellana merged 10 commits into
mainfrom
feature/pin-execution-directory-grants
Nov 17, 2026
Merged

kevin-orellana merged 10 commits into
mainfrom
feature/pin-execution-directory-grants

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem. Box can run a program from a replacement directory on Linux even though it approved a different directory for that launch. Box first selects the files and directories the program may access. A separate launch helper then creates the Linux sandbox. If another process replaces a directory at the same path between those steps, the helper can use the replacement. The launch configuration does not need to change.

Solution. Box keeps the approved files and directories open and passes their identifiers to the launch helper. Before creating the sandbox, the helper checks that each allowed path still names the approved file or directory. If a path names a replacement, the helper rejects that launch before the program starts.

Trade-off. Box holds those open references until the launched process exits. Each later launch can select the directory then present, subject to existing checks. This change does not freeze directory contents or protect operator-authored configuration from an agent that can edit it.

Description

In Box's box.toml, the exec list under [agent.filesystem] names executable files or directories available for execution inside the agent's sandbox. Consider an entry that names the illustrative directory /tools:

  1. Box prepares a launch and approves the directory currently at /tools.
  2. Another process moves that directory aside and puts a different directory at /tools before the launch helper loads its configuration.
  3. Without this fix, the helper can load the replacement. With this fix, it rejects that launch before the requested program starts.

A later launch prepares its access separately. It can select the replacement directory if the existing checks permit it. The directory replacement operation itself is not blocked by this change.

Figure 1: Box checks the directory again before starting the program. A replacement after approval stops that launch; a later launch can approve the replacement.

During one Linux sandbox launch, Box approves directory A at /tools. Another process replaces it with directory B before the launch helper loads the configuration. The helper detects the different directory and rejects the launch before the program starts. A later launch can approve directory B and start a sandboxed program if existing checks permit it.

Editable diagram source

How the check works

Linux identifies a file or directory by its filesystem device, inode number, and type. The inode number identifies an object within that filesystem. Box includes these values in the access configuration sent to the helper, and the helper compares them with the file or directory it opens. Keeping the original references open prevents Linux from reusing their identifiers during this handoff.

The check applies to allowed filesystem access. Existing checks for configured tool programs and denied paths remain in place.

Compatibility

The Linux helper configuration gains an identity field containing those identifiers. Existing configurations without the field retain their previous behavior: they select the file or directory present when loaded. Older helpers reject the added field, so the containment library and launch helper must come from the same build. The existing interface approval covers this field and requirement. This revision adds no public Rust types or methods.

Related Issues

Supersedes #201. Its six tests for denied executables and their permitted-execution controls remain unchanged.

Type of Change

Bug fix

Testing

Implementation revision: 760d5125b259bde18104fe08e331482e3a3eade5. Its main parent is 6097aed88c4c0e0a3f115efc40ad2b0e0c100c64. The diagram assets are published separately at 2b48a9073d0983d85a38e72c262b2518455202d4; this description update does not change the PR’s implementation or tests.

Check Result
Controlled reproduction On baseline 1d5cb05, the replacement program ran despite unchanged launch-configuration bytes. With the fix, that launch stops before execution. An unchanged directory and a replacement approved for a new launch both work.
Focused tests All 15 execute and pass on Amazon Linux 2023 ARM64: five configuration-loading tests, one open-reference lifetime test, three production-helper launch tests, and six tests preserved from #201.
Full workspace The local run passes with --locked --all-features --no-fail-fast -- --show-output. Hosted Linux and macOS workspace jobs also pass.
Deterministic containment suite The local Linux run records all 141 expected cases: 131 pass and 10 have declared macOS-only exclusions. There are no failures, errors, or cases excluded for known failures. The hosted Linux and macOS jobs also pass.
Build, lint, and formatting All-targets/all-features and no-default-features builds pass. Formatting and Clippy pass with the repository CI commands and documented allowances.
Review Independent source review and the automated review of 760d512 found no blocking issues. Formal maintainer approval remains required.
Diagram Source checks and visual inspection pass at full size and review width. The pinned draw.io renderer reproduced the repository control image exactly.

The Linux workspace reports two documented runtime omissions: the optional service that supplies credentials was unavailable, and one file-read protection assertion was omitted while its write-protection assertions ran. The check for unexpected test skips passes. None of the 15 focused tests skips; tests declared ignored remain separate.

The production-helper tests control the replacement timing directly. They do not prove that an agent can cause the replacement under a particular operator policy. Both permitted-launch cases run inside the sandbox and cannot read a test file outside their allowed paths.

scripts/test-all.sh box-examples rebuilds the candidate but reports that no scripted examples remain. The live SDK tutorial was not run.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran formatting and Clippy with the repository CI commands and documented allowances above.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Codex implemented and reviewed this change at Kevin's request, including independent source and documentation review. These attestations describe that delegated work; they do not claim formal maintainer approval.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

The complete workload route lacks regression tests for execution after a denied directory moves.
Existing identity checks already refuse that route.

## Solution

Add six production tests for directory replacement, missing names, symbolic links, and scripts with listed or unlisted interpreters.
Check execution markers, file identities, permitted execution, and unrelated renames.
Use the existing prerequisite probe to report unsupported Linux execution platforms explicitly.
Production code and public interfaces remain unchanged.

## Tests

All six denied_executable tests executed and passed on Amazon Linux 2023 ARM64 before the prerequisite probe addition.
Workspace lint passed with the repository's vendored allowances, and cargo fmt --all passed.
Independent review found and verified the prerequisite probe correction.
The full workspace suite and deterministic suite are running for the final source.
macOS execution remains pending hosted validation.
Earlier mutation evidence on e0af331 showed three actual executions when the denial identity check was disabled.
The other three variants retained overlapping refusals.
## Problem

An allowed rename could replace an execution-granted directory after Box
approved it. Later launches could then run a replacement program at that
pathname. Independently prepared nested mounts could also select objects
outside the retained execution directory.

## Solution

Retain each execution directory's approved identity throughout the run.
Reuse its prepared reference, validate identity across Linux helper
serialization, and bind nested objects through the checked directory.
Preserve supported aliases and document recovery and platform limits.

## Tests

Add production regressions for directory and ancestor replacement, plus
identity-lifetime, helper-loading, nested-mount, and alias controls.
Both production cases fail on unmodified main and pass after this change.
Formatting, lint, all-target/all-feature and no-default builds pass.
Deterministic acceptance: 124 pass, 9 macOS-only skips.
Workspace: 4612 pass, 1 initial catalog timing failure, 17 ignored.
The original timing test passes its focused rerun; the initial failure
remains documented and unexplained.
@kevin-orellana kevin-orellana changed the title Retain execution directory identity across launches fix: retain execution directory identity across launches Nov 2, 2026
Comment thread docs/user/shell.md Resolved
Comment thread crates/containment/src/model.rs Resolved
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Request Changes

Keeping the directory identity closes the case the tests cover. Two cases with the same cause stay open or newly break: exec file entries, and directories that get deleted and rebuilt. The PR also changes a frozen containment surface without recording approval.

Review Categories
  • Correctness / scope: The pin covers only Exec + Root. A file exec entry still accepts a replacement through an ancestor rename. I reproduced this with a temporary unit test against require_judged_identities and ContainmentConfig::from_json.
  • Operator impact: The refusal lasts for the whole run and covers every launch that uses the [agent] lists. The recovery the docs give ("restore the original") cannot work after cargo clean or npm ci.
  • Frozen surface: PreparedFilesystemPath: Clone and the trampoline wire field are visible additions under crates/containment/AGENTS.md.
  • Not run here: This runner blocks user namespaces, so the execution_directory.rs integration tests skip. My findings come from unit-level probes.

Assumptions and rules checked that held:

  • Symlinked or non-canonical exec entries are refused before the pin, so metadata is the resolved directory's.
  • MCP tables (approved: None) are judged again at each launch, so the pin does not apply to them stale.
  • Other authorizing grants are prepared fresh at each launch, so the identity they now carry on the wire matches unless a race occurs. This fails closed.
  • Denials keep their wire shape (a_serialized_denial_keeps_its_existing_shape).
  • A legacy config without identity still loads.
  • No deny-only floor or premise in root AGENTS.md is weakened.

The tests run the real replacement end to end and check that it is refused.

@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 2, 2026 03:00
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review of e79b5b3)

Since 23e4706, the follow-up changes the recovery hint in require_judged_identities and the docs, and nothing else. The deleted-and-rebuilt finding is resolved, and the file-entry gap is now a documented scope limit. The one open item is confirming approval for the façade change. That needs a human, not a code change.

What I checked in the follow-up
  • Recovery hint: I checked every case that reaches the hint. It appears only when execution_directory.is_some(). That covers a replaced directory, a deleted directory (cannot be read), and a directory that became a symlink or a file. A file exec entry and non-exec grants get no hint, which is correct because they have no pin.
  • Docs: shell.md, config.md, and containment.md now name cargo clean and npm ci, say that the refusal covers launches under unchanged entries, and give restart as the recovery when the original is gone. That matches what the code does.
  • Tests: The judged and filesystem unit tests pass locally (3 and 17). No test asserted the old message text. The integration tests skip here because this runner blocks user namespaces.

Rules checked that held: the new hint is attached only where a pin exists; the docs no longer suggest that file entries are covered; and the follow-up adds no new public API or wire change.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review of a25b98d)

Since e79b5b3, the only change is the new file crates/box/tests/denied_executable.rs. I checked that it is byte-for-byte identical to #201's 032773d, and #201 is now closed. It adds no production, wire, or doc change, and I found no new defect. The open item is unchanged: a human needs to confirm the façade addition (PreparedFilesystemPath: Clone and the trampoline identity field).

What I checked in the consolidation
  • Interaction with the new pin: The six cases move tools/denied, a deny entry inside the exec directory tools. They never replace tools itself. So the new execution-directory check passes, and the existing refusals loop in require_judged_identities produces the refusal. The "was replaced" and "cannot be read" assertions therefore still check the denied-path guard, not this PR's new code, as the description says.
  • Recovery hint: The hint appears only for execution-directory grants. A relocated deny entry gets the older refusal text with no hint. That matches the current docs, which describe recovery only for exec directories.
  • Local run: Both denied_executable (6) and execution_directory (2) compile and report ok. They finished in 0.00s because this runner blocks user namespaces, so they skipped. Hosted Linux runs are still the only evidence that the tests actually execute.

Rules checked that held: the consolidated file matches the reviewed #201 revision; no frozen surface changes beyond the one already under discussion; the file-entry follow-up correctly goes through private reporting under SECURITY.md.

@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 2, 2026 06:03
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review of c78c555)

Since a25b98d, the only change is the two-line platform-scope note at the top of docs/design/containment.md. It is correct, and I found no new defect. The open item from earlier is unchanged: a human needs to confirm the façade addition (PreparedFilesystemPath: Clone and the trampoline identity field).

What I checked in the scope note

The new rule is: "Unless a section explicitly states Linux behavior, this page describes … macOS." I checked each section that mentions Linux against it:

  • Execution directories: The section says "On Linux, …" (line 151), so the Linux launcher checks fall under the exception. The file-entry limit in that section is stated without a platform, which correctly covers both.
  • Dependency-read startup design: The section says "on macOS and Linux" (line 226). The old note said only the execution-directories section covered Linux, which contradicted this section. The new wording removes that contradiction.
  • The runtime minimum: The section names both os-paths.*.json files, one per platform, so the exception applies here too.
  • Anchors: No heading changed, so the inbound links from docs/user/*.md and docs/design/*.md still resolve.

Rules checked that held: the note matches every section that names Linux; the change adds no code, wire, or API change; and the doc still marks the file-entry gap as out of scope.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review of 7ad625d, merge of main 8e09fdf)

I checked the merge resolution and found no new defect. Only crates/containment/src/backend/linux/namespace/view.rs needed a manual conflict fix. The other four files that both sides changed (boundary.rs, containment/README.md, docs/design/containment.md, docs/user/config.md) are identical to a plain git merge of the two parents. The open item is unchanged: a human needs to confirm the façade addition (PreparedFilesystemPath: Clone and the trampoline identity field).

What I checked in the bind arm of the resolved establish

Each row is a case that reaches the merged bind arm:

  • Grant outside any execution directory: Uncovered leads to main's path unchanged: mount on target_pin, check the mounted identity, then pin_execution_directory returns None.
  • Nested grant pinned through a retained directory: The new pre-mount require_grant_identity(&target_pin.path(), …) requires main's descriptor target and the PR's openat target to be the same object. The mount goes to the execution-target fd, and require_new_mount runs against target_pin. If the two targets differ, the launch is refused (fails closed). After the mount, both the identity and the covering execution directories are checked again.
  • PreservedLink: Before the merge this returned early. It now continues into main's canonical-alias check, so a linked spelling is mounted separately only when the canonical bind's modes don't cover it. The PR description's "permission checks for canonical aliases" says this.
  • Removed enclosed_by_a_bind early return: Main's walk-based prepare_bind now handles a symlinked mountpoint. A symlink inside an execution directory still goes through pin_execution_target.
  • Main's intermediate-alias write grants inside an exec tree: Neither side tested this combination. I ran a temporary copy of permitted_intermediate_alias with the tree also granted Exec/Root, covering the file, directory, and linked-tree variants. All three establish and write correctly. The probe is reverted.

Local evidence (x86_64, with user namespaces enabled for this run): containment lib tests gave 460 passed and 1 failed. The failure is allow_all_joins_the_host_network…, which fails the same way on main 8e09fdf. That run includes the PR's nested execution-grant tests and main's nested_grants/alias tests in a real namespace. The crates/box integration tests and contains_exec_target_linux still skip or refuse here because the backend supports only aarch64, so hosted ARM64 results remain the evidence for those.

Rules checked that held: the resolution keeps main's descriptor targets, alias checks, and mount-location checks, plus the PR's execution-directory pinning; and the merge adds no public API or wire change beyond the one already under discussion.

## Problem

A Linux launch can prepare one filesystem object and load a replacement
at the same path. The serialized launch configuration need not change.
Pinning an execution directory for the entire Box run also rejects later
launches after an intentional replacement.

## Solution

Carry each Linux grant's recorded identity through the launcher handoff.
Keep the originating configuration with the process boundary, so its open
references prevent object identifier reuse while the helper loads grants.
Each new launch prepares the current object. Remove startup-directory
retention and its extra nested-mount checks. Keep existing configured-command
and denied-path guards, including the six unchanged regressions from PR201.

The previously approved Linux identity wire field remains. Older helpers
reject that field, so the library and helper must come from the same build.
The change adds no public Rust types or methods and does not freeze contents.

## Tests

On Amazon Linux 2023 ARM64, the baseline fails
`a_directory_replaced_after_approval_is_refused_before_execution` and the
fixed candidate passes. Both valid-launch controls pass on both revisions,
including `a_replacement_approved_for_a_new_launch_runs_contained`.

The baseline fails
`a_boundary_keeps_unlinked_grants_open_until_it_drops`; the candidate passes
in a 687-test Box library run with no skips. The two new grant-loading
mismatch tests likewise fail on baseline and pass with the repair.

The all-features workspace suite, 27 site-manifest tests, repository lint
and format gates, and both feature-set builds pass. Deterministic containment
passes 131 applicable cases with nine declared macOS-only exclusions.
The no-default build's 66 warning identities match baseline exactly.
Documented workspace ignores and Linux limits remain; the missing alias
helper prerequisite was installed before the final Box library rerun.
The examples runner finds no scripted examples; no live SDK tutorial ran.
Current-head hosted macOS validation remains for CI after publication.
@kevin-orellana kevin-orellana changed the title fix: retain execution directory identity across launches fix: preserve filesystem grant identities during Linux launches Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review of dd16343). No blocking findings.

This head is a merge of main 1d5cb05 that also changes the design. Compared with a plain auto-merge of 7ad625d and 1d5cb05, it removes the startup execution-directory retention, the nested execution-target checks in view.rs, and execution_directory.rs. What remains against main is small: boundary.rs keeps the ContainmentConfig alive, model.rs adds the wire identity and its load-time check, plus the new aarch64 test and docs. The earlier findings no longer apply on this head: run-wide refusal after cargo clean/npm ci, file-exec scope, and the PreparedFilesystemPath: Clone façade addition. The wire field is the one covered by the linked approval record.

Cases checked against the new TryFrom<PathGrantWire> identity check
  • Unchanged object: identities match and the grant loads.
  • Replaced between Boundary::translate and trampoline load: refused with a config-validation error before apply.
  • Later launch after a deliberate replacement: every launch path prepares fresh grants. That covers the agent (command/run.rs), tool spawns (hosted.rs), and MCP (host.rs, where prepare and spawn run in one call with only a synchronous policy decision between them). The new object is selected, which matches the docs.
  • Identifier reuse during the handoff: the parent's O_PATH|O_CLOEXEC pins stay open through _containment for the Boundary lifetime (Contained::_boundary and the leaf supervisors). pin.release() in view.rs runs only in the trampoline's own process.
  • Mount namespace at load: contain_trampoline/main.rs calls from_json before any unshare, so it reads the same paths the parent prepared.
  • Legacy wire without identity: binds the object present at load (a_legacy_grant_without_identity_binds_the_object_present_at_load).
  • Denials: the wire shape is unchanged and no identity is emitted.
  • Mismatched helper: PathGrantWire is deny_unknown_fields, so an older trampoline rejects the field instead of skipping the check. This matches the README.
  • Per-process spellings (/proc/self/...): already refused by main's resolved drift check, so this PR adds nothing new there.

Local evidence (x86_64): model::tests passed 5/5 and a_boundary_keeps_unlinked_grants_open_until_it_drops passed. launch_grant_identity_linux.rs is gated to aarch64, so hosted ARM64 is its only evidence. At review time, hosted macOS deterministic, native-filesystem, lint, and packaging checks passed, and both unit-test jobs were still running.

Rules that held: the façade adds no pub items (crates/containment/AGENTS.md); "validate once, then act on the identity you approved" (root AGENTS.md) now extends across the library-to-helper handoff; deny-only floors are unchanged.

@pgrayy's open thread on filesystem.rs asks about the startup-retention design that this head removed. That file has no remaining diff against main, so the thread may be ready to resolve.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review of 760d512). No blocking findings.

760d512 merges main 6097aed into dd16343, which I reviewed earlier. The Rust and test changes match the automatic merge exactly. The only manual change is the docs/design/containment.md conflict resolution, which keeps both the per-launch identity section and main's "Script interpreter grants on Linux" section. The tree is 8603c54, the one the PR description says was tested. denied_executable.rs and launch_grant_identity_linux.rs are byte-identical to dd16343. (Correction to my previous summary: denied_executable.rs, the #201 carry-over, was already in this PR's diff against main, and I left it out of the file list.)

Interactions with main that I checked

Local evidence (x86_64): model::tests passed 5/5, and a_boundary_keeps_unlinked_grants_open_until_it_drops passed once the adjacent workspace bins were built. On this head, Boundary::translate needs both strands-box-contain-trampoline and strands-box-sock-alias installed beside the test binary. The aarch64-gated launch tests and denied_executable.rs skip on this runner, so hosted ARM64 is their only evidence. At review time, hosted ARM64 and macOS unit-test and deterministic jobs for 760d512 had not finished; all checks passed on dd16343.

Assumptions and rules that held: the per-launch handoff refuses a replaced object and fails closed on a race; denials and legacy configs keep their wire shape; the containment façade adds no pub items; deny-only floors are unchanged.

@kevin-orellana kevin-orellana changed the title fix: preserve filesystem grant identities during Linux launches fix: verify approved directories during Linux sandbox launch Nov 7, 2026
@kevin-orellana
kevin-orellana merged commit c394883 into main Nov 17, 2026
25 checks passed
@kevin-orellana
kevin-orellana deleted the feature/pin-execution-directory-grants branch November 17, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants