Skip to content

fix(box): Grant the standard library of the Runtime Python on CodeZip, not its prefix, so box starts on Runtime V2 - #2903

Merged
vvargu merged 2 commits into
box-integrationfrom
fix/box-codezip-python-stdlib-grant
Nov 24, 2026
Merged

vvargu merged 2 commits into
box-integrationfrom
fix/box-codezip-python-stdlib-grant

Conversation

@vvargu

@vvargu vvargu commented Nov 24, 2026

Copy link
Copy Markdown

Description

A CodeZip Box agent does not start on AgentCore Runtime V2. Box refuses the Runtime profile, and the Runtime create fails with "The runtime process exited unexpectedly". The Runtime log has this error:

strands-box: error: `[agent]` filesystem entry "/usr" is refused: /usr is refused beneath every grant: grant is too broad to be authorized: /usr (a system root is never a grantable tree)

Cause. c40bee73 made the CodeZip Runtime profile grant the base prefix of the Runtime's Python (sys.base_prefix), for read and exec. Later, #2853 moved the value into start.py (BOX_PYTHON_PREFIX), and #2866 kept the grant as ${{ inputs.python.prefix }}.

  • On V1, Python is in /opt/aws/agentcore-runtime/python/versions/3.14.2. The grant is a narrow folder, and box accepts it.
  • On V2, Python is /usr/bin/python3.14, so the prefix is /usr. Box refuses a system root as a grant. All box builds from 0.1.11-linux-preview.5 to 0.1.11-preview.10 have this rule.

The V2 pin (aws/agentcore-l3-cdk-constructs#474 and #2879) does not cause the defect. It only makes the defect appear.

Fix. This is the change of #2882, which was closed unmerged. This PR applies it on the current box-integration.

  • start.py exports the standard library of the Runtime's Python (sysconfig.get_path("stdlib")) as BOX_PYTHON_STDLIB, in place of BOX_PYTHON_PREFIX.
  • The @box/agentcore-codezip pack reads it as inputs.python.stdlib.
  • The Runtime profile grants ${{ inputs.python.stdlib }} for read and exec. exec is necessary, because box cannot map the native modules in lib-dynload from a read grant. Box adds the interpreter itself as an implicit exec.

The second commit changes one test from #2882. On box-integration, the test helper createdRuntime also takes otel.

Effect on existing projects. create writes start.py into the project, and build does not write it again. A CodeZip Box project from before this change keeps a start.py that exports only BOX_PYTHON_PREFIX. With this change, box does not get inputs.python.stdlib for such a project. Such a project needs the new start.py, or a new create.

Related Issue

There is no issue. This PR replaces #2882. It works with #2879, which pins Box runtimes to V2.

Documentation PR

Not applicable.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Testing

Live test in us-east-1. The CLI was box-integration with #2879 and this change, the L3 was box-integration b21cfbf, and box was 0.1.11-preview.10. The project was create --template agent-python-strands-box, with no other change.

  • Without this change: the stack asks for PlatformVersion: V2. The Runtime create fails, and the Runtime log has the /usr refusal above.
  • With this change: deploy passes, and invoke returns status 200 with the answer. The box log shows [agent] runs /usr/bin/python3.14, exec /usr/lib/python3.14, and no refusal. All the agent's calls to Bedrock and AgentCore Memory are permitted.

Local test: start.py in an arm64 Amazon Linux 2023 container, where Python is in /usr. It shows the same refusal without this change, and box starts with this change.

  • I ran bun test. 6108 pass and 1 fails: boxProfileResolver.test.ts > "resolves a profile into the rules the tests fake" (a metadata_hosts rule). That test also fails on box-integration 2f9422d5 without this change.
  • I ran the relevant end-to-end tests with bun run test:e2e, or explained why they are not applicable
    (CI does not run them for you). I did not run them. The live deploy and invoke above take their place for this change.
  • I ran bun run typecheck
  • I ran bun run lint:check
  • I ran bun run format:check
  • I ran bun run audit
  • I ran bun run secrets:check
  • I ran bun run build
  • If I modified src/assets/, I updated affected snapshots with bun test <test-file> --update-snapshots and committed them. No snapshot changed.
  • If I re-recorded fixtures or golden files, every change beyond account identifiers is explained
    by this PR. old-renderer-tables.json changes only inputs.python.prefix to inputs.python.stdlib.
  • This PR does not change command.md (the release workflow regenerates it)

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

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

@vvargu
vvargu requested a review from a team November 24, 2026 00:42

@leo237 leo237 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks right: granting sysconfig.get_path("stdlib") in place of sys.base_prefix gets rid of the /usr system-root refusal on V2. The live deploy and invoke you ran back that up. The pack keeps ABSOLUTE_PATH_PATTERN on the new input, so an empty value or / still can't widen the grant. And nothing in src/ still refers to inputs.python.prefix or BOX_PYTHON_PREFIX.

I checked out a08503c and ran the checks locally. bun run typecheck passes. bun test gives 6108 pass, 7 skip, 0 fail, so the boxProfileResolver failure from the PR description didn't happen here. The new start.py test and the CodeZip template test both run (the start.py test isn't skipped, since python3 is on PATH).

Comments, none blocking:

  1. Stale start.py in existing projects (inline on the pack input). This one is worth addressing, or at least tracking. It's the biggest behavior risk in the PR.
  2. lib-dynload is assumed to be under stdlib (inline on start.py). It's true on the V2 image you measured, but CPython puts lib-dynload under platstdlib, and nothing checks that the two are the same.
  3. V1 and other Python versions. The narrowing was only tested live on V2 / PYTHON_3_14. On V1 (/opt/aws/agentcore-runtime/python/versions/3.14.2), the old prefix grant also covered <prefix>/lib, where a shared-build Python keeps libpython3.X.so (Py_ENABLE_SHARED=1, LIBDIR=<prefix>/lib). The new grant drops that folder. That's only safe if V1's Python is static, or if #2879 (V2 pin) merges before or with this PR. Can you confirm which one holds? Also, were PYTHON_3_10 to 3_13 on V2 checked to have the same /usr/lib/python3.X layout? The template test hard-codes the 3.14 values.
  4. nits on naming and the test fixtures (inline).

The squash plan doesn't cover this fix, so none of these are deferred to a later phase.

@mquang-amazon mquang-amazon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vvargu
vvargu force-pushed the fix/box-codezip-python-stdlib-grant branch from a08503c to 85e87ca Compare November 24, 2026 05:51
@codecov-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.85%. Comparing base (bca6a71) to head (855f3b9).

Additional details and impacted files
@@               Coverage Diff                @@
##           box-integration    #2903   +/-   ##
================================================
  Coverage            96.85%   96.85%           
================================================
  Files                  773      773           
  Lines                68326    68326           
================================================
+ Hits                 66177    66178    +1     
+ Misses                2149     2148    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leo237 leo237 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 85e87ca. Since my review at a08503c, the branch was rebased onto the current box-integration. The PR's own changes are line for line the same as before: I compared the changed lines of both versions. There are no replies on the threads yet, so the status below is the same as last time. None of it blocks.

I checked out 85e87ca and ran the checks locally. bun run typecheck passes. bun test gives 6333 pass, 7 skip, 0 fail.

Status of my earlier comments:

  1. Stale start.py in existing projects (boxProfile.ts): not fixed. One thing is new on the base. Since 3d7a347, an old Box project fails schema validation with a message that says only to set "platformVersion": "V2". A user who follows it then deploys with the old start.py and hits the Runtime crash. Details are in the thread.
  2. lib-dynload under platstdlib, not stdlib (start.py:95): not fixed.
  3. Question: V1, and PYTHON_3_10 to 3_13 on V2: the V1 part no longer matters. Since 3d7a347 on the base, every Box runtime must set platformVersion to V2. The question about 3.10 to 3.13 on V2 is still open. e2eTest/project/templates.test.ts:116-118 (from MQ-7) already deploys the CodeZip box template on each of those Pythons. One run of it on this branch would answer the question, because the stdlib path on V2 differs for each version.
  4. nit: the doc of runtimePythonStdlib on Container (context.ts): not fixed.
  5. nit: the dead inputs.python.prefix entry, and no source noted for the copied box lists (additions.test.ts): not fixed.

No new findings, because there is no new code.

Sai Abhishek and others added 2 commits November 23, 2026 22:41
…, not its prefix

A CodeZip box runtime does not start on AgentCore Runtime. box stops with this error:

`[agent] filesystem entry "/usr" is refused: ... a system root is never a grantable tree`

The Runtime profile moves the read grant and the exec grant of the uv Pythons of the local profile
to `${{ inputs.python.prefix }}`. start.py sets this input to `sys.base_prefix`. The Python of a
PYTHON_3_14 Runtime is `/usr/bin/python3.14`. Thus the value is `/usr`. Box Core refuses a grant of
`/usr`, and each Box Core release refuses it. Thus box did not start on a CodeZip Runtime before
this change. Before
[4700b62](4700b62),
start.sh started the agent with no box when box did not start. That commit and
[#2853](#2853) removed this fallback. At
this time, the Runtime stops the runtime, and the deploy stops with an error. The branch
box-integration-development has the same problem.

With this change, the uv Pythons of the local profile go to the standard library of the Runtime
Python, `${{ inputs.python.stdlib }}`, and not to its prefix.

- start.py exports `BOX_PYTHON_STDLIB`, the value of `sysconfig.get_path("stdlib")`, in place of
  `BOX_PYTHON_PREFIX`. On a PYTHON_3_14 Runtime, the value is `/usr/lib/python3.14`.
- The `@box/agentcore-codezip` pack has the input `python.stdlib` in place of `python.prefix`, with
  the same pattern.
- The paths rule moves `${{ home }}/.local/share/uv/python` to `${{ inputs.python.stdlib }}`.

After this change, the Runtime profile of each CodeZip template has these grants:

- `read = [code folder, standard library, "/usr/lib64", "/lib64"]`. The Python reads its modules.
  `/usr/lib64` contains the libraries that its native modules use, for example `libssl.so.3`.
- `exec = [code folder, standard library]`. box mounts a folder that is not a loader folder with
  no exec. Thus the Python can use the native modules in `lib-dynload` only with this grant.
- The Python itself is the command of the agent, and box gives it exec.

A read grant of the loader folder `/usr/lib` also lets the Python start. This change does not use
it, because it gives read and exec on all of `/usr/lib`, and not only on the standard library.

A CodeZip box runtime that `agentcore create` made before this change has a start.py that exports
the prefix. Copy the start.py of this change into its code folder.

- `start.py > gives box the standard library of the Runtime's Python, and not its base prefix`
  (`boxStartPy.test.ts`) starts `main()` of start.py, and replaces `os.execve` with a function that
  records the environment. It makes sure that `BOX_PYTHON_STDLIB` is the standard library, and that
  no value is the prefix.
- `the Runtime profile of each CodeZip box template of create` (`additions.test.ts`) derives the
  Runtime profile of the six CodeZip box templates. It makes sure that the read grant and the exec
  grant of the standard library are in the profile. It also makes sure that no grant has a value
  on the Runtime that Box Core refuses: a system root in a list, or a loader folder in a list that
  is not `read`.
- The pack test makes sure that the pack has the input `python.stdlib`. The paths test and the
  test of the recorded profiles in `old-renderer-tables.json` use the standard library. In that
  file, only these 204 values change.
- On the code before this change, 115 of the new and changed tests show an error.
- Five mutations of the code, and the errors that each mutation causes:
  - start.py exports the prefix again: the start.py test shows an error.
  - The paths rule moves the uv Pythons to the prefix again: 111 tests show an error.
  - The pack has `python.prefix` again: 2 pack tests show an error.
  - `runtimeCodeZipRunner` gives no exec grant of the uv Pythons: 110 tests show an error.
  - `runtimeCodeZipRunner` also gives a grant of the prefix: the six template tests show an error
    at the check of the refused grants.
- `bun test`: `5835 pass`, `6 skip`, `2 fail`. This change does not cause the two errors.
  `boxProfileResolver.test.ts` also shows the error on box-integration with the same box
  (0.1.11-preview.10) on PATH. `remove/index.test.ts` stops at its 10 s timeout when all tests
  operate together. When it operates with no other test, it shows no error.
- `bun run typecheck`, `bun run lint:check`, `bun run format:check`, `bun run build`,
  `bun run audit`, and `bun run secrets:check`: no errors.
- A local test in an Amazon Linux 2023 arm64 container, with box 0.1.11-preview.10 and a Python
  3.14.3 that has the prefix `/usr` and the standard library `/usr/lib/python3.14`. The Python of
  the Runtime has the same paths. The results:
  - The zip of box-integration stops with the `/usr` refusal.
  - The zip of this change starts the agent, and `/ping` gives 200.
  - The zip of box-integration-development stops with the `/usr` refusal.
- A live test on AgentCore Runtime in a dev account. In the test, we deploy a new CodeZip box
  project of this branch, with no change. Three invocations get status 200, and the box records
  are in the log group `-DEFAULT` of the runtime. The test removes all its resources.

We did not do `bun run test:e2e`. This change has no test on the CodeZip Runtimes PYTHON_3_10 to
PYTHON_3_13, and no test of an `[mcp]` server or a `[tool]` on the Runtime Python.

(cherry picked from commit 490c197)
createdRuntime on box-integration takes the otel flag. The box templates
write enableOtel false, so the test passes false.
@vvargu
vvargu force-pushed the fix/box-codezip-python-stdlib-grant branch from 85e87ca to 855f3b9 Compare November 24, 2026 06:42

@leo237 leo237 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 85e87ca. Thanks for the replies. Nothing blocking remains. Box is unreleased, and the live V2 deploy and invoke show the fix works.

On platstdlib == stdlib on V2: I could not check it directly, because no fixture in the repo records platstdlib. The live test points the same way: box reports exec /usr/lib/python3.14, and the agent's TLS calls to Bedrock work, which needs _ssl from lib-dynload. That's good enough for this PR.

Deferred follow-ups (please reply with the backlog ticket IDs so they can be tracked):

  1. start.py: fail early when platstdlib != stdlib, or when stdlib is not a folder (the lib-dynload guard).
  2. context.ts: fix the runtimePythonStdlib doc for Container, where the value is the image's Python prefix.
  3. additions.test.ts: drop the dead inputs.python.prefix entry, and name the box source/version that BOX_SYSTEM_ROOTS / BOX_LOADER_FOLDERS were copied from.
  4. Before Box is released: detect a stale start.py (no BOX_PYTHON_STDLIB) at build time, or at least mention it in the V2 schema message or the release notes.
  5. The Python 3.10–3.13 e2e run is still not confirmed. The PR description says e2e was not run. Please run it, or note why it isn't needed, before Box is released.

@leo237 leo237 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving after the rebase onto box-integration (now including #2893). I compared the PR's two commits before and after: 855f3b9 is identical to a08503c, and 4a476cd matches a27a77b except for the conflict resolution in one doc comment, which drops the stale "no ffi shim" wording that #2893 removed. The follow-ups listed in my previous approval still apply.

@vvargu
vvargu merged commit 5df0ab3 into box-integration Nov 24, 2026
6 checks passed
@vvargu
vvargu deleted the fix/box-codezip-python-stdlib-grant branch November 24, 2026 06:50
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.

4 participants