Skip to content

fix: admit hard-linked commands outside workload write grants - #347

Merged
opieter-aws merged 5 commits into
mainfrom
feature/macos-hardlink-write-reach
Nov 9, 2026
Merged

opieter-aws merged 5 commits into
mainfrom
feature/macos-hardlink-write-reach

Conversation

@kevin-orellana

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

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: Strands Box selects a tool's executable from the first entry of command under [tool.<name>] in box.toml. A hard link is another filesystem path to the same file; writes through either path change that file. On main, 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.toml excerpt selects the Bun executable and passes --version as its fixed argument:

[tool.bun]
command = ["bun", "--version"]

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 write under [agent.filesystem], every [tool.<name>.filesystem], and every local [mcp.<name>.filesystem] section. The mcp sections apply to Model Context Protocol (MCP) servers that Box runs locally. Files listed in write or write_file receive direct path and file-identity checks.

Directory inspections include subdirectories excluded by the deny list 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 the shell:spawn process-launch policy. This preserves the behavior now on main; 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 integrates main at 2aa281d. The recorded compiled snapshot differs from this commit only by a two-line documentation correction.

Check Result
Full workspace tests Linux passed with --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.
Workspace Clippy and formatting Passed on both platforms using the repository's lint allowances.
Builds All-feature Box and containment builds passed on both platforms. The full Linux workspace build without default features passed; the macOS Box and containment build without default features also passed.
Scripted containment behavior Linux recorded 141 cases: 131 passed, ten macOS-only exclusions, no failures or errors. macOS recorded 141 cases: 129 passed, 12 Linux-only exclusions, no case failures or errors. The overall macOS suite remained red because a separate harness self-test failed; see below.
Grammar integration regression The new test passed on both platforms. It admits a hard-linked executable, applies argument rules to the declared name, and applies process-launch policy to the other name. Restoring either former single-link restriction in isolated Linux source makes this test fail; the original and restored controls pass.
Boxy package workflows Bun installs a dependency, runs a test, builds, and executes its output on both platforms. bunx downloads and runs a package on both; the Linux esbuild case explicitly selects Bun with --bun. The real npm-installed Bun/bunx paths retain their shared file. Linux Bun also creates a verified package-cache hard link.
Protected executable checks through Boxy On both platforms, an existing writable hard link prevents setup before the agent runs. The tested contained programs could not create a new writable hard link to a protected executable or write it directly. File hashes stay unchanged. A Linux hard link within the writable workspace succeeds.

The table records the local campaign. GitHub checks passed on merge commit 6b2943206b7b3c271ed7cc3f1feab99031ce9b89, combining this PR's published head with newer main at 4268891462bd2d19f385d1f594a1181e813f80a7. 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 false executable 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 original false and copied true controls 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-current main. Boxy links the Box library, so the campaign used an external Cargo source replacement and verified dependency resolution; setting BOX_ENGINE alone would not select the candidate. Boxy's main advanced during testing. Selected tests on newer revision 681713edb59c40776b05b07ee8529a042a9e5abc also 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 rustdoc during 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 --bun passed. 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.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

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

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

## 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.
Comment thread crates/box/src/run/commands.rs Resolved
Comment thread docs/design/decisions.md Resolved
Comment thread crates/box/src/run/broker/reach.rs Resolved
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

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
  • Scope / usability: The fail-closed scan limits can trigger on ordinary dependency-cache grants. Finding the command's names in its own directory first would avoid the tree walk for both headline tools.
  • Written rules: The decision entry changes the premise. The open finding in crates/box/AGENTS.md still describes the old admission rule.
  • Observable output: The refusal text changed on Linux and for commands with one link, where no scan runs.
Assumptions and rules checked that held
  • An absent write-grant root never reaches the scan, because judge_filesystem refuses absent grants first.
  • A file-scope write grant on an alias is still refused through the disk_identity match in names.
  • On macOS, Box adds no implicit write cells outside DirectReach (runtime_minimum). Native filesystem policy only restricts.
  • Shell mkdir -p checks with stat before it creates a directory, and rm -r works bottom-up, so broker scans stay small. Monty refuses mkdir(parents=True).
  • Shell and Monty renames approve both sides as mutations, so moving a directory that holds an alias is scanned.
  • Linux admission and verify behaviour are unchanged. A macOS command with several links that this user cannot write takes the old path with no scan.
  • approved: None launches, which skip commands.validate_reach, occur only in tests.

The scanner refuses every incomplete walk, avoids following symbolic links through openat/fstatat, and its tests prove that each guard fires.

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.
@kevin-orellana kevin-orellana changed the title fix: admit hard-linked commands outside macOS write grants fix: admit hard-linked commands outside workload write grants Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

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 crates/box/AGENTS.md finding is waiting for a maintainer's decision.

Assumptions checked at this commit that held
  • linkat stays in one writable mount: links from a command or library on a read-only mount return EXDEV. So do links from a write_protections file, which has its own read-only bind at view.rs:374.
  • Descriptor-based links: linkat from a descriptor (AT_EMPTY_PATH or /proc/self/fd) that points into another mount also returns EXDEV.
  • Nested namespaces: a re-bind in a nested user namespace keeps the locked read-only flag, and the new probe covers the unmount attempts.
  • Legacy link(2): callers on x86_64 don't matter here, because the Linux backend runs only on ARM64 (crates/containment/AGENTS.md).
  • Writable Connect binds: these come only from Box's own broker socket (boundary.rs:599), never from authored grants, so the write-grant scan does not need to cover them.
  • Scan paths on Linux: the host paths the scan walks are the same paths the namespace bind-mounts.
  • Merge with feat(shell): connect the shell to tool grammars #327: ConfiguredCommands::load runs once per run (command/run.rs:200 → judge_with). Grammar-bound tools keep the single-link refusal.

@strands-agents strands-agents locked and limited conversation to collaborators Nov 6, 2026
@opieter-aws

Copy link
Copy Markdown
Contributor

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.

@opieter-aws
opieter-aws disabled auto-merge November 9, 2026 14:49
@opieter-aws
opieter-aws merged commit 04fa0ac into main Nov 9, 2026
25 checks passed
@opieter-aws
opieter-aws deleted the feature/macos-hardlink-write-reach branch November 9, 2026 14:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants