Skip to content

feat(containment): match macOS tool execution on Linux - #131

Merged
kevin-orellana merged 1 commit into
mainfrom
feature/linux-tool-execution-parity
Oct 21, 2026
Merged

kevin-orellana merged 1 commit into
mainfrom
feature/linux-tool-execution-parity

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: Linux tools can create programs and libraries in permitted directories, but Box prevents them from running or loading those files.

Solution: Apply the existing macOS behavior to Linux: let tools run helpers and load libraries from paths permitted by their box.toml configuration.

Trade-off: A tool can now execute code that it creates or changes in a writable directory. The agent keeps its existing execution restrictions.

Description

The existing broad_exec setting implements this behavior for declared tools and servers that communicate through standard input and output.
Box discloses the permission at startup. It adds no configuration fields or automatic access to host directories.
Private temporary mounts, denied paths, and protected files remain non-executable.
The requester explicitly approved extending macOS tool execution permissions to Linux before implementation.
The tool execution decision records the rationale and cost.

Library packs and broader compiler qualification remain separate work.
Automated Git and Cargo fixture changes remain a separate follow-up; this PR retains their original quarantine entries.
Additional helper trials at this PR revision are summarized in Testing below.
The root and Box crate AGENTS.md descriptions still need a maintainer update from macOS-only behavior.

Codex prepared and tested this change. An independent agent performed an adversarial review and found no confirmed defects.

Related Issues

No issue closes through this PR.

Type of Change

New feature

Testing

CI passed on both platforms. Local just check failed two unchanged startup tests; the exact bare Clippy command also failed on existing warnings.
The checked items use the passing workspace CI run and the Clippy recipe required by CONTRIBUTING.md. Local failures remain documented below.

CN-X-04, the tool execution and library-loading test, passes on ARM64 Debian and native macOS.
It creates previously absent outputs, verifies that the tool runs and loads them, and verifies that the agent cannot.
The same test fails both operations on unchanged Linux baseline 913f5367f57424b3bda65dc4a05278a5664f635d.

The new Linux kernel test also checks readable helpers, denied subtrees, protected files, ungranted programs, and private temporary output.
Successful host controls confirm that the test programs work before containment.
Existing validation refuses missing grant roots; new outputs inherit their permitted parent directory's mount permissions.

Check Result
Linux containment suite 359 reported passes, including one fixture that returned early
macOS containment suite 277 reported passes, including two fixtures that returned early
Linux Box unit suite 583 reported passes, including one fixture that returned early
Boundary translation and disclosure Linux 47 and macOS 52 passed without skips
Harness unit tests 89 passed
Focused review checks Missing-path validation and tool-only execution disclosure passed
Formatting and workspace Clippy Passed on both platforms with existing CI lint allowances
CI at 7f6baeb Workspace test jobs and full deterministic suites passed on Linux and macOS; macOS passed on retry
Local just check Formatting and configured Clippy passed; project suite had 16 passes and two startup timeouts

The macOS CI retry passed without source changes. The CI workflow completed successfully.
The first attempt failed the unchanged catalog timing test: ratio 3.13 against a 3.0 limit.

Additional helper trials (October 21)

Git and Cargo passed on ARM64 Debian 12 and Amazon Linux 2023 containers using the unchanged product build at 7f6baeb.
The Git fixture patch and standalone probes are outside this PR.

Git initialized a repository, staged a file, committed through a real pre-commit hook, and read the log.
Host checks confirmed that the commit existed.
The Debian run used the restored Git fixture; Amazon Linux used a separate probe with explicit library grants.
Git required its helper directory and the hook interpreter in the tool grants.

Cargo 1.98.1 compiled an offline crate, linked through GCC, executed its build script, and ran the generated output.
It used explicit Rust toolchain, library, and compiler grants, plus a dedicated directory containing linker-helper aliases.
Amazon Linux also required /usr/libexec/gcc/aarch64-amazon-linux/11.
Cargo selected the installed Cargo and Rust binaries directly; these trials did not exercise Rustup toolchain selection.
A whole /usr/bin grant and symlink file grants remained refused.

Both workflows passed read-only write, ungranted-program, protected-configuration, direct-agent execution, and missing-tool denial checks.
Cargo also refused an undeclared copy beside its permitted output.
On unchanged baseline 913f536, Git ignored the non-executable hook, and Cargo could not execute Rust (Permission denied, OS error 13).

These privileged containers shared LinuxKit kernel 7.0.12; their results do not establish native Linux or cloud qualification.
The separate Git fixture patch passed 90 harness unit tests.
Its full manifest remained RED: 107 passes, one setup error, and 21 skips.
Two test targets failed during unchanged host-tracing setup, before containment.
The Cargo fixture remains quarantined, and the standalone Cargo trial did not rerun the full suite.
These additional results do not replace the CI results or remove the validation limits below.

Commands and validation limits

