Repository navigation
fix(containment): allow executable memory on Linux so JIT runtimes run - #488
Conversation
… agent on Linux A JIT runtime writes the code it compiles into memory and then runs it. Linux's restriction filter refused that memory in every sandbox, so Node and the JVM aborted and Bun fell back to its interpreter. A tool or stdio MCP server now maps writable and executable memory, set beside broad exec. The agent keeps the rule unless `[agent]` sets `executable-memory = true`, which needs record version 36. Only the `mmap` and `mprotect` rules lift; `memfd_create`, descriptor `execveat`, `pkey_mprotect`, and the `noexec` mounts stay refused. Refs #42
|
Suggestion (non-blocking): this change makes two statements in Example:
Suggestion: Qualify the first bullet: "…unless |
|
Assessment: Request Changes The filter change itself is correct and tightly scoped: only the DetailsChecked and held
The real-box probe test and the end-to-end Node evidence make the filter change easy to trust. |
Every leaf mapped executable memory, on the premise that broad exec already runs what a leaf writes. A leaf with no writable grant had no place to run bytes it wrote, so the lift widened it, and every stored box gained it on resume. `executable-memory` is now a per-process key on `[agent]`, each `[tool.<name>]`, and each stdio `[mcp.<name>]`, off by default, as `file-watching` is. An unstarted MCP server discloses it at startup. The two per-process switches share one boundary test and one record test. Refs #42
|
Both points are addressed in d4c512f:
Thanks for running AI-assisted comment |
|
Assessment: Approve (re-review of d4c512f) Both earlier findings are addressed. Checked and held at d4c512f
Folding both switches into one table-driven test keeps file watching and executable memory pinned to the same per-process contract. |
Name the syscall list for what it holds, state the key's reach where allow_file_watching states its own, and give both per-process record tests the same Switch shape as the boundary test. Refs #42
|
Assessment: Approve (re-review of cab44ed) Compared with d4c512f, this commit only renames things and edits doc comments and prose. On x86-64 (kernel 7.0) I re-ran |
…jit-memory # Conflicts: # crates/box/src/record/config/mod.rs # docs/user/native-filesystem-policy.md
|
Assessment: Approve (re-review of 5191c96, the merge of
The merge does not touch any other file of this feature. I re-ran the tests on x86-64:
Small non-blocking fix: the PR description still says "Selecting it requires record version 36" and "only |
…jit-memory # Conflicts: # crates/box/src/record/config/mod.rs
|
Assessment: Approve (re-review of 55ca776, the second merge of This time
The other changes from
I re-ran on x86-64:
Non-blocking: the "Interface changes" section of the PR description still says "requires record version 36". The code now uses 38. |
kevin-orellana
left a comment
There was a problem hiding this comment.
The configuration guide explains the capability, but it does not show the new startup warning or explain when it appears. Could we add that example and update the architecture’s startup description, as .agents/references/doc-updates.md requires?
The pull-request description also says selecting this setting requires saved-state format version 36, while the implementation and committed version guide use 38. Could we update the description to match?
…jit-memory # Conflicts: # crates/box/src/record/config/mod.rs # docs/user/native-filesystem-policy.md
|
Assessment: Approve (re-review of d1958f7, the merge of This commit only merges
The merge doesn't touch Results on x86-64:
The approval covers the opt-in design as it stands at this head. @kevin-orellana now recommends removing the key and allowing executable memory by default on Linux. If the PR changes to that design, it's a different change and needs a fresh review. Besides the points in my earlier comment, it would reverse two things this repository writes down:
The root |
Reviewers preferred the simpler design: drop the `executable-memory` key and let a box map writable and executable memory on every Linux process, so a JIT runtime runs without configuration. The filter no longer mediates `mmap` or `mprotect`; `pkey_mprotect`, `memfd_create`, descriptor `execveat`, and the `noexec` mounts stay refused, so the box still governs which program files run. Generated code is bound by the same system-call filter, filesystem grants, and network policy. This gives up a hardening measure, not an authority, and matches macOS, whose Seatbelt does not govern anonymous memory. Removes the `box.toml` key, its record version, and the startup disclosure. `a_box_runs_generated_code_that_stays_contained` runs code the process wrote and checks it stays contained; a lib-level test pins the filter directly. Refs #42
|
Done in 1866973. The The containment stays, and a permanent test proves it. Agreed on the trade-off you flagged: this gives up a hardening measure, and we haven't quantified the kernel-exploit effect. |
|
Assessment: Comment (fresh review of 1866973, which switches to executable memory by default on every Linux process) The code change is correct and minimal. I have one documentation finding, inline: the claim that the box "still governs which program files run" is false for runtimes that can call native code. Checked and held at 1866973
Two leftovers to clean up while you're here:
|
- The raw-fork test probed the restriction filter with an executable mprotect, which is now permitted, so it no longer checked that filter. It now uses a nonzero setpgid, which the permit filter admits and the restriction filter refuses. The anonymous mapping it needed is gone, and FORK_CHILD_DENIED is back to its value on main. - Drop a_read_execute_mapping_is_still_permitted and the plain writable mapping check: both bounded the removed mmap rule. - State the real reason pkey_mprotect stays refused: it pairs with the unpermitted pkey_alloc. - Fix comments the change made stale (view.rs /proc, the V8 note) and revert unrelated rewording in architecture.md and native-filesystem-policy.md. - run_generated_code is a safe fn; its caller has no precondition.
The docs said the box "still governs which program files run". The kernel still never maps or starts a file outside the exec grants, but a runtime that calls native code can copy a readable program into memory and run it. Say so in config.md and the decision entry.
|
Thanks. On the two leftovers:
dfc7c94 also changed two tests:
|
|
Assessment: Approve (re-review of 8d60bc4) The last open item is fixed. 8d60bc4 changes only docs. The code is unchanged since dfc7c94, where I last ran the tests: the containment tests, the |
|
Assessment: Comment (re-review of dfc7c94) This commit tightens tests and wording around the default-on design, and the code side holds:
Results on x86-64:
The one open item is still the "governs which program files run" sentence in |
## Problem Build downloaded the ffi shim (box-ffi-python3.14, release 0.1.11-linux-preview.2), staged it in `.box-dist/ffi`, and put it first in the Runtime `PYTHONPATH` of the agent and of each leaf on the Runtime Python. The shim was necessary because Box Core refused executable memory on Linux. box 0.1.11-mquang.preview.9 has Box Core 78e752b0, with [strands-agents/box#488](strands-agents/box#488), so the Python of the Runtime runs in a box with no shim. ## Solution This commit has the shim removal of [aws#2867](aws#2867) ([e8069dd](aws@e8069dd) and [baa1fe0](aws@baa1fe0)), so that the PR that merges second has a small conflict: - `boxRelease.json` pins only `box`. `FFI_RELEASE`, its cache, and its download go. `bump-box-release.ts` accepts only `--box`. - `stageBoxCodeZip` stages no `ffi` folder, and `.box-dist` names no `ffi` folder. - The README says what the zip contains with no shim. The part of e8069dd in `runtimeCodeZipRunner` is not necessary here, because the derivation gives the Runtime `PYTHONPATH`. The derivation changes as follows: - The additions rule adds no shim. An `[agent]` with no `PYTHONPATH` gets the code folder on CodeZip. - The paths rule adds no shim at the start for a leaf. It keeps each entry one time, and keeps the code folder at the end of the `PYTHONPATH` of `[agent]` and of each leaf on the Runtime Python. The template tables of `old-renderer-tables.json` are recorded again from the renderer of aws#2867 at f40ebce. Only the 102 `PYTHONPATH` values change, to `${{ inputs.code.dir }}`. ## Tests - additions.test.ts: "keeps a PYTHONPATH of the user as it is, on CodeZip and on a container", "gives an [agent] with no PYTHONPATH the code folder on CodeZip, and none on a container", and the tests on the recorded tables. - paths.test.ts: "keeps the code folder in the PYTHONPATH of [agent] and of a leaf on the Runtime Python, one time", and "ends a leaf's own PYTHONPATH with the code folder, and adds none to [agent] or a leaf with no Python". - boxCodeZip.test.ts and boxRelease.test.ts, as in aws#2867.
…hine that it has no build for ## Problem The CLI pinned box 0.1.11-linux-preview.7. Its Box Core refused executable memory on Linux, so the ffi shim was necessary for a CodeZip agent. The previous commit removes the shim. The user selected [box 0.1.11-mquang.preview.9](https://github.com/mquang-amazon/box-releases/releases/tag/v0.1.11-mquang.preview.9): staging-boxy b0846169 with [strands-agents/staging-boxy#549](https://github.com/strands-agents/staging-boxy/pull/549), on Box Core 78e752b0 with [strands-agents/box#488](strands-agents/box#488). It does not have strands-agents/box#537. That release has only the Linux arm64 build. Each install hint named only the release page of the pin, so on macOS the hint gave a page with no build for the machine. ## Solution - `bun scripts/bump-box-release.ts --box 0.1.11-mquang.preview.9` wrote `boxRelease.json` from the SHA256SUMS.txt of the release. The file is the same as in [3934bbe](aws@3934bbe) of [aws#2867](aws#2867). - `BOX_MINIMUM_RELEASE_PAGE` is the release page of `BOX_MINIMUM_VERSION` (0.1.11-linux-preview.7), which has a macOS build. - `BOX_OTHER_MACHINE_HINT` says to use that box, or a subsequent release with a build for the machine, when the pinned release has none. `BOX_INSTALL_HINT` and each install hint of the profile resolver end with it. - The local box is not compared to the pin. A macOS box 0.1.11-linux-preview.7 on PATH stays correct for `agentcore dev` and for the profile checks of build. - The README, the guide, and the comment on the tools of `@box/base` name the new pin. The packs of preview.9 are the same as the packs of preview.7, so `@box/base` has one tool, `uname`. ## Tests - boxRelease.test.ts: "box is at least the first release that reads the profiles the CLI writes" (semver sorts 0.1.11-mquang.preview.9 after 0.1.11-linux-preview.7), and "the install hint names the pinned release, and the first release for a machine it has no build for". - boxProfileResolver.test.ts: each install hint of the resolver. - The SHA-256 of the archive that curl downloaded into a new empty folder agreed with SHA256SUMS.txt (5b0f8802fb1c5cbc22db4bfcefc9061e048e931c972584350ebce6c1b15da884). A `diff -r` of the resources of preview.7 and preview.9 found no difference.
## Problem Build downloaded the ffi shim (box-ffi-python3.14, release 0.1.11-linux-preview.2), staged it in `.box-dist/ffi`, and put it first in the Runtime `PYTHONPATH` of the agent and of each leaf on the Runtime Python. The shim was necessary because Box Core refused executable memory on Linux. box 0.1.11-mquang.preview.9 has Box Core 78e752b0, with [strands-agents/box#488](strands-agents/box#488), so the Python of the Runtime runs in a box with no shim. ## Solution This commit has the shim removal of [#2867](#2867) ([e8069dd](e8069dd) and [baa1fe0](baa1fe0)), so that the PR that merges second has a small conflict: - `boxRelease.json` pins only `box`. `FFI_RELEASE`, its cache, and its download go. `bump-box-release.ts` accepts only `--box`. - `stageBoxCodeZip` stages no `ffi` folder, and `.box-dist` names no `ffi` folder. - The README says what the zip contains with no shim. The part of e8069dd in `runtimeCodeZipRunner` is not necessary here, because the derivation gives the Runtime `PYTHONPATH`. The derivation changes as follows: - The additions rule adds no shim. An `[agent]` with no `PYTHONPATH` gets the code folder on CodeZip. - The paths rule adds no shim at the start for a leaf. It keeps each entry one time, and keeps the code folder at the end of the `PYTHONPATH` of `[agent]` and of each leaf on the Runtime Python. The template tables of `old-renderer-tables.json` are recorded again from the renderer of #2867 at f40ebce. Only the 102 `PYTHONPATH` values change, to `${{ inputs.code.dir }}`. ## Tests - additions.test.ts: "keeps a PYTHONPATH of the user as it is, on CodeZip and on a container", "gives an [agent] with no PYTHONPATH the code folder on CodeZip, and none on a container", and the tests on the recorded tables. - paths.test.ts: "keeps the code folder in the PYTHONPATH of [agent] and of a leaf on the Runtime Python, one time", and "ends a leaf's own PYTHONPATH with the code folder, and adds none to [agent] or a leaf with no Python". - boxCodeZip.test.ts and boxRelease.test.ts, as in #2867. Dev port: dev removed the shim in 264da50, so this port keeps the dev boxRelease.json, boxRelease.ts, boxCodeZip.ts, README, and their tests. It takes only the change of the rules: no shim, and the code folder at the end of each Runtime PYTHONPATH. The fixture of this branch has no shim already. (cherry picked from commit 6ce7363)
…hine that it has no build for ## Problem The CLI pinned box 0.1.11-linux-preview.7. Its Box Core refused executable memory on Linux, so the ffi shim was necessary for a CodeZip agent. The previous commit removes the shim. The user selected [box 0.1.11-mquang.preview.9](https://github.com/mquang-amazon/box-releases/releases/tag/v0.1.11-mquang.preview.9): staging-boxy b0846169 with [strands-agents/staging-boxy#549](https://github.com/strands-agents/staging-boxy/pull/549), on Box Core 78e752b0 with [strands-agents/box#488](strands-agents/box#488). It does not have strands-agents/box#537. That release has only the Linux arm64 build. Each install hint named only the release page of the pin, so on macOS the hint gave a page with no build for the machine. ## Solution - `bun scripts/bump-box-release.ts --box 0.1.11-mquang.preview.9` wrote `boxRelease.json` from the SHA256SUMS.txt of the release. The file is the same as in [3934bbe](3934bbe) of [#2867](#2867). - `BOX_MINIMUM_RELEASE_PAGE` is the release page of `BOX_MINIMUM_VERSION` (0.1.11-linux-preview.7), which has a macOS build. - `BOX_OTHER_MACHINE_HINT` says to use that box, or a subsequent release with a build for the machine, when the pinned release has none. `BOX_INSTALL_HINT` and each install hint of the profile resolver end with it. - The local box is not compared to the pin. A macOS box 0.1.11-linux-preview.7 on PATH stays correct for `agentcore dev` and for the profile checks of build. - The README, the guide, and the comment on the tools of `@box/base` name the new pin. The packs of preview.9 are the same as the packs of preview.7, so `@box/base` has one tool, `uname`. ## Tests - boxRelease.test.ts: "box is at least the first release that reads the profiles the CLI writes" (semver sorts 0.1.11-mquang.preview.9 after 0.1.11-linux-preview.7), and "the install hint names the pinned release, and the first release for a machine it has no build for". - boxProfileResolver.test.ts: each install hint of the resolver. - The SHA-256 of the archive that curl downloaded into a new empty folder agreed with SHA256SUMS.txt (5b0f8802fb1c5cbc22db4bfcefc9061e048e931c972584350ebce6c1b15da884). A `diff -r` of the resources of preview.7 and preview.9 found no difference. Dev port: dev pins 0.1.11-mquang.preview.9 already (7de308e), so this port keeps the dev boxRelease.json and the dev text of the pin. It takes BOX_MINIMUM_RELEASE_PAGE, BOX_OTHER_MACHINE_HINT, the hints that end with it, their tests, and the README sentence on the macOS box. (cherry picked from commit 853a8a5)
Description
On Linux, Node, Java and Bun fail inside a box. A JIT runtime writes the code it compiles into memory and then runs it. Box's seccomp restriction filter refused writable memory that becomes executable. V8 and the JVM treated that refusal as fatal (Node exits 133 with
Check failed: 12 == errno), and Bun dropped to its interpreter, which made a loop about 30x slower in my test. So npm, npx, vite, vitest, Maven and Gradle didn't work on Linux.This permits writable executable memory by default on every Linux process. There is no key and no config. The filter stops mediating
mmapwithPROT_WRITE|PROT_EXECandmprotectwithPROT_EXEC; both now go straight through.Everything else that touches executable memory stays refused, for every process:
pkey_mprotectmemfd_createexecveatnoexecmountsSo the kernel never maps or starts a file outside the process's exec grants. A process can run code it writes into its own memory, though, and a runtime that calls native code (Python
ctypes, Java FFM) can copy a readable program into memory and run it. For such a runtime, a read grant on a program works like an exec grant. The system-call filter, filesystem grants, and network policy still apply to that code.Why default-on, not a key. A read-only Node tool needs this too, so a per-table key would force almost every table to set it, and a leaf that writes files could already write a script and run it through its own interpreter. The key added surface without adding safety. Linux stays stricter than macOS even so: macOS has no counterpart rule, because Seatbelt does not govern anonymous memory.
Interface changes (frozen surfaces)
None. The earlier draft of this PR added an
executable-memorykey and aContainmentConfig::allow_executable_memory()method; both are gone.box.toml, the record version, and the containment config surface are unchanged. An existing box keeps its exact bytes and record version.Not in this change
records.jsonl. Box can't record seccomp refusals yet; Linux: record seccomp refusals as kernel_refused telemetry #101 is adding that.pkey_allocandpkey_mprotect, so V8 can use memory protection keys on x86-64. V8 already falls back to plainmprotectwhen it has no key.Related Issues
Closes #42
Type of Change
Bug fix
Testing
Tests:
crates/containment/tests/executable_memory_linux.rsruns a probe in a real box through the trampoline. The probe writes a small machine-code function (aarch64 and x86_64), runs it, and reports what else the kernel allows. The box runs the generated code (generated_code_returned: 42) whilepkey_mprotect,memfd_create, an IPv6 socket, and an ungranted path all stay refused in the same process.writable_memory_can_become_executable(namespace) assertsmmapW|XandmprotectR|Xare permitted whilepkey_mprotectis refused. It replaces the two tests that pinned the oldmmaprule.raw_fork_preserves_child_restrictions(x86-64) checked the restriction filter with an executablemprotect, which is now permitted. It now uses a nonzerosetpgid, which only the restriction filter refuses.End to end, with
strands-box runon Graviton (AL2023, kernel 6.18) and the official Node v22.22.2 build as the agent, a default box with no key prints2 object(1 + 1andtypeof WebAssembly). Before this change the same box exited 133 withCheck failed: 12 == (*__errno_location ()).Suites run on that host:
cargo test -p strands-box-containment --all-features --lib -- backend::linux: passedcargo test -p strands-box-containment --all-features --test executable_memory_linux --test x86_syscalls_linux: passedcargo test -p strands-box --lib -- record:: run::contain: passedcargo fmt --all -- --checkandcargo clippy --workspace --all-targets --all-features -- -D warnings: cleanNot run on this host: macOS, and anything x86-64 (no cross C compiler), including
raw_fork_preserves_child_restrictions.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.
AI-assisted PR