Repository navigation
fix: admit hard-linked commands outside workload write grants - #347
Conversation
## Problem Box refuses operator-writable commands with multiple hard links, including npm-installed Bun and hard-linked Rustup proxies. Those names can be safe when no workload can write them. Removing only the count check would let a workload change a command through another name and reuse its tool grants. ## Solution On macOS, inspect every native write grant for these command identities. Refuse an alias, an unreadable or changed directory, or an inspection above the entry or depth limit. Check hosted directory mutations with the same inspection so a workload cannot import a preexisting alias. Retain the command path, descriptor identity, ownership, mode, and link-count checks. The operator approved macOS write-reach-based admission on 2026-11-06. This changes configured-command admission and broker mutation refusals. No configuration fields, stored records, or protocol shapes change. Linux retains its current multiple-link rejection. The scope remains command[0]; unrelated outside processes and command dependencies are not frozen. Update the user and design references with the scan limits. ## Tests The full workspace ran through scripts/test-all.sh. Its initial exit was 1: seven Box library and two macos_file_enforcement cases used a synthetic home under the runtime metadata grant. Correcting only TMPDIR passed both complete unchanged test binaries: 779 and 3 tests. Every other workspace target passed, including box_shell (72), profile_conformance (71), and site_manifest (27). All-feature builds passed. Workspace Clippy passed with the repository lint allowances, and formatting passed. Clippy required a test-only 0 to 0o0 permission literal correction; all five scanner tests passed after it. No-default-feature builds passed with one dead_code warning for render_profile in unchanged containment code. The deterministic suite was GREEN: 129 passed, 12 declared Linux exclusions, zero failures or errors, and all 141 expected cases recorded. Linux ARM64 all-target checking and all nine configured-command unit regressions passed on the unchanged production snapshot, without runtime skips. Workspace prerequisite skips were operator-home Python, operator-home Node, the credential daemon, and non-UTF-8 filenames. Existing ignored tests stayed ignored. These checks do not establish signed-release qualification. linked_commands_are_admitted_only_outside_every_writable_tree and linked_commands_refuse_metadata_and_link_count_changes_before_launch pin admission and launch checks. a_command_alias_in_any_native_write_grant_refuses_before_the_agent_starts covers agent, tool, and local server grants. native_operations_cannot_import_a_command_alias_but_can_link_cache_files, hosted_links_cannot_import_a_configured_command_alias, and hosted_moves_cannot_import_a_directory_containing_a_command_alias pin import refusals beside ordinary file-operation controls. The linked command Shell and Monty tests preserve the executable through both names. An independent mutation check removed the recursive broker guard. The nested-alias and unreadable-directory regressions failed. All three broker regressions passed after restoring and recompiling the candidate. Six contained Bun, bunx, Rustup, Cargo, and rustc version/help probes passed. These do not cover package installation or compilation workflows. The live SDK tutorial was not run: its local project and model credential were absent. Linux does not enable the new admission model.
|
Assessment: Request Changes The macOS admission logic holds for every route I traced. Two things remain. The scan budget probably refuses the install and build caches that Bun and Rustup-proxied Cargo need. And the PR changes the safety basis of a recorded decision without a stated approval. Review Categories
Assumptions and rules checked that held
The scanner refuses every incomplete walk, avoids following symbolic links through |
Apply the approved workload-write protection model on Linux and macOS. Scan every writable tree and broker mutation directory for existing aliases. Permit Linux linkat within writable mounts and pin cross-mount refusals. Add native Linux mount, descriptor, rename, and nested-namespace regressions. Run the configured-command and hosted mutation tests on both platforms. Document the shared rule, platform controls, scan limits, and existing boundaries.
Preserve main's grammar binding and its separate single-link requirement. Reconcile the rewritten reference pages with shared admission and Linux mounts. Keep the grammar regression active on macOS and Linux.
|
Assessment: Comment (re-review at 4cf3e5b) The new Linux work raised no new correctness findings. The scan-budget thread and the refusal-text thread still apply, and the scan-budget limit now applies on Linux as well. The approval is now stated. The stale Assumptions checked at this commit that held
|
|
With rustup's cargo or npm's bun, a workspace over 100,000 entries can't start (directory inspection exceeds 100000 entries). Hosted Shell edits to such folders are refused too. A large node_modules gets there easily, and narrowing the grant isn't an option when the workspace must be writable. Suggestion: skip the scan when the command's own folder holds all nlink names. That folder is already outside every write grant (enclosed_by), and verify() refuses a new link before launch. This covers rustup and npm bun with no scan. The scan and its cap then apply only to names elsewhere, such as bun's shared store. |
Human readable section
Problem: Strands Box selects a tool's executable from the first entry of
commandunder[tool.<name>]inbox.toml. A hard link is another filesystem path to the same file; writes through either path change that file. Onmain, Box refuses startup for executables with multiple hard links if the account running Box may be able to modify them. This blocks some Bun and Rustup installations even when sandboxed processes cannot modify their executable files.Solution: On macOS and Linux, allow these tools after Box checks every directory declared writable for sandboxed processes. No such directory may contain another hard-link path to one of these executables. During a run, Box also checks file operations that could move such a path into a writable directory.
Linux programs inside Box can also create hard links through the operating system within one writable mount: a filesystem view exposed inside the sandbox. Links between separate mounts remain blocked.
Trade-off: Each directory inspection has a 30-second time budget and a depth limit of 128 directory levels. An incomplete inspection during startup prevents Box from starting the run. During a running session, an incomplete inspection causes Box to reject the requested file operation.
Description
For example, this
box.tomlexcerpt selects the Bun executable and passes--versionas its fixed argument:The protection applies to the executable selected by the first list entry. It does not cover scripts supplied only as arguments, libraries, or plugins. Other programs outside Box may still modify the executable.
Before startup, Box inspects directories listed in
writeunder[agent.filesystem], every[tool.<name>.filesystem], and every local[mcp.<name>.filesystem]section. Themcpsections apply to Model Context Protocol (MCP) servers that Box runs locally. Files listed inwriteorwrite_filereceive direct path and file-identity checks.Directory inspections include subdirectories excluded by the
denylist in each section. They do not follow symbolic links. An unreadable entry or a detected directory change makes the inspection fail. The tool's executable, symbolic-link paths to it, and enclosing directories must also remain outside writable permissions.Before each tool launch, Box rechecks the executable's file identity. For files with multiple hard links, it also rechecks the link count, owner, group, and permissions.
During a run, Box checks file requests made through Strands Shell (Box's shell interpreter) and Monty (Box's Python interpreter). These checks reject changes to a tool's executable or enclosing directories. They also reject directory moves that would bring another hard-link path to the executable into a writable directory. Error messages distinguish a protected path, a discovered hard link, and an inspection that could not finish. The last case includes the inspection failure's cause.
The operating system restricts file operations performed directly by sandboxed programs. On macOS, Seatbelt, the operating system's sandbox mechanism, requires the sandbox policy to permit writes to the source of a hard link or rename. On Linux, this PR permits
linkat, the operating-system call that creates a hard link. Protected executables remain on read-only mounts; links and renames cannot cross mount boundaries. Separately configured writable directories remain separate mounts. Read and write permissions for the same directory can share a mount. Strands Shell's own hard-link operation remains blocked, and Monty does not provide one.The inspection budget is independent of the Shell command timeout, including when that timeout is disabled. Box checks elapsed time between filesystem calls and before accepting completion. It cannot interrupt a blocked filesystem call, so an inspection can take longer than 30 seconds before reporting failure. Separate inspections receive separate budgets; the limit does not bound total startup time. Box detects observable directory changes, but scanning does not freeze the filesystem. A file operation can currently inspect the same directory twice, by its requested path and its resolved path. Each inspection receives its own budget.
Tools configured with
[tool.<name>.grammar], which restricts their accepted arguments, bind those rules to the executable file and the name used to call it. Other names follow theshell:spawnprocess-launch policy. This preserves the behavior now onmain; grammars do not impose an additional single-hard-link requirement.Files already open as standard input, output, or error retain the access supplied by the caller. This protection does not cover filesystem views that report different owners for the same underlying file.
Related Issues
Follows #263 and #332.
Type of Change
Bug fix
Testing
The integration was tested on macOS 27.2 arm64 and Amazon Linux 2023 arm64 (kernel 6.12.113), using Rust/Cargo 1.98.1 to build Box. Linux used
EXPERIMENTAL_LINUX_SUPPORT=TRUE. Tested commit c4be43d integratesmainat2aa281d. The recorded compiled snapshot differs from this commit only by a two-line documentation correction.--all-features --no-fail-fast -- --show-output. The macOS run reported four failures across three targets. Individual retries passed both server-response tests and the Shell session test. The remaining policy-history fixture failure is described below. All 799 macOS Box library tests passed.--bun. The real npm-installed Bun/bunx paths retain their shared file. Linux Bun also creates a verified package-cache hard link.The table records the local campaign. GitHub checks passed on merge commit
6b2943206b7b3c271ed7cc3f1feab99031ce9b89, combining this PR's published head with newermainat4268891462bd2d19f385d1f594a1181e813f80a7. Both full workspace test jobs and the final CI Gate passed. Both complete containment jobs passed: Linux recorded 131 passes and ten platform exclusions; macOS recorded 129 passes and 12 platform exclusions. Each accounts for all 141 cases without failures or errors. Lint, packaging, documentation, and the separate CodeQL analysis also passed. These hosted results supplement the retained local failures described below.The informational macOS check of the saved signed-native test record reported that the record is stale. That step is explicitly allowed to fail without failing the job. The full signed native enforcement suite did not run; native adapter, configuration, startup, and receipt-checker tests passed. These results do not refresh that record or establish signed-native qualification.
The macOS policy-history test copies the system
falseexecutable and expects exit code one. The copy is terminated with signal nine. An exact standalone Rust copy-and-rename control reproduces this outside Box; the originalfalseand copiedtruecontrols return their expected codes. The precise macOS cause remains unconfirmed. The local full workspace run is therefore not reported as entirely passing.A separate macOS test-harness cleanup assertion also fails when run alone. It uses the system shell, Python, and sleep, without launching the candidate Box executable; its source matches the integrated
main. It passed the first complete run and failed the second. The second run passed every recorded containment case, but its overall suite status remains red because of this harness failure. Original results and exact retries are retained.The broad Boxy campaign uses revision
8bed3e8570fdf5a2dae29a598e6dd6b624cfadd4, selected from its then-currentmain. Boxy links the Box library, so the campaign used an external Cargo source replacement and verified dependency resolution; settingBOX_ENGINEalone would not select the candidate. Boxy'smainadvanced during testing. Selected tests on newer revision681713edb59c40776b05b07ee8529a042a9e5abcalso passed the Bun and bunx workflows and both executable-protection controls on both platforms. On that newer revision, macOS bunx server initialization and tool listing pass; both pnpx server cases still fail. Two tests of the new inherited-PATH behavior and the Claude settings-import fixture also pass. The newer Linux pnpx and bunx server tests fail before a complete response.On macOS, additional successful workflows include dependency installation with npm and testing with Node, Apple's Git, uv package installation and import, the Cargo CSV-to-JSON fixture, and npm lint/format repair. Seven of nine committed package-launcher tests pass, including npx, bunx, and uvx server initialization and tool listing. Both pnpx server cases fail before a complete response; the cause is unresolved. The fresh macOS Rustup installation in this campaign uses symbolic links. A separate hard-linked Rustup fixture passes its library test but fails to launch
rustdocduring the full Cargo test.All nine Linux package-launcher tests failed after Box startup. npx and pnpx hit Node memory-permission failures; uvx could not persist its cache lockfile. bunx downloaded semver but failed to execute it, while the separate esbuild workflow with
--bunpassed. The four server tests closed their output before complete protocol responses; those causes remain unresolved.On Linux, installing the pinned Rust nightly and running Clippy passes when explicit configuration puts Rustup data inside the workspace and permits its download host. The shipped Cargo configuration treats an external Rustup installation as read-only. A pip installation passes with an existing workspace temporary directory. These are explicit configuration variants, not changes to shipped defaults.
Broader development workflows still fail. Linux Node's executable-memory failure also reproduces with Boxy's original Box dependency. Traced uv and Cargo failures reach operating-system calls that the current sandbox does not permit. macOS Rustup reaches certificate errors. Some macOS dependency and tool-installation commands exceed the default Shell timeout; Boxy rejects the profile key needed to increase it. That execution timeout is separate from this PR's directory-inspection budget. Direct Box replays with only a longer timeout expose later localhost lookup, local listening, and missing archive-tool failures. These replays are not Boxy passes. No additional syscall permission or Boxy configuration interface was added in this PR.
The campaign does not establish that every Boxy workflow works, qualify a signed release, or exercise a live model-agent service. Tests retain their declared platform exclusions and ignored cases. The macOS workspace reports prerequisite skips for an unavailable credential daemon, Node and Python installations outside the operator home, and a filesystem that rejects non-UTF-8 names. Linux reports separate skips for unavailable optional test instrumentation, an unavailable credential daemon, and two script-mutation tests whose launcher helper was built outside the directory searched by the tests. Both later executed and passed with the expected helper layout; the initial skips and targeted results remain separate records. Linux also skips an assertion that the Shell forwarding executable cannot be read; the corresponding write-protection assertions ran. These skipped assertions are not covered by the passing test count. The lint command uses the repository's allowances; builds without default features retain existing platform warnings.
Automated review run 42340133920 checked out the published PR head and completed its analysis without a new correctness finding. GitHub rejected its comment-posting request with HTTP 403, so the run did not publish a comment or formal review. Its description concern referred to superseded text already corrected here. Its repeated-directory-inspection observation concerns existing behavior disclosed above. The completed analysis does not supply formal approval.
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.