Commands included cargo test -p strands-box-containment --all-features, the Box boundary test filter, and cargo test --manifest-path test-integ/Cargo.toml cn_x_04 -- --nocapture.
The Linux Box unit binary ran as a non-root user with an init process and controlled environment.
Workspace Clippy used the allowances in .github/workflows/rust-test-lint.yml; the bare command below reports warnings in unchanged code.
Local just check passed formatting and configured Clippy, then failed two unchanged box_project tests after 60-second startup timeouts:
a_policy_edited_during_a_run_governs_the_next_run_and_not_the_running_one and a_run_on_a_running_box_is_refused_before_it_touches_an_alias.
An isolated rerun reproduced the first timeout.
A process sample showed Box blocked writing stderr while the test waited for startup without draining its captured output.
The run stopped at this suite; later suites did not run locally.

cargo fmt --all passed without source changes.
The exact bare Clippy command failed on seven existing lint findings: six in vendored shell code and one in unchanged trampoline code.
These lints are covered by the repository's existing allowances.
CONTRIBUTING.md explicitly requires just clippy for those allowances.

The Amazon Linux deterministic harness failed before the parity case because its agent lacked the libpcre2-8.so.0 grant.
The Linux kernel test passed in that environment.
The Linux library-denial assertion depends on glibc error text, so its portability is limited to the current test environments.

  • I ran the relevant workspace suites through CI (cargo test --workspace --all-features); the current commit passed on both platforms.
  • I ran cargo fmt --all and the repository-supported Clippy recipe (just clippy); both passed with the required lint allowances.

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

Linux tools cannot execute programs or load libraries that they write into their granted directories.
The unchanged baseline fails CN-X-04 at both operations.

## Solution

Apply the existing broad-execution setting to Linux tools and stdio servers.
Permit code execution through their readable and writable file and directory grants.
Keep agent execution restrictions, automatic temporary mounts, denied paths, and protected files unchanged.
Disclose the permission at startup without adding configuration fields.

## Tests

CN-X-04 passes on Linux and macOS and fails on the unchanged Linux baseline.
The new Linux kernel test covers written helpers, denied paths, protected files, temporary files, and agent denials.
The plan test covers file grants, directory grants, metadata entries, and device mounts.
The boundary test covers leaf-only wiring and disclosure.
Containment suites report 359 Linux and 277 macOS passes, with one and two existing fixture skips.
Linux Box units report 583 passes with one installed-alias lookup skip.
Harness units report 89 passes.
Formatting and workspace Clippy pass with the existing CI allowances.
Full workspace and full deterministic suites were not run.
Amazon Linux's deterministic harness still lacks an agent library grant before this case starts.
Comment thread test-integ/tests/containment/cn_x_04.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment (one blocking question to confirm before merge)

The mechanism is clean and well-tested: the change ports the existing broad_exec model to Linux by dropping MS_NOEXEC on a leaf's writable/readable grant mounts, while the seccomp filters (mmap PROT_WRITE|PROT_EXEC, mprotect PROT_EXEC, memfd_create) stay in place, so only file-backed exec from the tool's own grants opens — matching macOS. Agent W^X, denied subtrees, protected files, and private /tmp remain non-executable, and the new unit, boundary, and integration tests pin each of those.

Review themes
  • Foundational-premise approval: Relaxing Linux W^X for a leaf is a premise change under AGENTS.md's STOP section. Please confirm explicit approval in the description. A previously premise-pinning test had its allow_broad_exec() assertion removed, which confirms the shift.
  • Stale premise docs: Root AGENTS.md / crates/box/AGENTS.md still say broad exec is macOS-only; decisions.md is correctly updated. Flagged for a maintainer to reconcile (not a doc edit asked of this PR).
  • Plan-time filesystem probe: The is_file()/is_dir() gate may drop exec on a write grant whose target is created after planning — worth confirming it cannot regress a lazily-created output dir.
  • Test robustness: The Linux loader-error string assertion is brittle but acceptable for the harness.

Nicely scoped change with strong denial coverage on both platforms.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

/strands review

@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed at 7f6baeb after the author's replies. No new commits; the follow-up is in the responses and the rewritten description. All three prior threads are resolved satisfactorily:

Thread resolution
  • Premise approval (blocking) — Resolved. The description now records that the requester explicitly approved extending the macOS tool-execution model to Linux before implementation, states the writable-code execution trade-off, and flags the stale AGENTS.md wording for a maintainer (correctly not edited here). decisions.md carries the rationale.
  • Plan-time is_file()/is_dir() probe — Resolved and verified. Grant roots must exist at planning: PathGrant resolution calls canonicalize_existing, which returns PathNotFound for an absent target, so the probe runs on a resolved root and new outputs inherit their existing writable parent's executable mount. CN-X-04 and a_leaf_runs_written_helpers_... both create previously-absent outputs and exercise this.
  • Loader-string assertion — Resolved. Retained with the portability limit documented; the probe returns success on DLOPEN_REFUSED, so exit status and bare DLOPEN_OK absence cannot distinguish a mapping denial from an unrelated failure, which justifies matching the glibc message.

One open item is a maintainer action, not a code defect: reconciling the "macOS-only" wording in the root and box AGENTS.md with the now-shipped Linux behavior. The PR correctly flags it rather than carrying the doc change. Clean, well-tested change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants