Skip to content

fix: protect Box executables from workload writes - #295

Merged
kevin-orellana merged 3 commits into
mainfrom
feature/trusted-launcher-integrity
Nov 4, 2026
Merged

kevin-orellana merged 3 commits into
mainfrom
feature/trusted-launcher-integrity

Conversation

@kevin-orellana

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

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: A workload with write access to installed Box programs can replace them. Later launches can use the changed programs, including helpers that start the sandbox.

Solution: Protect Box's main executable, containment helper, socket alias helper, and the macOS package wrapper from workload modification. Refuse direct write grants and hosted file operations that can replace these installed programs.

Trade-off: Box refuses write grants that cover its installation, including development trees containing the running build output. Cargo source builds remain supported when Box can account for every hard-link name of the installed programs. The operator owns initial installation contents, updates between runs, and changes from processes outside Box.

Description

The accepted decision extends configured-tool protection to installed Box programs. These programs start containment or route workload operations to its checks. The socket alias runs inside the agent's sandbox. Replacing that alias alone does not demonstrate execution outside the sandbox.

The run retains file identities and opened helper files. It accounts for hard links, which give one file additional names, and verified paths through mounts. Write checks cover the installed names and containing directories. An incomplete inventory or changed identity causes a refusal. Linux executes the retained containment helper through its open file handle. macOS executes a private copy. Alias copies use the opened file and preserve its shared read offset.

An executable regular sibling named box receives package-wrapper protection. A standalone application bundle tolerates an unrelated directory, symbolic link, or nonexecutable sibling with that name. Launch scripts and additional names outside this inventory remain operator responsibilities. This decision does not add blanket protection for customer launch settings.

Executable-format checks and the public build marker identify the expected artifact kind. They do not authenticate initial contents. No command-line vocabulary, configuration keys, stored-record shapes, broker protocol, or public crate interfaces change.

Related Issues

No public issue linked.

Type of Change

Bug fix

Testing

Tested revision: 4f41d7f0d88245acca29c48479d8c0a7503bb11f, based on 67e378ae16f2a8457a6b856228343086f404e743. Local validation used Amazon Linux 2023 ARM64 and macOS 27.2 ARM64. Both platforms match all 23 changed source files in manifest 5ffd15b50dcf8ec248d09831d95cea409c37738e38839309671da47865a8b75e.

Check Result
Linux Box package, all features Passed: 1,183 top-level passes, zero failures, six declared ignores, and the separate custom harness. Nested child results are excluded.
macOS Box package, all features Passed: 1,169 top-level passes, zero failures, five declared ignores, and the separate custom harness. Two nested child results are excluded.
Local installation regressions Passed: all eight Linux and all 12 macOS product cases, without skips. Twenty-one installation units passed on each platform.
Build, format, Clippy, and optional-feature build Required package gates passed on both platforms. Linux also passed its no-default-feature build and the prescribed workspace format and Clippy recipes. Warning qualifications appear below.
Local Linux deterministic containment GREEN: all 140 case rows recorded, 131 passed, nine declared macOS-only skips, zero failures or errors, and no quarantine. Both harness and verdict commands passed.
Documentation site manifest Passed: 27 manifest tests on each platform. Independent review found no prose defect in the changed guides.
Shipped examples and live Strands Python tutorial Example build passed. The live tutorial permitted a README read and denied a synthetic secret-file read. Both agent runs exited successfully. Its isolated binaries match the current production build.
Independent source and documentation review SHIP: independent review found no source, documentation, or local-gate blocker. Every committed file matches its tested source hash.
Hosted workspace tests, all features Passed: Linux recorded 4,932 top-level passes, zero failures, and 17 declared ignores. macOS recorded 4,567 passes, zero failures, and 16 ignores. Each platform completed 149 counted targets and the separate custom harness. Nested child passes are excluded: one on Linux and three on macOS.
Hosted deterministic containment GREEN on both platforms. Linux recorded 131 passes and nine declared macOS-only skips. macOS recorded 128 passes and 12 declared Linux-only skips. Each report has all 140 case rows, zero failures or errors, and no quarantine.
Hosted checks and automated review The required gate and platform jobs passed. The automated assessment is Approve, with no new findings. All four review threads are resolved. Formal human approval remains pending.

Hosted source: The hosted test jobs used merge 0160da32f2453e2e68fa81506429d36a3a8d3b72, combining this head with main 1d5cb050d2072727a0dd53e2f11db4854b251615. This merge includes newer test-harness changes from main. All 23 changed files match the locally tested manifest. Automated review checked out the pull request head. The final hosted workspace runs satisfy the suite checklist for this revision.

Tests use legitimate executables and plain, nonexecuted file fixtures. The macOS fixture copies the shipped package layout and uses the wrapper text from scripts/macos-release.py.

The regressions cover:

  • Agent, tool, and local-server write grants against installed programs and their containing directories.

  • Shell and Monty writes, deletion, rename, and replacement, with unchanged-file controls.

  • Cargo hard links, Linux mount paths, and refusal when inventory is incomplete.

  • The macOS package wrapper, readable alias image, and standalone bundles beside unrelated paths.

  • Namespace setup refusals without hiding failures after the Linux mount test starts.

  • Cargo helper freshness when the profile directory and dependency directory contain different helper copies.

  • Alias copies after pathname replacement and reads that preserve a shared file offset.

  • Permitted reads, sibling writes, and operator updates between runs.

  • 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

Clippy qualification: The Rust gate uses the recipes required by CONTRIBUTING.md: just fmt-check and just clippy. Formatting ran in check mode. Clippy used -D warnings with the repository's seven vendored-code allowances. Separate plain package checks reported zero Box-owned warnings and six unchanged Shell warnings on each platform. The checked template line denotes this prescribed gate, not an unqualified bare-command pass.

Existing exclusions: The local package suites retain six declared ignores on Linux and five on macOS. Hosted workspace suites retain 17 on Linux and 16 on macOS. Linux logs retain exclusions for unavailable cardinality instrumentation, the existing alias-read limitation, and an absent credential service. Local macOS excludes absent cardinality instrumentation and filesystem rejection of non-UTF-8 names. Hosted macOS hides successful test output, so that job cannot confirm the absence of runtime skips. The separate native-filesystem job passed but skipped bridge checks, which require the macOS 27 software development kit.

Separate local focused runs executed the installed-alias test on both platforms and the controlling-terminal test on macOS without skips. The native build retains its existing containment render_profile warning. Both Linux build modes retain the 66 existing containment warnings. Hosted workspace build and test logs contain eight warnings from unchanged Shell tests; the prescribed lint job passed.

The earlier revision passed six plain-file unit controls and detected each isolated defect mutation. This follow-up passed eight control invocations and detected four intended defects across five unique units, without skips. Product tests used legitimate binaries. The live tutorial used isolated binaries from cargo build --all-features. Cargo test builds produced different binary hashes from the same source, with separate receipts. The earlier three product guard-removal checks remain historical evidence. This revision did not repeat every product test with protection disabled, and no counterfeit-launcher replay ran. These results do not establish release qualification or formal security acceptance.

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 prepared the implementation, documentation, and validation. Human review of the complete diff remains pending, so the code-ownership attestation remains unchecked.


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

## Problem

A workload with write access to the installation can replace Box's executable or containment helper.
A later launch can run the replacement before sandbox restrictions apply.
Configured tool programs already receive protection against otherwise permitted writes.

## Solution

Extend that protection to the installed Box executable and helper, as the user explicitly decided.
Retain their file identities and refuse direct writable grants and broker mutations that reach their names or containing directories.
Account for hard links and verified mounted paths, and refuse incomplete inventories or changed identities.
Preserve Cargo layouts when every binary name is accounted for and the workload cannot change the installation.
Retain descriptor execution on Linux and the private helper copy on macOS.
Record the accepted decision and the installation-directory cost in the documentation.
The operator owns initial contents, outside writers, and updates between runs.
Executable-format and public-marker checks identify artifact kind rather than authenticating contents.
Reuse the existing hosted Site value to remove an owned macOS Clippy warning without changing tool-spawn behavior.
Codex prepared the implementation, documentation, and validation. Human review remains pending.

## Tests

- Direct replacement refusal: every_process_table_refuses_writes_to_installed_executables_and_their_ancestors passed on Linux and macOS.
- Broker replacement and deletion refusal: the_hosted_shell_cannot_rename_installed_executables_or_their_ancestors and monty_cannot_remove_installed_executables_through_their_paths_or_symlinks passed on both platforms.
- Cargo binary names: cargo_hard_links_and_all_their_ancestors_remain_protected passed on both platforms.
- Linux mounted names: real_mount_aliases_preserve_link_counts_and_refuse_overlapping_write_grants passed without a skip.
- Ordinary reads and sibling writes: installed_executables_remain_readable_and_an_unrelated_sibling_remains_writable passed on both platforms.
- Operator updates: an_operator_can_replace_installed_executables_between_runs passed on both platforms.
- Linux just check passed: 4,921 top-level tests, zero failures, 17 ignored. The custom box_library harness passed separately.
- macOS all-features Box tests passed: 1,156 top-level tests, zero failures, five ignored. The custom box_library harness passed separately.
- Installation coverage ran without skips: 30 units and seven product tests on Linux; 17 units and seven product tests on macOS.
- Both platforms passed build, formatting, and Clippy checks. Plain changed-package Clippy reported zero owned warnings and six unchanged vendored Shell warnings.
- The site-manifest tests passed on both platforms: 27 tests each.
- Linux deterministic containment passed: 131 cases, zero failures or errors, nine declared macOS-only exclusions, and full coverage of its 140 defined cases.
- scripts/test-all.sh box-examples passed its all-features build. No scripted examples remain; the full workspace gate covered its Rust-test section separately.
- The live Strands Python tutorial with Amazon Bedrock passed an allowed README read and a denied synthetic .env read on macOS. Its isolated copy used a 512-token output cap.
- The no-default-features build passed with 66 warnings in unchanged containment sources and no Box warning locations.
- The initially absent installed-alias fixtures passed focused reruns on both platforms using legitimate binary copies.
- Independent feature-critic review found no blocking, design, or documentation issues. All manifested source files remained unchanged during the gates.

Clippy follows CONTRIBUTING.md and the just recipe's vendored-code allowances.
Remaining Linux runtime limits are the absent optional instrumentation probe, the alias-read restriction, and the absent credential-daemon fixture.
The macOS filesystem cannot run the non-UTF-8 filename case. Intentional ignored tests remain unchanged.
The deterministic runner's embedded commit label was unknown; source and binary hashes identify the tested candidate separately.
Validation uses legitimate binaries and plain fixtures. It does not establish release qualification or formal security closure.
@kevin-orellana kevin-orellana changed the title Protect Box executables from workload writes fix: protect Box executables from workload writes Nov 4, 2026
@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 4, 2026 01:30
Comment thread crates/box/src/run/installation.rs Resolved
Comment thread crates/box/src/run/installation.rs Resolved
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Request Changes

This review covers bcb8823; there was no earlier review on this PR. The approach holds for the Cargo and copy-install layouts. However, the inventory only covers the resolved bundle executable and the trampoline. The signed macOS package's ./box-core/box launcher stays writable, which leaves the problem this PR names unfixed for the main documented install (see inline).

Details Review Categories
  • Correctness / scope: The protected set comes from executable() plus the helper. Other files that decide what a later launch runs (the package launcher and the sock-alias image) fall outside it.
  • Tests: The fixtures only model target/<profile> layouts. A fixture copied from scripts/macos-release.py::stage_package would have caught the launcher gap.
  • Size: About 2,000 changed lines (about 1,370 of them tests). If follow-ups come, splitting off the Linux mount-alias inventory would make review easier.

