diff --git a/src/assets/templates/box-codezip/start.py b/src/assets/templates/box-codezip/start.py index 8944f53ac..b84813124 100644 --- a/src/assets/templates/box-codezip/start.py +++ b/src/assets/templates/box-codezip/start.py @@ -3,15 +3,16 @@ # zip into a folder this user owns (box runs only a profile its user owns), exports the Python and # code paths that only the microVM knows, and hands over to `box run`. # -# The box profile reads the deployed resources, the gateway URL, the Python interpreter and the code -# directory from the environment through the @box/agentcore and @box/agentcore-codezip packs, and -# signs AWS routes with the execution role through a bare `aws://`. So there is nothing to fill in, -# no credentials to write, and no start.sh. +# The box profile reads the deployed resources, the gateway URL, the Python interpreter, its +# standard library and the code directory from the environment through the @box/agentcore and +# @box/agentcore-codezip packs, and signs AWS routes with the execution role through a bare +# `aws://`. So there is nothing to fill in, no credentials to write, and no start.sh. import json import os import re import shutil import sys +import sysconfig try: import tomllib @@ -91,7 +92,7 @@ def main(): "HOME": HOME, "BOX_CODE": CODE, "BOX_PYTHON": box_python(sys.executable, sys.version_info), - "BOX_PYTHON_PREFIX": sys.base_prefix, + "BOX_PYTHON_STDLIB": sysconfig.get_path("stdlib"), }, ) diff --git a/src/core/project/backends/boxStartPy.test.ts b/src/core/project/backends/boxStartPy.test.ts index f77c251b7..8317a9555 100644 --- a/src/core/project/backends/boxStartPy.test.ts +++ b/src/core/project/backends/boxStartPy.test.ts @@ -1,5 +1,5 @@ import { afterEach, describe, expect, test } from "bun:test"; -import { mkdtemp, rm, writeFile } from "node:fs/promises"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { serializeRuntimeProfile } from "../runtimeProfile/serialize"; @@ -92,3 +92,47 @@ describe.skipIf(PYTHON === undefined)("start.py with no tomllib, as on Python 3. expect(result.stderr).toContain("has a `policies` line start.py cannot read"); }); }); + +/** + * Runs start.py's main with its folders in a test folder and os.execve replaced, and prints what main + * hands box: the BOX_ variables, and the standard library and base prefix of this Python. + */ +const MAIN_HARNESS = ` +import json, os, sys, sysconfig, types +start = types.ModuleType("start") +start.__file__ = sys.argv[1] +exec(compile(open(sys.argv[1]).read(), "start.py", "exec"), start.__dict__) +folder = sys.argv[2] +start.DIST = os.path.join(folder, "dist") +start.BOX = os.path.join(start.DIST, "box") +start.HOME = os.path.join(folder, "home") +start.WORKSPACE = os.path.join(folder, "workspace") +start.PROFILE_DIR = os.path.join(folder, "profile") +start.PROFILE = os.path.join(start.PROFILE_DIR, "profile.toml") +def execve(path, args, env): + box = {name: value for name, value in env.items() if name.startswith("BOX_")} + print(json.dumps({"box": box, "stdlib": sysconfig.get_path("stdlib"), "prefix": sys.base_prefix})) + sys.exit(0) +os.execve = execve +start.main() +`; + +describe.skipIf(PYTHON === undefined)("start.py", () => { + test("gives box the standard library of the Runtime's Python, and not its base prefix, which box refuses as a system root (/usr on the Runtime)", async () => { + const folder = await mkdtemp(join(tmpdir(), "box-start-py-")); + folders.push(folder); + await mkdir(join(folder, "dist")); + await writeFile(join(folder, "dist", "profile.toml"), runtimeProfile()); + + const result = Bun.spawnSync([PYTHON!, "-c", MAIN_HARNESS, START_PY, folder]); + + expect(result.stderr.toString()).toBe(""); + const { box, stdlib, prefix } = JSON.parse(result.stdout.toString()) as { + box: Record; + stdlib: string; + prefix: string; + }; + expect(box.BOX_PYTHON_STDLIB).toBe(stdlib); + expect(Object.values(box)).not.toContain(prefix); + }); +}); diff --git a/src/core/project/runtimeProfile/__fixtures__/old-renderer-tables.json b/src/core/project/runtimeProfile/__fixtures__/old-renderer-tables.json index f8f75af16..54d6c9a95 100644 --- a/src/core/project/runtimeProfile/__fixtures__/old-renderer-tables.json +++ b/src/core/project/runtimeProfile/__fixtures__/old-renderer-tables.json @@ -43,13 +43,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -122,13 +122,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -207,13 +207,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -290,13 +290,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -369,13 +369,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -454,13 +454,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -532,13 +532,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -606,13 +606,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -686,13 +686,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -764,13 +764,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -838,13 +838,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -918,13 +918,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -989,13 +989,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1056,13 +1056,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1129,13 +1129,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1200,13 +1200,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1267,13 +1267,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1340,13 +1340,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1411,13 +1411,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1478,13 +1478,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1551,13 +1551,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1622,13 +1622,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1689,13 +1689,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1762,13 +1762,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1839,13 +1839,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1912,13 +1912,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -1991,13 +1991,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2068,13 +2068,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2141,13 +2141,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2220,13 +2220,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2292,13 +2292,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2360,13 +2360,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2434,13 +2434,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2506,13 +2506,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2574,13 +2574,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2648,13 +2648,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2724,13 +2724,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2796,13 +2796,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2874,13 +2874,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -2950,13 +2950,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -3022,13 +3022,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -3100,13 +3100,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -3171,13 +3171,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -3238,13 +3238,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -3311,13 +3311,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -3382,13 +3382,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -3449,13 +3449,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -3522,13 +3522,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -5679,13 +5679,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -5771,13 +5771,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -5869,13 +5869,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -5965,13 +5965,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6074,13 +6074,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6189,13 +6189,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6297,13 +6297,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6384,13 +6384,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6477,13 +6477,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6568,13 +6568,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6672,13 +6672,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6782,13 +6782,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6901,13 +6901,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -6999,13 +6999,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -7103,13 +7103,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -7205,13 +7205,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -7320,13 +7320,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -7441,13 +7441,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -7560,13 +7560,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -7658,13 +7658,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -7762,13 +7762,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -7864,13 +7864,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -7979,13 +7979,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -8100,13 +8100,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -8219,13 +8219,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -8317,13 +8317,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -8421,13 +8421,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -8523,13 +8523,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -8638,13 +8638,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -8759,13 +8759,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -8873,13 +8873,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -8966,13 +8966,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -9065,13 +9065,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -9162,13 +9162,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -9272,13 +9272,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -9388,13 +9388,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -10884,13 +10884,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -10975,13 +10975,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11072,13 +11072,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11167,13 +11167,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11275,13 +11275,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11389,13 +11389,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11496,13 +11496,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11582,13 +11582,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11674,13 +11674,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11764,13 +11764,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11867,13 +11867,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -11976,13 +11976,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -12083,13 +12083,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -12169,13 +12169,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -12261,13 +12261,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -12351,13 +12351,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -12454,13 +12454,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ @@ -12563,13 +12563,13 @@ "filesystem": { "read": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64" ], "exec": [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}" + "${{ inputs.python.stdlib }}" ] }, "ingress": [ diff --git a/src/core/project/runtimeProfile/context.ts b/src/core/project/runtimeProfile/context.ts index 9b7a21cf7..9a401611d 100644 --- a/src/core/project/runtimeProfile/context.ts +++ b/src/core/project/runtimeProfile/context.ts @@ -34,7 +34,7 @@ export function runtimePaths( localPythons: "/usr/local", runtimeCode: WORKSPACE, runtimePython: `${WORKSPACE}/.venv/bin/python`, - runtimePythonPrefix: "/usr/local", + runtimePythonStdlib: "/usr/local", shownCode: "/app/", }; } @@ -49,7 +49,7 @@ export function runtimePaths( localPythons: `${HOME}/.local/share/uv/python`, runtimeCode: RUNTIME_INPUTS.codeDir, runtimePython: RUNTIME_INPUTS.pythonPath, - runtimePythonPrefix: RUNTIME_INPUTS.pythonPrefix, + runtimePythonStdlib: RUNTIME_INPUTS.pythonStdlib, shownCode: root ? "./" : `${folder}/`, }; } diff --git a/src/core/project/runtimeProfile/derive.test.ts b/src/core/project/runtimeProfile/derive.test.ts index dff787616..e6b2d1243 100644 --- a/src/core/project/runtimeProfile/derive.test.ts +++ b/src/core/project/runtimeProfile/derive.test.ts @@ -81,7 +81,7 @@ describe("runtimePaths", () => { localPythons: "${{ home }}/.local/share/uv/python", runtimeCode: "${{ inputs.code.dir }}", runtimePython: "${{ inputs.python.path }}", - runtimePythonPrefix: "${{ inputs.python.prefix }}", + runtimePythonStdlib: "${{ inputs.python.stdlib }}", shownCode: "app/agent/", }); expect(runtimePaths({ ...CODEZIP, codeLocation: "./app/agent/" } as ProjectRuntime)).toEqual( diff --git a/src/core/project/runtimeProfile/projectPaths.ts b/src/core/project/runtimeProfile/projectPaths.ts index edbdd3b6f..8e348cd7b 100644 --- a/src/core/project/runtimeProfile/projectPaths.ts +++ b/src/core/project/runtimeProfile/projectPaths.ts @@ -7,7 +7,7 @@ * | --- | --- | * | the venv's Python, `/.venv/bin/python[3[.N]]` | `${{ inputs.python.path }}` | * | the venv, `/.venv` | `${{ inputs.code.dir }}`, where the Runtime installs the dependencies | - * | the uv Pythons, `${{ home }}/.local/share/uv/python` | `${{ inputs.python.prefix }}` | + * | the uv Pythons, `${{ home }}/.local/share/uv/python` | `${{ inputs.python.stdlib }}`, the standard library of the Runtime's Python | * | the code folder and each path in it, `[/...]` | `${{ inputs.code.dir }}[/...]` | * | another path of the project, of the home folder, or in the venv | none: a {@link PathProblem} | */ @@ -127,7 +127,7 @@ export function moveProjectPath( .replace(new RegExp(`${venv}${PATH_END}`, "g"), () => paths.runtimeCode) .replace( new RegExp(`${literal(paths.localPythons)}${PATH_END}`, "g"), - () => paths.runtimePythonPrefix, + () => paths.runtimePythonStdlib, ); if (new RegExp(`${venv}/`).test(moved)) return { problem: "venv" }; const result = moved.replace( diff --git a/src/core/project/runtimeProfile/rules/additions.test.ts b/src/core/project/runtimeProfile/rules/additions.test.ts index 1b3dc8202..fcbc47df7 100644 --- a/src/core/project/runtimeProfile/rules/additions.test.ts +++ b/src/core/project/runtimeProfile/rules/additions.test.ts @@ -145,7 +145,10 @@ const TELEMETRY_CASES: Record = { * the gateway fixture. The gateway fixture is recorded from renderRuntimeBoxProfile of * box-integration (f5503f02). The two template sets are recorded, with the default telemetry * target, from the renderer of aws/agentcore-cli#2867 (f40ebce7): box-integration (7252504c) with - * the `@box/` pack names and no ffi shim. + * the `@box/` pack names and no ffi shim. Their read and exec grants of the Runtime's Python name + * its standard library, `${{ inputs.python.stdlib }}`, where that renderer named its prefix, + * `${{ inputs.python.prefix }}`: the prefix is /usr on the Runtime, which box refuses as a system + * root. */ const OLD_RENDERER = JSON.parse( readFileSync(join(import.meta.dir, "..", "__fixtures__", "old-renderer-tables.json"), "utf8"), @@ -298,6 +301,86 @@ describe("deriveRuntimeProfile on each box template of create", () => { ); }); +/** + * The value of each input of @box/agentcore-codezip on a CodeZip AgentCore Runtime, as start.py + * exports it there. Measured on a PYTHON_3_14 Runtime: its Python is /usr/bin/python3.14, with the + * base prefix /usr and the standard library /usr/lib/python3.14. + */ +const CODEZIP_RUNTIME_INPUTS: Readonly> = { + "${{ inputs.code.dir }}": "/var/task", + "${{ inputs.python.path }}": "/usr/bin/python3.14", + "${{ inputs.python.stdlib }}": "/usr/lib/python3.14", + "${{ inputs.python.prefix }}": "/usr", +}; + +/** The system roots that box refuses as a grant in each list (the floor of Box Core). */ +const BOX_SYSTEM_ROOTS: ReadonlySet = new Set([ + "/", + "/bin", + "/boot", + "/dev", + "/etc", + "/opt", + "/proc", + "/root", + "/run", + "/sbin", + "/srv", + "/sys", + "/tmp", + "/usr", + "/usr/bin", + "/usr/local", + "/usr/sbin", + "/usr/share", + "/var", +]); + +/** The loader folders, which box grants only to `read`, as a whole tree. */ +const BOX_LOADER_FOLDERS: ReadonlySet = new Set([ + "/lib", + "/lib64", + "/usr/lib", + "/usr/lib64", +]); + +describe("the Runtime profile of each CodeZip box template of create", () => { + const templates = BOX_TEMPLATES.filter( + (template) => resolveRuntimeTemplateShortcut(template).build === "CodeZip", + ); + + test.each(templates)( + "lets the Runtime's Python read its standard library and load its native modules, and grants no folder that box refuses on the Runtime (%s)", + (template) => { + const input = resolveRuntimeTemplateShortcut(template); + const local = parse(renderBoxProfile("demo", input, CREATE_REGION)!) as TomlTable; + + const { profile, problems } = deriveRuntimeProfile(local, contextOf(createdRuntime(input))); + + expect(problems).toEqual([]); + const filesystem = agentOf(profile).filesystem as Record; + // A non-loader folder that box reads cannot map code, so lib-dynload needs exec too. + expect(filesystem.read).toContain("${{ inputs.python.stdlib }}"); + expect(filesystem.exec).toContain("${{ inputs.python.stdlib }}"); + for (const [list, grants] of Object.entries(filesystem)) { + for (const grant of grants) { + const path = typeof grant === "string" ? grant : (grant as { path: string }).path; + const onRuntime = CODEZIP_RUNTIME_INPUTS[path] ?? path; + const refused = + BOX_SYSTEM_ROOTS.has(onRuntime) || + (list !== "read" && BOX_LOADER_FOLDERS.has(onRuntime)); + expect({ list, path, onRuntime, refused }).toEqual({ + list, + path, + onRuntime, + refused: false, + }); + } + } + }, + ); +}); + describe("the additions rule", () => { const CODEZIP = runtimeOf("CodeZip"); const CONTAINER = runtimeOf("Container"); @@ -597,12 +680,12 @@ describe("the additions rule", () => { expect(agentOf(deriveRuntimeProfile(local, contextOf(CODEZIP)).profile).filesystem).toEqual({ read: [ "${{ inputs.code.dir }}", - "${{ inputs.python.prefix }}", + "${{ inputs.python.stdlib }}", "/usr/lib64", "/lib64", "${{ inputs.code.dir }}/data", ], - exec: ["${{ inputs.code.dir }}", "${{ inputs.python.prefix }}"], + exec: ["${{ inputs.code.dir }}", "${{ inputs.python.stdlib }}"], deny_write: ["${{ inputs.code.dir }}/secrets"], write: ["/tmp/agent"], }); diff --git a/src/core/project/runtimeProfile/rules/paths.test.ts b/src/core/project/runtimeProfile/rules/paths.test.ts index 075d6e1c3..59428d37a 100644 --- a/src/core/project/runtimeProfile/rules/paths.test.ts +++ b/src/core/project/runtimeProfile/rules/paths.test.ts @@ -48,7 +48,7 @@ const toml = (...lines: string[]) => lines.join("\n"); const APP = "${{ workspace }}"; const CODE = "${{ inputs.code.dir }}"; const PYTHON = "${{ inputs.python.path }}"; -const PREFIX = "${{ inputs.python.prefix }}"; +const STDLIB = "${{ inputs.python.stdlib }}"; const PYTHONPATH = CODE; /** A local profile with a stdio MCP server and a tool, each with a key build does not know. */ @@ -90,7 +90,7 @@ const LEAVES_ON_RUNTIME = { env: { NOTES_DIR: `${CODE}/notes`, LEVEL: "debug", PYTHONPATH }, // The venv moves to the code folder, which the first grant names already. filesystem: { - read: [CODE, { path: PREFIX, optional: true }], + read: [CODE, { path: STDLIB, optional: true }], }, network: { contain_egress: true }, }, @@ -213,10 +213,10 @@ describe("the paths rule", () => { // The agent's own PYTHONPATH is the additions rule's: this rule adds none to [agent]. env: { PYTHONPATH: `${CODE}/src:${CODE}`, PYTHON, LEVEL: "debug" }, filesystem: { - read: [CODE, { path: PREFIX, optional: true }], + read: [CODE, { path: STDLIB, optional: true }], exec: [ { path: CODE, optional: true }, - { path: PREFIX, optional: true }, + { path: STDLIB, optional: true }, ], write_file: [`${CODE}/out.json`], }, @@ -271,23 +271,23 @@ describe("the paths rule", () => { "[agent]", 'command = ["${{ inputs.python.path }}", "-m", "main"]', "[agent.env]", - `PYTHONPATH = "${PREFIX}/lib:${APP}/src:${APP}"`, + `PYTHONPATH = "${STDLIB}:${APP}/src:${APP}"`, "[mcp.notes]", 'type = "stdio"', `command = ["${APP}/.venv/bin/python3.15", "-m", "notes"]`, - `env = { PYTHONPATH = "${PREFIX}/lib:${APP}/lib:${APP}" }`, + `env = { PYTHONPATH = "${STDLIB}:${APP}/lib:${APP}" }`, ); expect(moved(text)).toEqual({ agent: { command: [PYTHON, "-m", "main"], - env: { PYTHONPATH: `${PREFIX}/lib:${CODE}/src:${CODE}` }, + env: { PYTHONPATH: `${STDLIB}:${CODE}/src:${CODE}` }, }, mcp: { notes: { type: "stdio", command: [PYTHON, "-m", "notes"], - env: { PYTHONPATH: `${PREFIX}/lib:${CODE}/lib:${CODE}` }, + env: { PYTHONPATH: `${STDLIB}:${CODE}/lib:${CODE}` }, }, }, }); diff --git a/src/core/project/runtimeProfile/rules/paths.ts b/src/core/project/runtimeProfile/rules/paths.ts index 8593ea27e..151589710 100644 --- a/src/core/project/runtimeProfile/rules/paths.ts +++ b/src/core/project/runtimeProfile/rules/paths.ts @@ -2,7 +2,7 @@ * Rule 4 of the derivation, the last: each path of the project and of the home folder, where it is * on AgentCore Runtime (`context.paths`). A container image keeps each path. On CodeZip, the venv's * Python goes to `${{ inputs.python.path }}`, the venv and the code folder go to - * `${{ inputs.code.dir }}`, and the uv Pythons go to `${{ inputs.python.prefix }}`. The paths move + * `${{ inputs.code.dir }}`, and the uv Pythons go to `${{ inputs.python.stdlib }}`. The paths move * in each key that can hold a path (projectPaths.ts): the `[agent]` command, env, and filesystem * lists, and each key of each stdio `[mcp.]` and `[tool.]`. Then each filesystem list * has one grant for each path. A leaf that runs the Runtime's Python gets the `PYTHONPATH` of the diff --git a/src/core/project/runtimeProfile/types.ts b/src/core/project/runtimeProfile/types.ts index 628d1520f..363110c03 100644 --- a/src/core/project/runtimeProfile/types.ts +++ b/src/core/project/runtimeProfile/types.ts @@ -27,8 +27,8 @@ export const RUNTIME_INPUTS = { codeDir: "${{ inputs.code.dir }}", /** The Python of a CodeZip Runtime (@box/agentcore-codezip). */ pythonPath: "${{ inputs.python.path }}", - /** The base prefix of that Python (@box/agentcore-codezip). */ - pythonPrefix: "${{ inputs.python.prefix }}", + /** The standard library of that Python, with its native modules (@box/agentcore-codezip). */ + pythonStdlib: "${{ inputs.python.stdlib }}", } as const; /** @@ -48,8 +48,11 @@ export interface RuntimePaths { readonly runtimeCode: string; /** The Python on the Runtime, for the venv's Python: `${{ inputs.python.path }}` on CodeZip. */ readonly runtimePython: string; - /** The prefix of that Python, for the uv Pythons: `${{ inputs.python.prefix }}` on CodeZip. */ - readonly runtimePythonPrefix: string; + /** + * The standard library of that Python, with its native modules, for the uv Pythons: + * `${{ inputs.python.stdlib }}` on CodeZip. + */ + readonly runtimePythonStdlib: string; /** The code folder as a message names it: `app/agent/`. */ readonly shownCode: string; } diff --git a/src/core/project/templates/boxProfile.test.ts b/src/core/project/templates/boxProfile.test.ts index b4f65b42a..c74b5d349 100644 --- a/src/core/project/templates/boxProfile.test.ts +++ b/src/core/project/templates/boxProfile.test.ts @@ -486,18 +486,20 @@ describe("renderAgentCoreCodeZipPack", () => { expect(toml().pack).toEqual({ name: "@box/agentcore-codezip", version: 1, kind: "support" }); }); - test("declares the Runtime Python and code directory from the environment start.py exports", () => { + test("declares the Runtime Python, its standard library, and the code directory from the environment start.py exports", () => { const { inputs } = toml(); expect(inputs.python.path.from).toBe("env:BOX_PYTHON"); - expect(inputs.python.prefix.from).toBe("env:BOX_PYTHON_PREFIX"); + expect(inputs.python.stdlib.from).toBe("env:BOX_PYTHON_STDLIB"); expect(inputs.code.dir.from).toBe("env:BOX_CODE"); + // The prefix of the Runtime's Python is /usr, which box refuses as a grant. + expect(inputs.python.prefix).toBeUndefined(); }); test("bounds the inputs that reach the agent command or a filesystem grant with a pattern", () => { const { inputs } = toml(); - // The Python path (command element 0) and the code dir (--app-dir) reach `command`; the prefix - // reaches the read and exec grants. - for (const input of [inputs.python.path, inputs.code.dir, inputs.python.prefix]) { + // The Python path (command element 0) and the code dir (--app-dir) reach `command`; the + // standard library reaches the read and exec grants. + for (const input of [inputs.python.path, inputs.code.dir, inputs.python.stdlib]) { const pattern = new RegExp(`^${input.pattern}$`); expect(pattern.test("/var/lang")).toBe(true); // Neither an empty value nor / may widen a grant to the whole filesystem. diff --git a/src/core/project/templates/boxProfile.ts b/src/core/project/templates/boxProfile.ts index 231f59ed8..27b7b5541 100644 --- a/src/core/project/templates/boxProfile.ts +++ b/src/core/project/templates/boxProfile.ts @@ -42,7 +42,7 @@ export const BOX_CODEZIP_DIST = ".box-dist"; /** The Runtime sets the gateway URL; start.py exports the CodeZip paths only the microVM knows. */ const BOX_GATEWAY_URL_ENV = "AGENTCORE_GATEWAY_BOX_URL"; const BOX_PYTHON_ENV = "BOX_PYTHON"; -const BOX_PYTHON_PREFIX_ENV = "BOX_PYTHON_PREFIX"; +const BOX_PYTHON_STDLIB_ENV = "BOX_PYTHON_STDLIB"; const BOX_CODE_ENV = "BOX_CODE"; /** @@ -411,10 +411,10 @@ function containerRunner(workloadPort: number, dev: boolean): Runner { /** * A CodeZip agent on AgentCore Runtime, in the paths of the local profile: the paths rule of the - * Runtime profile derivation moves them to the Runtime's code folder and Python. It does not - * reload. Box Core adds the loader folders itself and refuses exec on them, so they are read only. - * One grant may not sit inside another, so the Python's prefix covers its bin/ folder. The box - * starts in a writable folder outside the code, so nothing the agent runs needs `deny_write`. + * Runtime profile derivation moves them to the Runtime's code folder, Python, and standard library. + * It does not reload. Box Core adds the loader folders itself and refuses exec on them, so they are + * read only. The box starts in a writable folder outside the code, so nothing the agent runs needs + * `deny_write`. */ function runtimeCodeZipRunner(protocol: Protocol, appDir: string, workloadPort: number): Runner { // An A2A agent card advertises the URL of the Runtime, which @box/agentcore reads. @@ -675,10 +675,11 @@ ${agentEnv}`; /** * The `@box/agentcore-codezip` pack a CodeZip Runtime profile adds: the Runtime's Python interpreter - * and base prefix, and the read-only code directory, which only the microVM knows. start.py exports - * them ({@link BOX_PYTHON_ENV}, {@link BOX_PYTHON_PREFIX_ENV}, {@link BOX_CODE_ENV}) before it runs - * box, and the profile reads them through these inputs, so no start script fills the profile in. box - * finds the pack beside its binary at {@link AGENTCORE_CODEZIP_PACK_PATH}. + * and its standard library, and the read-only code directory, which only the microVM knows. + * start.py exports them ({@link BOX_PYTHON_ENV}, {@link BOX_PYTHON_STDLIB_ENV}, + * {@link BOX_CODE_ENV}) before it runs box, and the profile reads them through these inputs, so no + * start script fills the profile in. box finds the pack beside its binary at + * {@link AGENTCORE_CODEZIP_PACK_PATH}. */ export function renderAgentCoreCodeZipPack(): string { return `# The CodeZip Runtime's Python and code directory, read from the environment start.py exports. @@ -694,9 +695,9 @@ description = "The AgentCore Runtime's Python interpreter." from = ${str(`env:${BOX_PYTHON_ENV}`)} pattern = ${str(ABSOLUTE_PATH_PATTERN)} -[inputs.python.prefix] -description = "The Python interpreter's base prefix, for its standard library." -from = ${str(`env:${BOX_PYTHON_PREFIX_ENV}`)} +[inputs.python.stdlib] +description = "The Python interpreter's standard library, with its native modules." +from = ${str(`env:${BOX_PYTHON_STDLIB_ENV}`)} pattern = ${str(ABSOLUTE_PATH_PATTERN)} [inputs.code.dir]