Checked and held:

  • Cargo deps/ hard links are inventoried, and an unaccounted link refuses startup (open_with_flags).
  • The helper is opened once and executed from the retained descriptor, which keeps the crates/box/AGENTS.md rule "Never validate one pathname and reopen it for exec".
  • Concurrent launches that share the try_clone offset are serialized by prepare().
  • A write grant with Scope::File cannot name a directory (filesystem.rs refuses is_dir() != (scope != File)), so the File arm cannot be used to rename an ancestor.
  • If the mount inventory fails, refuses_mutation refuses every mutation (fail-closed).
  • Production Boundary::translate callers always pass approved, so the fallback TrustedInstallation::load() only runs in tests.
  • The decision entry exists for the narrowed box.toml acceptance. I took it as user-approved, as the description states.

The broker and direct-grant checks are wired consistently across agent, tool, and MCP tables.

Comment thread crates/box/src/run/installation.rs Resolved
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review of 6a86c48 against bcb8823)

6a86c48 fixes both blocking scope gaps from the previous review: the macOS box-core/box launcher and strands-box-sock-alias are now inventoried and refused. The two new inline comments are non-blocking. One is a startup regression for standalone bundles introduced by the wrapper check. The other is a skip guard in the mount test that misses a known namespace refusal.

Review Categories
  • Correctness: Wrapper discovery treats any <package>/box entry as the launcher, so an unrelated directory, symlink, or plain file next to Box.app stops every run.
  • Tests: The namespace-dependent mount test fails on hosts that refuse uid-map writes, a case crates/containment already skips. tests/box_installation.rs returned early on this host (namespace_launcher_is_usable() is false) without printing a skipping: line, so I could not check its end-to-end results here.

Checked and held:

  • Signed layout: box-core/box, its hard links, box-core, and Contents/MacOS/strands-box-sock-alias are refused by refuses_mutation and validate_reach (the_packaged_launcher_and_its_hard_links_refuse_writes), while a sibling output file stays writable.
  • Alias materialization hashes and copies from the opened descriptor with read_at, so a path swap or a shared offset cannot change the copied bytes.
  • is_stale still reopens the path, so an operator update between runs refreshes the copy.
  • The new sock-alias requirement in TrustedInstallation::load adds no precondition for box configure or run, since aliases::materialize already required that binary. The EKS and AgentCore deployment examples ship it.
  • cargo test -p strands-box --all-features --lib -- installation aliases passed 42 of 43. The one failure is the environment case above.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review of 4f41d7f against 6a86c48)

4f41d7f resolves both findings from my last review. I found no new issues, so this review has no inline comments.

What I checked
  • Wrapper discovery: <package>/box is now inventoried only when it is an executable regular file. A directory, a symlink, or a non-executable file in that spot no longer stops startup. Unit and macOS integration tests cover all three cases.
  • Namespace skip: namespace_prerequisite_is_denied matches the same refusal messages as crates/containment. Negative tests show it still rejects real inner-test failures: an ENTERED or harness stdout, an exit status other than 1, an unknown errno, and an embedded message. On this host the mount test now prints skipping: … write failed /proc/self/uid_map: Operation not permitted.
  • Shared installation::directory: in production it returns parent(), so behaviour is unchanged. The deps fallback applies only under cfg(test). Freshness checks, materialization, and the trampoline lookup now use the same directory, and cargo_alias_freshness_uses_the_same_installation_as_materialization covers the old mismatch.

Checks that held, one line each:

  • A non-launcher entry named box beside Box.app is skipped, and the bundle's own programs stay protected.
  • An executable launcher, its hard links, and box-core are still refused.
  • The alias copy still reads from the opened descriptor, and is_stale still reopens the path.
  • Production lookup paths for the trampoline and alias image are unchanged.

Verification on Linux:

  • I built the trampoline first, as crates/box/README.md says to, then ran EXPERIMENTAL_LINUX_SUPPORT=TRUE cargo test -p strands-box --all-features --no-fail-fast. Everything passed (lib: 724).
  • On this host the namespace-dependent tests return early, so they did not exercise containment here.
  • cargo fmt --check is clean.
  • Clippy reports warnings only in strands-shell, which this PR does not touch.
  • I did not run the #[cfg(target_os = "macos")] tests.

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