@buildanagent/harness 0.0.0-bootstrap.0 → 0.1.0-alpha.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +54 -0
- package/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +717 -0
- package/dist/ablation.d.ts +2 -0
- package/dist/ablation.js +3 -0
- package/dist/ablation.js.map +1 -0
- package/dist/completion/check.d.ts +64 -0
- package/dist/completion/check.js +152 -0
- package/dist/completion/check.js.map +1 -0
- package/dist/completion/checks.d.ts +45 -0
- package/dist/completion/checks.js +173 -0
- package/dist/completion/checks.js.map +1 -0
- package/dist/completion/flags.d.ts +25 -0
- package/dist/completion/flags.js +87 -0
- package/dist/completion/flags.js.map +1 -0
- package/dist/completion/index.d.ts +8 -0
- package/dist/completion/index.js +9 -0
- package/dist/completion/index.js.map +1 -0
- package/dist/completion/snapshot.d.ts +33 -0
- package/dist/completion/snapshot.js +83 -0
- package/dist/completion/snapshot.js.map +1 -0
- package/dist/context/cap.d.ts +32 -0
- package/dist/context/cap.js +50 -0
- package/dist/context/cap.js.map +1 -0
- package/dist/context/estimate.d.ts +18 -0
- package/dist/context/estimate.js +20 -0
- package/dist/context/estimate.js.map +1 -0
- package/dist/context/file-spill.d.ts +5 -0
- package/dist/context/file-spill.js +25 -0
- package/dist/context/file-spill.js.map +1 -0
- package/dist/context/index.d.ts +10 -0
- package/dist/context/index.js +10 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/mask.d.ts +27 -0
- package/dist/context/mask.js +71 -0
- package/dist/context/mask.js.map +1 -0
- package/dist/context/mid-turn.d.ts +40 -0
- package/dist/context/mid-turn.js +82 -0
- package/dist/context/mid-turn.js.map +1 -0
- package/dist/context/policy.d.ts +9 -0
- package/dist/context/policy.js +140 -0
- package/dist/context/policy.js.map +1 -0
- package/dist/context/spill-ledger.d.ts +25 -0
- package/dist/context/spill-ledger.js +54 -0
- package/dist/context/spill-ledger.js.map +1 -0
- package/dist/context/spill.d.ts +6 -0
- package/dist/context/spill.js +14 -0
- package/dist/context/spill.js.map +1 -0
- package/dist/context/summarize.d.ts +53 -0
- package/dist/context/summarize.js +204 -0
- package/dist/context/summarize.js.map +1 -0
- package/dist/context/summary-template.d.ts +29 -0
- package/dist/context/summary-template.js +69 -0
- package/dist/context/summary-template.js.map +1 -0
- package/dist/context/types.d.ts +150 -0
- package/dist/context/types.js +2 -0
- package/dist/context/types.js.map +1 -0
- package/dist/context/write-cap.d.ts +19 -0
- package/dist/context/write-cap.js +41 -0
- package/dist/context/write-cap.js.map +1 -0
- package/dist/create-harness.d.ts +7 -0
- package/dist/create-harness.js +21 -0
- package/dist/create-harness.js.map +1 -0
- package/dist/credentials/addresses.d.ts +14 -0
- package/dist/credentials/addresses.js +144 -0
- package/dist/credentials/addresses.js.map +1 -0
- package/dist/credentials/allowlist.d.ts +34 -0
- package/dist/credentials/allowlist.js +77 -0
- package/dist/credentials/allowlist.js.map +1 -0
- package/dist/credentials/egress-proxy.d.ts +70 -0
- package/dist/credentials/egress-proxy.js +482 -0
- package/dist/credentials/egress-proxy.js.map +1 -0
- package/dist/credentials/index.d.ts +9 -0
- package/dist/credentials/index.js +10 -0
- package/dist/credentials/index.js.map +1 -0
- package/dist/credentials/scrub.d.ts +16 -0
- package/dist/credentials/scrub.js +93 -0
- package/dist/credentials/scrub.js.map +1 -0
- package/dist/errors.d.ts +56 -0
- package/dist/errors.js +63 -0
- package/dist/errors.js.map +1 -0
- package/dist/extensions/compose.d.ts +27 -0
- package/dist/extensions/compose.js +83 -0
- package/dist/extensions/compose.js.map +1 -0
- package/dist/extensions/context-files-node.d.ts +28 -0
- package/dist/extensions/context-files-node.js +74 -0
- package/dist/extensions/context-files-node.js.map +1 -0
- package/dist/extensions/context-files.d.ts +68 -0
- package/dist/extensions/context-files.js +214 -0
- package/dist/extensions/context-files.js.map +1 -0
- package/dist/extensions/digest.d.ts +6 -0
- package/dist/extensions/digest.js +68 -0
- package/dist/extensions/digest.js.map +1 -0
- package/dist/extensions/index.d.ts +10 -0
- package/dist/extensions/index.js +10 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/load.d.ts +42 -0
- package/dist/extensions/load.js +211 -0
- package/dist/extensions/load.js.map +1 -0
- package/dist/extensions/lock.d.ts +8 -0
- package/dist/extensions/lock.js +95 -0
- package/dist/extensions/lock.js.map +1 -0
- package/dist/extensions/node.d.ts +10 -0
- package/dist/extensions/node.js +11 -0
- package/dist/extensions/node.js.map +1 -0
- package/dist/extensions/project-dirs.d.ts +24 -0
- package/dist/extensions/project-dirs.js +97 -0
- package/dist/extensions/project-dirs.js.map +1 -0
- package/dist/extensions/skills-node.d.ts +34 -0
- package/dist/extensions/skills-node.js +123 -0
- package/dist/extensions/skills-node.js.map +1 -0
- package/dist/extensions/skills.d.ts +51 -0
- package/dist/extensions/skills.js +175 -0
- package/dist/extensions/skills.js.map +1 -0
- package/dist/extensions/trust-file.d.ts +3 -0
- package/dist/extensions/trust-file.js +62 -0
- package/dist/extensions/trust-file.js.map +1 -0
- package/dist/extensions/trust-store-node.d.ts +10 -0
- package/dist/extensions/trust-store-node.js +33 -0
- package/dist/extensions/trust-store-node.js.map +1 -0
- package/dist/extensions/types.d.ts +42 -0
- package/dist/extensions/types.js +2 -0
- package/dist/extensions/types.js.map +1 -0
- package/dist/harness.d.ts +156 -0
- package/dist/harness.js +2 -0
- package/dist/harness.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/connection.d.ts +22 -0
- package/dist/mcp/connection.js +267 -0
- package/dist/mcp/connection.js.map +1 -0
- package/dist/mcp/content.d.ts +27 -0
- package/dist/mcp/content.js +177 -0
- package/dist/mcp/content.js.map +1 -0
- package/dist/mcp/errors.d.ts +19 -0
- package/dist/mcp/errors.js +21 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/mcp/index.js +10 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +7 -0
- package/dist/mcp/manager.js +173 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/record.d.ts +7 -0
- package/dist/mcp/record.js +20 -0
- package/dist/mcp/record.js.map +1 -0
- package/dist/mcp/stdio.d.ts +39 -0
- package/dist/mcp/stdio.js +382 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/mcp/types.d.ts +172 -0
- package/dist/mcp/types.js +2 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +3 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/permissions/default-rules.d.ts +7 -0
- package/dist/permissions/default-rules.js +42 -0
- package/dist/permissions/default-rules.js.map +1 -0
- package/dist/permissions/errors.d.ts +11 -0
- package/dist/permissions/errors.js +14 -0
- package/dist/permissions/errors.js.map +1 -0
- package/dist/permissions/index.d.ts +9 -0
- package/dist/permissions/index.js +9 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/permissions/match.d.ts +33 -0
- package/dist/permissions/match.js +287 -0
- package/dist/permissions/match.js.map +1 -0
- package/dist/permissions/pipeline.d.ts +9 -0
- package/dist/permissions/pipeline.js +235 -0
- package/dist/permissions/pipeline.js.map +1 -0
- package/dist/permissions/rules.d.ts +22 -0
- package/dist/permissions/rules.js +74 -0
- package/dist/permissions/rules.js.map +1 -0
- package/dist/permissions/shadow.d.ts +5 -0
- package/dist/permissions/shadow.js +22 -0
- package/dist/permissions/shadow.js.map +1 -0
- package/dist/permissions/types.d.ts +104 -0
- package/dist/permissions/types.js +2 -0
- package/dist/permissions/types.js.map +1 -0
- package/dist/sandbox/base.d.ts +35 -0
- package/dist/sandbox/base.js +60 -0
- package/dist/sandbox/base.js.map +1 -0
- package/dist/sandbox/docker/index.d.ts +35 -0
- package/dist/sandbox/docker/index.js +448 -0
- package/dist/sandbox/docker/index.js.map +1 -0
- package/dist/sandbox/errors.d.ts +16 -0
- package/dist/sandbox/errors.js +22 -0
- package/dist/sandbox/errors.js.map +1 -0
- package/dist/sandbox/host-files.d.ts +63 -0
- package/dist/sandbox/host-files.js +248 -0
- package/dist/sandbox/host-files.js.map +1 -0
- package/dist/sandbox/index.d.ts +8 -0
- package/dist/sandbox/index.js +8 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/none.d.ts +17 -0
- package/dist/sandbox/none.js +108 -0
- package/dist/sandbox/none.js.map +1 -0
- package/dist/sandbox/process.d.ts +61 -0
- package/dist/sandbox/process.js +253 -0
- package/dist/sandbox/process.js.map +1 -0
- package/dist/sandbox/spawn-env.d.ts +20 -0
- package/dist/sandbox/spawn-env.js +128 -0
- package/dist/sandbox/spawn-env.js.map +1 -0
- package/dist/sandbox/srt/index.d.ts +35 -0
- package/dist/sandbox/srt/index.js +264 -0
- package/dist/sandbox/srt/index.js.map +1 -0
- package/dist/sandbox/srt/settings.d.ts +48 -0
- package/dist/sandbox/srt/settings.js +31 -0
- package/dist/sandbox/srt/settings.js.map +1 -0
- package/dist/sandbox/types.d.ts +88 -0
- package/dist/sandbox/types.js +6 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/server/answers.d.ts +16 -0
- package/dist/server/answers.js +43 -0
- package/dist/server/answers.js.map +1 -0
- package/dist/server/connection.d.ts +99 -0
- package/dist/server/connection.js +309 -0
- package/dist/server/connection.js.map +1 -0
- package/dist/server/dispatcher.d.ts +86 -0
- package/dist/server/dispatcher.js +800 -0
- package/dist/server/dispatcher.js.map +1 -0
- package/dist/server/index.d.ts +13 -0
- package/dist/server/index.js +12 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/local-transport.d.ts +44 -0
- package/dist/server/local-transport.js +103 -0
- package/dist/server/local-transport.js.map +1 -0
- package/dist/server/outbox.d.ts +31 -0
- package/dist/server/outbox.js +130 -0
- package/dist/server/outbox.js.map +1 -0
- package/dist/server/params.d.ts +25 -0
- package/dist/server/params.js +112 -0
- package/dist/server/params.js.map +1 -0
- package/dist/server/protocol.schema.json +2448 -0
- package/dist/server/rpc-session.d.ts +43 -0
- package/dist/server/rpc-session.js +167 -0
- package/dist/server/rpc-session.js.map +1 -0
- package/dist/server/stdio-streams.d.ts +67 -0
- package/dist/server/stdio-streams.js +218 -0
- package/dist/server/stdio-streams.js.map +1 -0
- package/dist/server/stdio.d.ts +59 -0
- package/dist/server/stdio.js +189 -0
- package/dist/server/stdio.js.map +1 -0
- package/dist/server/websocket.d.ts +106 -0
- package/dist/server/websocket.js +327 -0
- package/dist/server/websocket.js.map +1 -0
- package/dist/session/approvals.d.ts +81 -0
- package/dist/session/approvals.js +217 -0
- package/dist/session/approvals.js.map +1 -0
- package/dist/session/code-call-log.d.ts +42 -0
- package/dist/session/code-call-log.js +63 -0
- package/dist/session/code-call-log.js.map +1 -0
- package/dist/session/code-call-result.d.ts +19 -0
- package/dist/session/code-call-result.js +95 -0
- package/dist/session/code-call-result.js.map +1 -0
- package/dist/session/code-call.d.ts +49 -0
- package/dist/session/code-call.js +345 -0
- package/dist/session/code-call.js.map +1 -0
- package/dist/session/effect-scope.d.ts +11 -0
- package/dist/session/effect-scope.js +10 -0
- package/dist/session/effect-scope.js.map +1 -0
- package/dist/session/errors.d.ts +19 -0
- package/dist/session/errors.js +27 -0
- package/dist/session/errors.js.map +1 -0
- package/dist/session/file-index.d.ts +8 -0
- package/dist/session/file-index.js +70 -0
- package/dist/session/file-index.js.map +1 -0
- package/dist/session/file-key-store.d.ts +16 -0
- package/dist/session/file-key-store.js +169 -0
- package/dist/session/file-key-store.js.map +1 -0
- package/dist/session/file-lock.d.ts +52 -0
- package/dist/session/file-lock.js +324 -0
- package/dist/session/file-lock.js.map +1 -0
- package/dist/session/index.d.ts +22 -0
- package/dist/session/index.js +20 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/jsonl-store.d.ts +37 -0
- package/dist/session/jsonl-store.js +386 -0
- package/dist/session/jsonl-store.js.map +1 -0
- package/dist/session/jsonl.d.ts +9 -0
- package/dist/session/jsonl.js +10 -0
- package/dist/session/jsonl.js.map +1 -0
- package/dist/session/lock.d.ts +19 -0
- package/dist/session/lock.js +2 -0
- package/dist/session/lock.js.map +1 -0
- package/dist/session/memory-store.d.ts +12 -0
- package/dist/session/memory-store.js +60 -0
- package/dist/session/memory-store.js.map +1 -0
- package/dist/session/migrate.d.ts +41 -0
- package/dist/session/migrate.js +86 -0
- package/dist/session/migrate.js.map +1 -0
- package/dist/session/pointer.d.ts +15 -0
- package/dist/session/pointer.js +22 -0
- package/dist/session/pointer.js.map +1 -0
- package/dist/session/rebuild.d.ts +53 -0
- package/dist/session/rebuild.js +230 -0
- package/dist/session/rebuild.js.map +1 -0
- package/dist/session/resume.d.ts +26 -0
- package/dist/session/resume.js +128 -0
- package/dist/session/resume.js.map +1 -0
- package/dist/session/retention.d.ts +97 -0
- package/dist/session/retention.js +702 -0
- package/dist/session/retention.js.map +1 -0
- package/dist/session/runner.d.ts +156 -0
- package/dist/session/runner.js +656 -0
- package/dist/session/runner.js.map +1 -0
- package/dist/session/scheduler.d.ts +47 -0
- package/dist/session/scheduler.js +85 -0
- package/dist/session/scheduler.js.map +1 -0
- package/dist/session/secret-key-store.d.ts +47 -0
- package/dist/session/secret-key-store.js +79 -0
- package/dist/session/secret-key-store.js.map +1 -0
- package/dist/session/session.d.ts +106 -0
- package/dist/session/session.js +353 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/sticky.d.ts +48 -0
- package/dist/session/sticky.js +232 -0
- package/dist/session/sticky.js.map +1 -0
- package/dist/session/store.d.ts +108 -0
- package/dist/session/store.js +163 -0
- package/dist/session/store.js.map +1 -0
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +3 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/testing/fake-sandbox.d.ts +34 -0
- package/dist/testing/fake-sandbox.js +221 -0
- package/dist/testing/fake-sandbox.js.map +1 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/key-store-conformance.d.ts +22 -0
- package/dist/testing/key-store-conformance.js +97 -0
- package/dist/testing/key-store-conformance.js.map +1 -0
- package/dist/testing/run-cases.d.ts +21 -0
- package/dist/testing/run-cases.js +20 -0
- package/dist/testing/run-cases.js.map +1 -0
- package/dist/testing/sandbox-conformance.d.ts +64 -0
- package/dist/testing/sandbox-conformance.js +361 -0
- package/dist/testing/sandbox-conformance.js.map +1 -0
- package/dist/testing/scheduler-conformance.d.ts +32 -0
- package/dist/testing/scheduler-conformance.js +72 -0
- package/dist/testing/scheduler-conformance.js.map +1 -0
- package/dist/testing/store-conformance.d.ts +21 -0
- package/dist/testing/store-conformance.js +320 -0
- package/dist/testing/store-conformance.js.map +1 -0
- package/dist/tools/errors.d.ts +13 -0
- package/dist/tools/errors.js +17 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.js +8 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +3 -0
- package/dist/tools/registry.js +234 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/tool-search.d.ts +30 -0
- package/dist/tools/tool-search.js +118 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/types.d.ts +106 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/llms.txt +435 -0
- package/package.json +119 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-env.js","sourceRoot":"","sources":["../../src/sandbox/spawn-env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,mHAAmH;AACnH,MAAM,YAAY,GAAG,8BAA8B,CAAC;AACpD,MAAM,YAAY,GAAG,SAAS,CAAC;AAC/B,mGAAmG;AACnG,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE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awns gets, so an inherited credential can never\n * reach a child (AGENTS.md, \"Running third-party code\"; ADR 0036). It is Node-only, because it reads the parent's\n * environment and makes a temp folder, so it loads Node's modules by `process.getBuiltinModule()` when it is called,\n * not by an import, and the sandbox entry still loads on a runtime without them.\n */\nimport { HarnessError } from \"../errors.js\";\n\n// Where a child finds its programs when the parent has no PATH, which only a parent started without a shell lacks.\nconst DEFAULT_PATH = \"/usr/local/bin:/usr/bin:/bin\";\nconst DEFAULT_LANG = \"C.UTF-8\";\n// The variables every child gets, by `spawnEnv()` itself. A caller names no other source for them.\nconst RESERVED = [\"PATH\", \"HOME\", \"TMPDIR\", \"LANG\"];\nconst NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n// A name that says it holds a credential, matched by each `_`-separated segment so `GIT_AUTHOR_NAME` and\n// `KEYBOARD_LAYOUT` pass and `GH_PAT` and `ANTHROPIC_API_KEY` don't. These reach a child only through `extra`, where the\n// caller writes the value in code, such as a dummy key for a proxy, and never by being copied from the parent.\n// A word that ends a part catches a joined one such as `GITHUBTOKEN`; a short word must be the whole part, so `PATH` and\n// `PASSIVE` pass. `PASS` and `AUTH` refuse a name like `PASS_THROUGH`, which is the safe side: it passes as an `extra`.\nconst CREDENTIAL_ENDING = /(KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIALS?)$/;\nconst CREDENTIAL_WORD = /^(PASS|PGPASS|PAT|AUTH|AUTHORIZATION|COOKIE|DSN)$/;\n// Names that hold a credential without a word that says so: a connection string or a proxy URL can carry a password.\nconst CREDENTIAL_NAMES = new Set([\n \"DATABASE_URL\",\n \"REDIS_URL\",\n \"MONGODB_URI\",\n \"HTTP_PROXY\",\n \"HTTPS_PROXY\",\n \"ALL_PROXY\",\n \"NPM_CONFIG__AUTH\",\n]);\n// Names that make a program load the caller's code or change where it looks, which a copy from the parent must not do.\nconst LOADER_NAMES = new Set([\n \"NODE_OPTIONS\",\n \"LD_PRELOAD\",\n \"LD_LIBRARY_PATH\",\n \"DYLD_INSERT_LIBRARIES\",\n \"DYLD_LIBRARY_PATH\",\n \"BASH_ENV\",\n \"ENV\",\n \"NODE_PATH\",\n \"NODE_EXTRA_CA_CERTS\",\n \"PYTHONPATH\",\n \"PYTHONSTARTUP\",\n \"PERL5OPT\",\n \"RUBYOPT\",\n \"LD_AUDIT\",\n \"GIT_SSH_COMMAND\",\n \"GIT_ASKPASS\",\n \"GIT_CONFIG_GLOBAL\",\n \"GIT_CONFIG_COUNT\",\n]);\n\nfunction looksLikeCredential(name: string): boolean {\n const upper = name.toUpperCase();\n return (\n CREDENTIAL_NAMES.has(upper) ||\n upper.split(\"_\").some((part) => CREDENTIAL_ENDING.test(part) || CREDENTIAL_WORD.test(part))\n );\n}\n\n// The parent's PATH without an entry that isn't absolute, because \".\" or an empty entry would run a program from\n// whatever folder a command starts in. It falls back to `DEFAULT_PATH` when nothing absolute is left.\nfunction safePath(parentPath: string | undefined, path: typeof import(\"node:path\")): string {\n const kept = (parentPath ?? \"\").split(path.delimiter).filter((entry) => path.isAbsolute(entry));\n return kept.length > 0 ? kept.join(path.delimiter) : DEFAULT_PATH;\n}\n\nfunction refuse(message: string): HarnessError {\n return new HarnessError(\"invalid_spawn_env\", `spawnEnv: ${message}`);\n}\n\nfunction checkName(name: string): void {\n if (!NAME.test(name)) throw refuse(`${JSON.stringify(name)} is not a valid variable name`);\n}\n\nfunction checkValue(name: string, value: unknown): asserts value is string {\n if (typeof value !== \"string\" || value.includes(\"\\0\")) {\n throw refuse(`the value of ${name} must be a string without a NUL character`);\n }\n}\n\n/**\n * The environment for a spawned process: `PATH`, a fresh temp `HOME`, `TMPDIR` and `LANG`, plus the parent variables\n * named in `allow` that are set, plus every `extra`. Nothing else is copied. `HOME` is a new folder under the temp\n * directory on each call, which the caller removes when the process is done, so a tool that writes dotfiles never\n * touches the real home.\n *\n * `PATH` is the parent's with every entry that isn't absolute removed, and `TMPDIR` is the shared temp directory.\n * When `extra` sets `HOME`, no temp folder is made.\n *\n * `allow` takes plain names, such as `DOCKER_HOST`. It refuses a reserved name (`PATH`, `HOME`, `TMPDIR`, `LANG`), which\n * is always set already; a name that looks like a credential, because a `_`-separated part of it is `KEY`, `TOKEN`,\n * `SECRET`, `PASSWORD`, `PAT`, `AUTH` and the like, or because it is a connection string or a proxy URL such as\n * `DATABASE_URL`; and a name that makes a program load code, such as `NODE_OPTIONS` or `LD_PRELOAD`. A credential can\n * reach a child only as an explicit `extra`. The check goes by name, so it can't catch a credential under an\n * unremarkable name. `extra` overrides everything and holds the values the caller writes itself.\n *\n * Throws a `HarnessError`, code `invalid_spawn_env`, for a name that isn't a variable name or a value that isn't a\n * string without a NUL character.\n */\nexport function spawnEnv(\n allow: readonly string[],\n extra: Readonly<Record<string, string>> = {},\n): Record<string, string> {\n const fs = process.getBuiltinModule(\"node:fs\");\n const os = process.getBuiltinModule(\"node:os\");\n const path = process.getBuiltinModule(\"node:path\");\n for (const name of allow) {\n checkName(name);\n if (RESERVED.includes(name)) throw refuse(`${name} is always set, so it can't be allowed`);\n if (LOADER_NAMES.has(name.toUpperCase())) {\n throw refuse(`${name} changes what a program loads, so it can't be copied from the parent; pass it in \\`extra\\``);\n }\n if (looksLikeCredential(name)) {\n throw refuse(\n `${name} looks like a credential, so it can't be copied from the parent; pass it in \\`extra\\` if the child needs it`,\n );\n }\n }\n for (const [name, value] of Object.entries(extra)) {\n checkName(name);\n checkValue(name, value);\n }\n // A caller's own HOME replaces ours, so making a folder for it would leave one behind that nothing removes.\n const home = \"HOME\" in extra ? extra.HOME : fs.mkdtempSync(path.join(os.tmpdir(), \"buildanagent-home-\"));\n const env: Record<string, string> = {\n PATH: safePath(process.env.PATH, path),\n HOME: home as string,\n TMPDIR: os.tmpdir(),\n LANG: process.env.LANG ?? DEFAULT_LANG,\n };\n for (const name of allow) {\n const value = process.env[name];\n if (value !== undefined) env[name] = value;\n }\n return { ...env, ...extra };\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SandboxClient } from "../types.js";
|
|
2
|
+
export type { SrtPathEntry, SrtSettings, SrtSettingsInput } from "./settings.js";
|
|
3
|
+
export { srtSettings } from "./settings.js";
|
|
4
|
+
/** The options of `srtSandbox()`. */
|
|
5
|
+
export interface SrtSandboxOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The `srt` executable. Without it the backend runs the `srt` that the installed `@anthropic-ai/sandbox-runtime`
|
|
8
|
+
* package ships, with this process's Node. A binary from elsewhere must have its own install folder in
|
|
9
|
+
* `extraReadRoots`, because `srt` reads its helper program from there inside the sandbox.
|
|
10
|
+
*/
|
|
11
|
+
readonly binary?: string;
|
|
12
|
+
/** Folders to read besides the policy's roots and the system's, such as the folder a toolchain is installed in. */
|
|
13
|
+
readonly extraReadRoots?: readonly string[];
|
|
14
|
+
/** Folders that stay read-only even inside a write root, such as the session's own log folder. */
|
|
15
|
+
readonly denyWrite?: readonly string[];
|
|
16
|
+
/** An upstream HTTP proxy that the allowed traffic goes through, for a host that sits behind one. */
|
|
17
|
+
readonly parentProxy?: {
|
|
18
|
+
readonly http?: string;
|
|
19
|
+
readonly https?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** The system folders a program needs to start. Each one that exists is readable, and nothing else outside the roots. */
|
|
23
|
+
export declare const SRT_SYSTEM_READ_ROOTS: readonly string[];
|
|
24
|
+
/**
|
|
25
|
+
* The variables `srt` 0.0.83 adds to a command's environment, which are its proxy settings and the few that go with
|
|
26
|
+
* them. A command sees these besides the variables it was given, so a test that compares environments lists them.
|
|
27
|
+
*/
|
|
28
|
+
export declare const SRT_ADDED_ENVIRONMENT: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* Builds the `srt` backend. `provision()` checks the platform, the programs `srt` needs and `srt` itself, by running a
|
|
31
|
+
* command that does nothing, so a host that can't confine a process throws `SandboxUnavailableError` and runs nothing.
|
|
32
|
+
* The policy's roots, `extraReadRoots` and `denyWrite` must be absolute folders other than `/`. Each command runs under
|
|
33
|
+
* its own `srt`, so a command sees the proxy variables `srt` adds to its environment, besides those it was given.
|
|
34
|
+
*/
|
|
35
|
+
export declare function srtSandbox(options?: SrtSandboxOptions): SandboxClient;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@buildanagent/harness/sandbox/srt`: the OS-tier backend. It runs each command under Anthropic's `srt` sandbox
|
|
3
|
+
* runtime, which uses bubblewrap on Linux and starts a proxy that allows only the policy's hosts. It claims to stop
|
|
4
|
+
* `mistakes` and `exfiltration`, never a `hostile_process`: the kernel is shared with the host, and `srt` is a
|
|
5
|
+
* pre-1.0 beta (as of November 2026). Only Linux is supported, because it is the only platform this backend is tested
|
|
6
|
+
* on. A backend that can't start throws `SandboxUnavailableError` and runs nothing. It is Node-only.
|
|
7
|
+
*
|
|
8
|
+
* The file calls run in the host, not under `srt`: two `srt` processes in one workspace can disturb each other, because
|
|
9
|
+
* each makes and removes empty files there. A path outside the roots is refused by its real path, so a symlink that
|
|
10
|
+
* leads out is refused too, and the opened file is checked again through `/proc`, so a path swapped for a link in
|
|
11
|
+
* between is caught. A hostile process could still win that race, which is why no `hostile_process` stop is claimed.
|
|
12
|
+
*/
|
|
13
|
+
import { HarnessError } from "../../errors.js";
|
|
14
|
+
import { BackendSandbox } from "../base.js";
|
|
15
|
+
import { SandboxUnavailableError } from "../errors.js";
|
|
16
|
+
import { absolutePath, checkPaths, existing, findOnPath, HostFiles, isProtectedPath, realOrSelf, workspaceRoot, } from "../host-files.js";
|
|
17
|
+
import { nodeModules, ProcessRunner } from "../process.js";
|
|
18
|
+
import { srtSettings } from "./settings.js";
|
|
19
|
+
export { srtSettings } from "./settings.js";
|
|
20
|
+
/** The system folders a program needs to start. Each one that exists is readable, and nothing else outside the roots. */
|
|
21
|
+
export const SRT_SYSTEM_READ_ROOTS = [
|
|
22
|
+
"/usr",
|
|
23
|
+
"/bin",
|
|
24
|
+
"/sbin",
|
|
25
|
+
"/lib",
|
|
26
|
+
"/lib32",
|
|
27
|
+
"/lib64",
|
|
28
|
+
"/libx32",
|
|
29
|
+
"/etc",
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* The variables `srt` 0.0.83 adds to a command's environment, which are its proxy settings and the few that go with
|
|
33
|
+
* them. A command sees these besides the variables it was given, so a test that compares environments lists them.
|
|
34
|
+
*/
|
|
35
|
+
export const SRT_ADDED_ENVIRONMENT = [
|
|
36
|
+
"ALL_PROXY",
|
|
37
|
+
"CLAUDE_CODE_HOST_HTTP_PROXY_PORT",
|
|
38
|
+
"CLAUDE_CODE_HOST_SOCKS_PROXY_PORT",
|
|
39
|
+
"CLOUDSDK_PROXY_ADDRESS",
|
|
40
|
+
"CLOUDSDK_PROXY_PASSWORD",
|
|
41
|
+
"CLOUDSDK_PROXY_PORT",
|
|
42
|
+
"CLOUDSDK_PROXY_TYPE",
|
|
43
|
+
"CLOUDSDK_PROXY_USERNAME",
|
|
44
|
+
"DOCKER_HTTPS_PROXY",
|
|
45
|
+
"DOCKER_HTTP_PROXY",
|
|
46
|
+
"FTP_PROXY",
|
|
47
|
+
"GIT_CONFIG_PARAMETERS",
|
|
48
|
+
"GIT_SSH_COMMAND",
|
|
49
|
+
"GRPC_PROXY",
|
|
50
|
+
"HTTPS_PROXY",
|
|
51
|
+
"HTTP_PROXY",
|
|
52
|
+
"JAVA_TOOL_OPTIONS",
|
|
53
|
+
"NO_PROXY",
|
|
54
|
+
"RSYNC_PROXY",
|
|
55
|
+
"SANDBOX_RUNTIME",
|
|
56
|
+
"all_proxy",
|
|
57
|
+
"ftp_proxy",
|
|
58
|
+
"grpc_proxy",
|
|
59
|
+
"http_proxy",
|
|
60
|
+
"https_proxy",
|
|
61
|
+
"no_proxy",
|
|
62
|
+
];
|
|
63
|
+
/** The programs `srt` runs on Linux, which it finds on the `PATH`. */
|
|
64
|
+
const REQUIRED_PROGRAMS = ["bwrap", "socat"];
|
|
65
|
+
const PROBE_TIMEOUT_MS = 20_000;
|
|
66
|
+
// How long `srt` has to clean up after a `SIGTERM` before the command's whole group is killed.
|
|
67
|
+
const GRACE_MS = 2000;
|
|
68
|
+
/** How to start `srt`, or a `SandboxUnavailableError` when there is nothing to start. */
|
|
69
|
+
async function srtCommand(modules, binary) {
|
|
70
|
+
if (binary !== undefined) {
|
|
71
|
+
// Resolved once against this process's folder, because it is started from the workspace.
|
|
72
|
+
const program = modules.path.resolve(binary);
|
|
73
|
+
try {
|
|
74
|
+
await modules.fs.access(program, modules.fs.constants.X_OK);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw new SandboxUnavailableError("srt", `${binary} is not an executable file`, { cause: error });
|
|
78
|
+
}
|
|
79
|
+
return { program, args: [], readRoots: [] };
|
|
80
|
+
}
|
|
81
|
+
let cli;
|
|
82
|
+
try {
|
|
83
|
+
const url = import.meta.resolve("@anthropic-ai/sandbox-runtime/dist/cli.js");
|
|
84
|
+
cli = await modules.fs.realpath(modules.url.fileURLToPath(url));
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
throw new SandboxUnavailableError("srt", "the @anthropic-ai/sandbox-runtime package is not installed", {
|
|
88
|
+
cause: error,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// `srt` runs its seccomp helper from the package's own folder, inside the sandbox.
|
|
92
|
+
return { program: process.execPath, args: [cli], readRoots: [modules.path.resolve(cli, "..", "..", "vendor")] };
|
|
93
|
+
}
|
|
94
|
+
/** A `SandboxUnavailableError` unless this platform and host can run `srt`, looking for its programs on `hostPath`. */
|
|
95
|
+
async function checkHost(modules, hostPath) {
|
|
96
|
+
if (process.platform !== "linux") {
|
|
97
|
+
throw new SandboxUnavailableError("srt", `only Linux is supported, because it is the only platform this backend is tested on, and this is ${process.platform}`);
|
|
98
|
+
}
|
|
99
|
+
for (const program of REQUIRED_PROGRAMS) {
|
|
100
|
+
if ((await findOnPath(modules, hostPath, program)) === undefined) {
|
|
101
|
+
throw new SandboxUnavailableError("srt", `${program} is not on the PATH, and srt needs it on Linux`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// A variable name that `env` can set, which is every name a process can be given.
|
|
106
|
+
const VARIABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
107
|
+
class SrtSandbox extends BackendSandbox {
|
|
108
|
+
runner;
|
|
109
|
+
state;
|
|
110
|
+
constructor(state) {
|
|
111
|
+
super(state);
|
|
112
|
+
this.state = state;
|
|
113
|
+
this.runner = new ProcessRunner(state.modules);
|
|
114
|
+
}
|
|
115
|
+
/** The program that starts `srt`. */
|
|
116
|
+
get program() {
|
|
117
|
+
return this.state.command.program;
|
|
118
|
+
}
|
|
119
|
+
/** The arguments that start `srt` with this sandbox's settings, then run `inner`. */
|
|
120
|
+
srtArguments(inner) {
|
|
121
|
+
return [...this.state.command.args, "--settings", this.state.settingsFile, "--", ...inner];
|
|
122
|
+
}
|
|
123
|
+
/** The environment `srt` itself runs with: where to find its programs, and where to make its sockets. Nothing else. */
|
|
124
|
+
launchEnvironment() {
|
|
125
|
+
return { PATH: this.state.hostPath, TMPDIR: this.state.runFolder };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The command that runs inside `srt`. `env` sets the command's whole environment from `srt`'s own, so a variable that
|
|
129
|
+
* makes a program load code, such as `NODE_OPTIONS`, never reaches `srt` or the programs it starts outside the
|
|
130
|
+
* sandbox. The `--` ends `env`'s options, so a first word that starts with `-` is a program name.
|
|
131
|
+
*/
|
|
132
|
+
innerCommand(command, env) {
|
|
133
|
+
const unset = [];
|
|
134
|
+
for (const name of ["PATH", "TMPDIR"]) {
|
|
135
|
+
if (!(name in env))
|
|
136
|
+
unset.push("-u", name);
|
|
137
|
+
}
|
|
138
|
+
const assignments = [];
|
|
139
|
+
for (const [name, value] of Object.entries(env)) {
|
|
140
|
+
if (!VARIABLE_NAME.test(name)) {
|
|
141
|
+
throw new HarnessError("invalid_sandbox_options", `${JSON.stringify(name)} is not a variable name`);
|
|
142
|
+
}
|
|
143
|
+
assignments.push(`${name}=${value}`);
|
|
144
|
+
}
|
|
145
|
+
return ["/usr/bin/env", ...unset, "--", ...assignments, ...command];
|
|
146
|
+
}
|
|
147
|
+
/** Runs `command` under `srt` in `cwd`, with `env` as its whole environment. */
|
|
148
|
+
runUnderSrt(command, cwd, env, options) {
|
|
149
|
+
return this.runner.run({
|
|
150
|
+
program: this.state.command.program,
|
|
151
|
+
args: this.srtArguments(this.innerCommand(command, env)),
|
|
152
|
+
cwd,
|
|
153
|
+
env: this.launchEnvironment(),
|
|
154
|
+
missingProgram: "reject",
|
|
155
|
+
graceMs: GRACE_MS,
|
|
156
|
+
}, options);
|
|
157
|
+
}
|
|
158
|
+
async exec(command, options) {
|
|
159
|
+
const prepared = await this.prepare(command, options);
|
|
160
|
+
if (!("cwd" in prepared))
|
|
161
|
+
return prepared;
|
|
162
|
+
const { stdoutBytes: _bytes, ...result } = await this.runUnderSrt(command, prepared.cwd, options.env, options);
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
async shutDown() {
|
|
166
|
+
await this.runner.stopAll();
|
|
167
|
+
await this.state.modules.fs.rm(this.state.folder, { recursive: true, force: true });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** The first line of what `srt` printed, for the message of a failed start. */
|
|
171
|
+
function firstLine(text) {
|
|
172
|
+
return text.trim().split("\n")[0] ?? "no output";
|
|
173
|
+
}
|
|
174
|
+
/** The settings and the real roots for one sandbox, with every path's symlinks resolved. */
|
|
175
|
+
async function planSandbox(modules, policy, options, command, runFolder) {
|
|
176
|
+
const real = (paths) => Promise.all(paths.map((path) => realOrSelf(modules, path)));
|
|
177
|
+
const [readRoots, writeRoots, extra, denyWrite, helpers] = await Promise.all([
|
|
178
|
+
real(policy.readRoots),
|
|
179
|
+
real(policy.writeRoots),
|
|
180
|
+
real(options.extraReadRoots ?? []),
|
|
181
|
+
real(options.denyWrite ?? []),
|
|
182
|
+
real(command.readRoots),
|
|
183
|
+
]);
|
|
184
|
+
const input = {
|
|
185
|
+
policy: { ...policy, readRoots, writeRoots },
|
|
186
|
+
systemReadRoots: await existing(modules, await real(SRT_SYSTEM_READ_ROOTS)),
|
|
187
|
+
// Only the run folder: the settings file beside it holds a proxy address that a command must not read.
|
|
188
|
+
helperReadRoots: [runFolder, ...helpers, ...extra],
|
|
189
|
+
denyWrite,
|
|
190
|
+
...(options.parentProxy === undefined ? {} : { parentProxy: options.parentProxy }),
|
|
191
|
+
};
|
|
192
|
+
return { settings: srtSettings(input), roots: { read: readRoots, write: writeRoots, denyWrite } };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Builds the `srt` backend. `provision()` checks the platform, the programs `srt` needs and `srt` itself, by running a
|
|
196
|
+
* command that does nothing, so a host that can't confine a process throws `SandboxUnavailableError` and runs nothing.
|
|
197
|
+
* The policy's roots, `extraReadRoots` and `denyWrite` must be absolute folders other than `/`. Each command runs under
|
|
198
|
+
* its own `srt`, so a command sees the proxy variables `srt` adds to its environment, besides those it was given.
|
|
199
|
+
*/
|
|
200
|
+
export function srtSandbox(options = {}) {
|
|
201
|
+
return {
|
|
202
|
+
tier: "os",
|
|
203
|
+
stops: ["mistakes", "exfiltration"],
|
|
204
|
+
async provision(manifest, policy) {
|
|
205
|
+
const modules = nodeModules("srt");
|
|
206
|
+
const hostPath = absolutePath(modules, process.env.PATH);
|
|
207
|
+
await checkHost(modules, hostPath);
|
|
208
|
+
const root = await workspaceRoot(modules, manifest.root);
|
|
209
|
+
checkPaths(modules, [...policy.readRoots, ...policy.writeRoots], "a sandbox root");
|
|
210
|
+
checkPaths(modules, options.extraReadRoots ?? [], "an extra read root");
|
|
211
|
+
checkPaths(modules, options.denyWrite ?? [], "a denyWrite folder");
|
|
212
|
+
const command = await srtCommand(modules, options.binary);
|
|
213
|
+
const folder = await modules.fs.mkdtemp(modules.path.join(modules.os.tmpdir(), "harness-srt-"));
|
|
214
|
+
try {
|
|
215
|
+
await modules.fs.chmod(folder, 0o700);
|
|
216
|
+
const runFolder = modules.path.join(folder, "run");
|
|
217
|
+
await modules.fs.mkdir(runFolder, { mode: 0o700 });
|
|
218
|
+
const plan = await planSandbox(modules, policy, options, command, runFolder);
|
|
219
|
+
const settingsFile = modules.path.join(folder, "settings.json");
|
|
220
|
+
await modules.fs.writeFile(settingsFile, JSON.stringify(plan.settings), { mode: 0o600 });
|
|
221
|
+
const sandbox = new SrtSandbox({
|
|
222
|
+
modules,
|
|
223
|
+
command,
|
|
224
|
+
root,
|
|
225
|
+
files: new HostFiles(modules, root, plan.roots, isProtectedPath),
|
|
226
|
+
folder,
|
|
227
|
+
runFolder,
|
|
228
|
+
settingsFile,
|
|
229
|
+
hostPath,
|
|
230
|
+
});
|
|
231
|
+
await probe(modules, sandbox, root);
|
|
232
|
+
const encoder = new TextEncoder();
|
|
233
|
+
for (const [path, data] of Object.entries(manifest.files ?? {})) {
|
|
234
|
+
await sandbox.writeFile(path, typeof data === "string" ? encoder.encode(data) : data);
|
|
235
|
+
}
|
|
236
|
+
return sandbox;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
await modules.fs.rm(folder, { recursive: true, force: true });
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/** Starts `srt` once with a command that does nothing, and throws `SandboxUnavailableError` when it can't. */
|
|
246
|
+
async function probe(modules, sandbox, root) {
|
|
247
|
+
const runner = new ProcessRunner(modules);
|
|
248
|
+
const result = await runner
|
|
249
|
+
.run({
|
|
250
|
+
program: sandbox.program,
|
|
251
|
+
args: sandbox.srtArguments(["/usr/bin/true"]),
|
|
252
|
+
cwd: root,
|
|
253
|
+
env: sandbox.launchEnvironment(),
|
|
254
|
+
missingProgram: "reject",
|
|
255
|
+
graceMs: GRACE_MS,
|
|
256
|
+
}, { env: {}, signal: new AbortController().signal, timeoutMs: PROBE_TIMEOUT_MS })
|
|
257
|
+
.catch((error) => {
|
|
258
|
+
throw new SandboxUnavailableError("srt", "it could not be started", { cause: error });
|
|
259
|
+
});
|
|
260
|
+
if (result.exitCode !== 0) {
|
|
261
|
+
throw new SandboxUnavailableError("srt", `it did not start a command: ${firstLine(result.stderr)}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sandbox/srt/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,eAAe,EACf,UAAU,EACV,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAoB,WAAW,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE7E,OAAO,EAAyB,WAAW,EAAE,MAAM,eAAe,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAkB5C,yHAAyH;AACzH,MAAM,CAAC,MAAM,qBAAqB,GAAsB;IACtD,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,MAAM;CACP,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAsB;IACtD,WAAW;IACX,kCAAkC;IAClC,mCAAmC;IACnC,wBAAwB;IACxB,yBAAyB;IACzB,qBAAqB;IACrB,qBAAqB;IACrB,yBAAyB;IACzB,oBAAoB;IACpB,mBAAmB;IACnB,WAAW;IACX,uBAAuB;IACvB,iBAAiB;IACjB,YAAY;IACZ,aAAa;IACb,YAAY;IACZ,mBAAmB;IACnB,UAAU;IACV,aAAa;IACb,iBA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CAAC,CAAC;gBAC9D,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,8GAA8G;AAC9G,KAAK,UAAU,KAAK,CAAC,OAAoB,EAAE,OAAmB,EAAE,IAAY;IAC1E,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,MAAM,MAAM;SACxB,GAAG,CACF;QACE,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,eAAe,CAAC,CAAC;QAC7C,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,OAAO,CAAC,iBAAiB,EAAE;QAChC,cAAc,EAAE,QAAQ;QACxB,OAAO,EAAE,QAAQ;KAClB,EACD,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAC/E;SACA,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACxB,MAAM,IAAI,uBAAuB,CAAC,KAAK,EAAE,yBAAyB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;IACL,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,uBAAuB,CAAC,KAAK,EAAE,+BAA+B,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACtG,CAAC;AACH,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/sandbox/srt`: the OS-tier backend. It runs each command under Anthropic's `srt` sandbox\n * runtime, which uses bubblewrap on Linux and starts a proxy that allows only the policy's hosts. It claims to stop\n * `mistakes` and `exfiltration`, never a `hostile_process`: the kernel is shared with the host, and `srt` is a\n * pre-1.0 beta (as of November 2026). Only Linux is supported, because it is the only platform this backend is tested\n * on. A backend that can't start throws `SandboxUnavailableError` and runs nothing. It is Node-only.\n *\n * The file calls run in the host, not under `srt`: two `srt` processes in one workspace can disturb each other, because\n * each makes and removes empty files there. A path outside the roots is refused by its real path, so a symlink that\n * leads out is refused too, and the opened file is checked again through `/proc`, so a path swapped for a link in\n * between is caught. A hostile process could still win that race, which is why no `hostile_process` stop is claimed.\n */\nimport { HarnessError } from \"../../errors.js\";\nimport { BackendSandbox } from \"../base.js\";\nimport { SandboxUnavailableError } from \"../errors.js\";\nimport {\n absolutePath,\n checkPaths,\n existing,\n findOnPath,\n HostFiles,\n isProtectedPath,\n realOrSelf,\n workspaceRoot,\n} from \"../host-files.js\";\nimport { type NodeModules, nodeModules, ProcessRunner } from \"../process.js\";\nimport type { ExecOptions, ExecResult, Sandbox, SandboxClient, SandboxPolicy, WorkspaceManifest } from \"../types.js\";\nimport { type SrtSettingsInput, srtSettings } from \"./settings.js\";\n\nexport type { SrtPathEntry, SrtSettings, SrtSettingsInput } from \"./settings.js\";\nexport { srtSettings } from \"./settings.js\";\n\n/** The options of `srtSandbox()`. */\nexport interface SrtSandboxOptions {\n /**\n * The `srt` executable. Without it the backend runs the `srt` that the installed `@anthropic-ai/sandbox-runtime`\n * package ships, with this process's Node. A binary from elsewhere must have its own install folder in\n * `extraReadRoots`, because `srt` reads its helper program from there inside the sandbox.\n */\n readonly binary?: string;\n /** Folders to read besides the policy's roots and the system's, such as the folder a toolchain is installed in. */\n readonly extraReadRoots?: readonly string[];\n /** Folders that stay read-only even inside a write root, such as the session's own log folder. */\n readonly denyWrite?: readonly string[];\n /** An upstream HTTP proxy that the allowed traffic goes through, for a host that sits behind one. */\n readonly parentProxy?: { readonly http?: string; readonly https?: string };\n}\n\n/** The system folders a program needs to start. Each one that exists is readable, and nothing else outside the roots. */\nexport const SRT_SYSTEM_READ_ROOTS: readonly string[] = [\n \"/usr\",\n \"/bin\",\n \"/sbin\",\n \"/lib\",\n \"/lib32\",\n \"/lib64\",\n \"/libx32\",\n \"/etc\",\n];\n\n/**\n * The variables `srt` 0.0.83 adds to a command's environment, which are its proxy settings and the few that go with\n * them. A command sees these besides the variables it was given, so a test that compares environments lists them.\n */\nexport const SRT_ADDED_ENVIRONMENT: readonly string[] = [\n \"ALL_PROXY\",\n \"CLAUDE_CODE_HOST_HTTP_PROXY_PORT\",\n \"CLAUDE_CODE_HOST_SOCKS_PROXY_PORT\",\n \"CLOUDSDK_PROXY_ADDRESS\",\n \"CLOUDSDK_PROXY_PASSWORD\",\n \"CLOUDSDK_PROXY_PORT\",\n \"CLOUDSDK_PROXY_TYPE\",\n \"CLOUDSDK_PROXY_USERNAME\",\n \"DOCKER_HTTPS_PROXY\",\n \"DOCKER_HTTP_PROXY\",\n \"FTP_PROXY\",\n \"GIT_CONFIG_PARAMETERS\",\n \"GIT_SSH_COMMAND\",\n \"GRPC_PROXY\",\n \"HTTPS_PROXY\",\n \"HTTP_PROXY\",\n \"JAVA_TOOL_OPTIONS\",\n \"NO_PROXY\",\n \"RSYNC_PROXY\",\n \"SANDBOX_RUNTIME\",\n \"all_proxy\",\n \"ftp_proxy\",\n \"grpc_proxy\",\n \"http_proxy\",\n \"https_proxy\",\n \"no_proxy\",\n];\n\n/** The programs `srt` runs on Linux, which it finds on the `PATH`. */\nconst REQUIRED_PROGRAMS = [\"bwrap\", \"socat\"] as const;\nconst PROBE_TIMEOUT_MS = 20_000;\n// How long `srt` has to clean up after a `SIGTERM` before the command's whole group is killed.\nconst GRACE_MS = 2000;\n\n/** The program and leading arguments that start `srt`. */\ninterface SrtCommand {\n readonly program: string;\n readonly args: readonly string[];\n /** The folders `srt` reads inside the sandbox, as absolute paths. */\n readonly readRoots: readonly string[];\n}\n\n/** How to start `srt`, or a `SandboxUnavailableError` when there is nothing to start. */\nasync function srtCommand(modules: NodeModules, binary: string | undefined): Promise<SrtCommand> {\n if (binary !== undefined) {\n // Resolved once against this process's folder, because it is started from the workspace.\n const program = modules.path.resolve(binary);\n try {\n await modules.fs.access(program, modules.fs.constants.X_OK);\n } catch (error) {\n throw new SandboxUnavailableError(\"srt\", `${binary} is not an executable file`, { cause: error });\n }\n return { program, args: [], readRoots: [] };\n }\n let cli: string;\n try {\n const url = import.meta.resolve(\"@anthropic-ai/sandbox-runtime/dist/cli.js\");\n cli = await modules.fs.realpath(modules.url.fileURLToPath(url));\n } catch (error) {\n throw new SandboxUnavailableError(\"srt\", \"the @anthropic-ai/sandbox-runtime package is not installed\", {\n cause: error,\n });\n }\n // `srt` runs its seccomp helper from the package's own folder, inside the sandbox.\n return { program: process.execPath, args: [cli], readRoots: [modules.path.resolve(cli, \"..\", \"..\", \"vendor\")] };\n}\n\n/** A `SandboxUnavailableError` unless this platform and host can run `srt`, looking for its programs on `hostPath`. */\nasync function checkHost(modules: NodeModules, hostPath: string): Promise<void> {\n if (process.platform !== \"linux\") {\n throw new SandboxUnavailableError(\n \"srt\",\n `only Linux is supported, because it is the only platform this backend is tested on, and this is ${process.platform}`,\n );\n }\n for (const program of REQUIRED_PROGRAMS) {\n if ((await findOnPath(modules, hostPath, program)) === undefined) {\n throw new SandboxUnavailableError(\"srt\", `${program} is not on the PATH, and srt needs it on Linux`);\n }\n }\n}\n\n// A variable name that `env` can set, which is every name a process can be given.\nconst VARIABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** Everything a provisioned sandbox holds. */\ninterface SrtSandboxState {\n readonly modules: NodeModules;\n readonly command: SrtCommand;\n readonly root: string;\n readonly files: HostFiles;\n /** A private folder that holds the settings file and the run folder, and is removed on dispose. */\n readonly folder: string;\n /** The folder `srt` makes its proxy sockets in, and the only part of `folder` a command may read. */\n readonly runFolder: string;\n readonly settingsFile: string;\n /** The `PATH` that `srt` itself runs with, which finds `bwrap` and `socat`. */\n readonly hostPath: string;\n}\n\nclass SrtSandbox extends BackendSandbox {\n private readonly runner: ProcessRunner;\n private readonly state: SrtSandboxState;\n\n constructor(state: SrtSandboxState) {\n super(state);\n this.state = state;\n this.runner = new ProcessRunner(state.modules);\n }\n\n /** The program that starts `srt`. */\n get program(): string {\n return this.state.command.program;\n }\n\n /** The arguments that start `srt` with this sandbox's settings, then run `inner`. */\n srtArguments(inner: readonly string[]): string[] {\n return [...this.state.command.args, \"--settings\", this.state.settingsFile, \"--\", ...inner];\n }\n\n /** The environment `srt` itself runs with: where to find its programs, and where to make its sockets. Nothing else. */\n launchEnvironment(): Record<string, string> {\n return { PATH: this.state.hostPath, TMPDIR: this.state.runFolder };\n }\n\n /**\n * The command that runs inside `srt`. `env` sets the command's whole environment from `srt`'s own, so a variable that\n * makes a program load code, such as `NODE_OPTIONS`, never reaches `srt` or the programs it starts outside the\n * sandbox. The `--` ends `env`'s options, so a first word that starts with `-` is a program name.\n */\n private innerCommand(command: readonly string[], env: Readonly<Record<string, string>>): string[] {\n const unset: string[] = [];\n for (const name of [\"PATH\", \"TMPDIR\"]) {\n if (!(name in env)) unset.push(\"-u\", name);\n }\n const assignments: string[] = [];\n for (const [name, value] of Object.entries(env)) {\n if (!VARIABLE_NAME.test(name)) {\n throw new HarnessError(\"invalid_sandbox_options\", `${JSON.stringify(name)} is not a variable name`);\n }\n assignments.push(`${name}=${value}`);\n }\n return [\"/usr/bin/env\", ...unset, \"--\", ...assignments, ...command];\n }\n\n /** Runs `command` under `srt` in `cwd`, with `env` as its whole environment. */\n private runUnderSrt(\n command: readonly string[],\n cwd: string,\n env: Readonly<Record<string, string>>,\n options: ExecOptions,\n ) {\n return this.runner.run(\n {\n program: this.state.command.program,\n args: this.srtArguments(this.innerCommand(command, env)),\n cwd,\n env: this.launchEnvironment(),\n missingProgram: \"reject\",\n graceMs: GRACE_MS,\n },\n options,\n );\n }\n\n async exec(command: readonly string[], options: ExecOptions): Promise<ExecResult> {\n const prepared = await this.prepare(command, options);\n if (!(\"cwd\" in prepared)) return prepared;\n const { stdoutBytes: _bytes, ...result } = await this.runUnderSrt(command, prepared.cwd, options.env, options);\n return result;\n }\n\n protected async shutDown(): Promise<void> {\n await this.runner.stopAll();\n await this.state.modules.fs.rm(this.state.folder, { recursive: true, force: true });\n }\n}\n\n/** The first line of what `srt` printed, for the message of a failed start. */\nfunction firstLine(text: string): string {\n return text.trim().split(\"\\n\")[0] ?? \"no output\";\n}\n\n/** The settings and the real roots for one sandbox, with every path's symlinks resolved. */\nasync function planSandbox(\n modules: NodeModules,\n policy: SandboxPolicy,\n options: SrtSandboxOptions,\n command: SrtCommand,\n runFolder: string,\n) {\n const real = (paths: readonly string[]) => Promise.all(paths.map((path) => realOrSelf(modules, path)));\n const [readRoots, writeRoots, extra, denyWrite, helpers] = await Promise.all([\n real(policy.readRoots),\n real(policy.writeRoots),\n real(options.extraReadRoots ?? []),\n real(options.denyWrite ?? []),\n real(command.readRoots),\n ]);\n const input: SrtSettingsInput = {\n policy: { ...policy, readRoots, writeRoots },\n systemReadRoots: await existing(modules, await real(SRT_SYSTEM_READ_ROOTS)),\n // Only the run folder: the settings file beside it holds a proxy address that a command must not read.\n helperReadRoots: [runFolder, ...helpers, ...extra],\n denyWrite,\n ...(options.parentProxy === undefined ? {} : { parentProxy: options.parentProxy }),\n };\n return { settings: srtSettings(input), roots: { read: readRoots, write: writeRoots, denyWrite } };\n}\n\n/**\n * Builds the `srt` backend. `provision()` checks the platform, the programs `srt` needs and `srt` itself, by running a\n * command that does nothing, so a host that can't confine a process throws `SandboxUnavailableError` and runs nothing.\n * The policy's roots, `extraReadRoots` and `denyWrite` must be absolute folders other than `/`. Each command runs under\n * its own `srt`, so a command sees the proxy variables `srt` adds to its environment, besides those it was given.\n */\nexport function srtSandbox(options: SrtSandboxOptions = {}): SandboxClient {\n return {\n tier: \"os\",\n stops: [\"mistakes\", \"exfiltration\"],\n async provision(manifest: WorkspaceManifest, policy: SandboxPolicy): Promise<Sandbox> {\n const modules = nodeModules(\"srt\");\n const hostPath = absolutePath(modules, process.env.PATH);\n await checkHost(modules, hostPath);\n const root = await workspaceRoot(modules, manifest.root);\n checkPaths(modules, [...policy.readRoots, ...policy.writeRoots], \"a sandbox root\");\n checkPaths(modules, options.extraReadRoots ?? [], \"an extra read root\");\n checkPaths(modules, options.denyWrite ?? [], \"a denyWrite folder\");\n const command = await srtCommand(modules, options.binary);\n const folder = await modules.fs.mkdtemp(modules.path.join(modules.os.tmpdir(), \"harness-srt-\"));\n try {\n await modules.fs.chmod(folder, 0o700);\n const runFolder = modules.path.join(folder, \"run\");\n await modules.fs.mkdir(runFolder, { mode: 0o700 });\n const plan = await planSandbox(modules, policy, options, command, runFolder);\n const settingsFile = modules.path.join(folder, \"settings.json\");\n await modules.fs.writeFile(settingsFile, JSON.stringify(plan.settings), { mode: 0o600 });\n const sandbox = new SrtSandbox({\n modules,\n command,\n root,\n files: new HostFiles(modules, root, plan.roots, isProtectedPath),\n folder,\n runFolder,\n settingsFile,\n hostPath,\n });\n await probe(modules, sandbox, root);\n const encoder = new TextEncoder();\n for (const [path, data] of Object.entries(manifest.files ?? {})) {\n await sandbox.writeFile(path, typeof data === \"string\" ? encoder.encode(data) : data);\n }\n return sandbox;\n } catch (error) {\n await modules.fs.rm(folder, { recursive: true, force: true });\n throw error;\n }\n },\n };\n}\n\n/** Starts `srt` once with a command that does nothing, and throws `SandboxUnavailableError` when it can't. */\nasync function probe(modules: NodeModules, sandbox: SrtSandbox, root: string): Promise<void> {\n const runner = new ProcessRunner(modules);\n const result = await runner\n .run(\n {\n program: sandbox.program,\n args: sandbox.srtArguments([\"/usr/bin/true\"]),\n cwd: root,\n env: sandbox.launchEnvironment(),\n missingProgram: \"reject\",\n graceMs: GRACE_MS,\n },\n { env: {}, signal: new AbortController().signal, timeoutMs: PROBE_TIMEOUT_MS },\n )\n .catch((error: unknown) => {\n throw new SandboxUnavailableError(\"srt\", \"it could not be started\", { cause: error });\n });\n if (result.exitCode !== 0) {\n throw new SandboxUnavailableError(\"srt\", `it did not start a command: ${firstLine(result.stderr)}`);\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `srt` settings file for a sandbox policy. It is a pure function of the policy, so a test can read the file a
|
|
3
|
+
* backend would write without starting `srt`. `srt` is a pre-1.0 beta whose settings format may change (as of
|
|
4
|
+
* November 2026), so this is the one place that knows the format.
|
|
5
|
+
*/
|
|
6
|
+
import type { SandboxPolicy } from "../types.js";
|
|
7
|
+
/** A path that `srt` must read as written. Without `literal`, `srt` reads a spelling such as `*.ts` as a pattern. */
|
|
8
|
+
export interface SrtPathEntry {
|
|
9
|
+
readonly path: string;
|
|
10
|
+
readonly literal: true;
|
|
11
|
+
}
|
|
12
|
+
/** The settings `srt` reads from its `--settings` file. */
|
|
13
|
+
export interface SrtSettings {
|
|
14
|
+
readonly network: {
|
|
15
|
+
readonly allowedDomains: readonly string[];
|
|
16
|
+
readonly deniedDomains: readonly string[];
|
|
17
|
+
readonly parentProxy?: {
|
|
18
|
+
readonly http?: string;
|
|
19
|
+
readonly https?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
readonly filesystem: {
|
|
23
|
+
readonly denyRead: readonly SrtPathEntry[];
|
|
24
|
+
readonly allowRead: readonly SrtPathEntry[];
|
|
25
|
+
readonly allowWrite: readonly SrtPathEntry[];
|
|
26
|
+
readonly denyWrite: readonly SrtPathEntry[];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** What the settings are built from, beyond the policy. Every path is absolute with its symlinks resolved. */
|
|
30
|
+
export interface SrtSettingsInput {
|
|
31
|
+
readonly policy: SandboxPolicy;
|
|
32
|
+
/** The system folders every program needs to start, which the policy does not list. */
|
|
33
|
+
readonly systemReadRoots: readonly string[];
|
|
34
|
+
/** The folders `srt` itself needs to read, such as its own helper and its private socket folder. */
|
|
35
|
+
readonly helperReadRoots: readonly string[];
|
|
36
|
+
/** Folders to keep read-only inside a write root, such as the session's own log folder. */
|
|
37
|
+
readonly denyWrite: readonly string[];
|
|
38
|
+
readonly parentProxy?: {
|
|
39
|
+
readonly http?: string;
|
|
40
|
+
readonly https?: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Denies every read and then allows the policy's read and write roots, the system folders and the helper folders back.
|
|
45
|
+
* Writes are allowed only under the write roots, and `denyWrite` takes precedence over them. The network allows only the
|
|
46
|
+
* policy's hosts. Each path is `literal`, so a folder named `*` is never read as a pattern.
|
|
47
|
+
*/
|
|
48
|
+
export declare function srtSettings(input: SrtSettingsInput): SrtSettings;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const literal = (path) => ({ path, literal: true });
|
|
2
|
+
/** Removes repeats, keeping the first of each. */
|
|
3
|
+
const unique = (paths) => [...new Set(paths)];
|
|
4
|
+
/**
|
|
5
|
+
* Denies every read and then allows the policy's read and write roots, the system folders and the helper folders back.
|
|
6
|
+
* Writes are allowed only under the write roots, and `denyWrite` takes precedence over them. The network allows only the
|
|
7
|
+
* policy's hosts. Each path is `literal`, so a folder named `*` is never read as a pattern.
|
|
8
|
+
*/
|
|
9
|
+
export function srtSettings(input) {
|
|
10
|
+
const { policy } = input;
|
|
11
|
+
const readable = unique([
|
|
12
|
+
...policy.readRoots,
|
|
13
|
+
...policy.writeRoots,
|
|
14
|
+
...input.systemReadRoots,
|
|
15
|
+
...input.helperReadRoots,
|
|
16
|
+
]);
|
|
17
|
+
return {
|
|
18
|
+
network: {
|
|
19
|
+
allowedDomains: [...policy.network.allow],
|
|
20
|
+
deniedDomains: [...policy.network.deny],
|
|
21
|
+
...(input.parentProxy === undefined ? {} : { parentProxy: input.parentProxy }),
|
|
22
|
+
},
|
|
23
|
+
filesystem: {
|
|
24
|
+
denyRead: [literal("/")],
|
|
25
|
+
allowRead: readable.map(literal),
|
|
26
|
+
allowWrite: unique(policy.writeRoots).map(literal),
|
|
27
|
+
denyWrite: unique(input.denyWrite).map(literal),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../src/sandbox/srt/settings.ts"],"names":[],"mappings":"AAwCA,MAAM,OAAO,GAAG,CAAC,IAAY,EAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1E,kDAAkD;AAClD,MAAM,MAAM,GAAG,CAAC,KAAwB,EAAY,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAE3E;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAuB;IACjD,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACzB,MAAM,QAAQ,GAAG,MAAM,CAAC;QACtB,GAAG,MAAM,CAAC,SAAS;QACnB,GAAG,MAAM,CAAC,UAAU;QACpB,GAAG,KAAK,CAAC,eAAe;QACxB,GAAG,KAAK,CAAC,eAAe;KACzB,CAAC,CAAC;IACH,OAAO;QACL,OAAO,EAAE;YACP,cAAc,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YACzC,aAAa,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;YACvC,GAAG,CAAC,KAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;SAC/E;QACD,UAAU,EAAE;YACV,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxB,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;YAChC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;YAClD,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;SAChD;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The `srt` settings file for a sandbox policy. It is a pure function of the policy, so a test can read the file a\n * backend would write without starting `srt`. `srt` is a pre-1.0 beta whose settings format may change (as of\n * November 2026), so this is the one place that knows the format.\n */\nimport type { SandboxPolicy } from \"../types.js\";\n\n/** A path that `srt` must read as written. Without `literal`, `srt` reads a spelling such as `*.ts` as a pattern. */\nexport interface SrtPathEntry {\n readonly path: string;\n readonly literal: true;\n}\n\n/** The settings `srt` reads from its `--settings` file. */\nexport interface SrtSettings {\n readonly network: {\n readonly allowedDomains: readonly string[];\n readonly deniedDomains: readonly string[];\n readonly parentProxy?: { readonly http?: string; readonly https?: string };\n };\n readonly filesystem: {\n readonly denyRead: readonly SrtPathEntry[];\n readonly allowRead: readonly SrtPathEntry[];\n readonly allowWrite: readonly SrtPathEntry[];\n readonly denyWrite: readonly SrtPathEntry[];\n };\n}\n\n/** What the settings are built from, beyond the policy. Every path is absolute with its symlinks resolved. */\nexport interface SrtSettingsInput {\n readonly policy: SandboxPolicy;\n /** The system folders every program needs to start, which the policy does not list. */\n readonly systemReadRoots: readonly string[];\n /** The folders `srt` itself needs to read, such as its own helper and its private socket folder. */\n readonly helperReadRoots: readonly string[];\n /** Folders to keep read-only inside a write root, such as the session's own log folder. */\n readonly denyWrite: readonly string[];\n readonly parentProxy?: { readonly http?: string; readonly https?: string };\n}\n\nconst literal = (path: string): SrtPathEntry => ({ path, literal: true });\n\n/** Removes repeats, keeping the first of each. */\nconst unique = (paths: readonly string[]): string[] => [...new Set(paths)];\n\n/**\n * Denies every read and then allows the policy's read and write roots, the system folders and the helper folders back.\n * Writes are allowed only under the write roots, and `denyWrite` takes precedence over them. The network allows only the\n * policy's hosts. Each path is `literal`, so a folder named `*` is never read as a pattern.\n */\nexport function srtSettings(input: SrtSettingsInput): SrtSettings {\n const { policy } = input;\n const readable = unique([\n ...policy.readRoots,\n ...policy.writeRoots,\n ...input.systemReadRoots,\n ...input.helperReadRoots,\n ]);\n return {\n network: {\n allowedDomains: [...policy.network.allow],\n deniedDomains: [...policy.network.deny],\n ...(input.parentProxy === undefined ? {} : { parentProxy: input.parentProxy }),\n },\n filesystem: {\n denyRead: [literal(\"/\")],\n allowRead: readable.map(literal),\n allowWrite: unique(policy.writeRoots).map(literal),\n denyWrite: unique(input.denyWrite).map(literal),\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sandbox interface: a pluggable client with honest tiers. The host owns the policy and the approval, never the
|
|
3
|
+
* model, and a backend that can't start throws instead of running unconfined (harness guide section 6, ADR 0020).
|
|
4
|
+
*/
|
|
5
|
+
/** What a sandbox may touch. Roots are absolute directories; a backend that enforces them denies the rest. */
|
|
6
|
+
export interface SandboxPolicy {
|
|
7
|
+
/** Directories the sandbox may read. The write roots are readable too. */
|
|
8
|
+
readonly readRoots: readonly string[];
|
|
9
|
+
/** Directories the sandbox may write. */
|
|
10
|
+
readonly writeRoots: readonly string[];
|
|
11
|
+
/** The hosts the sandbox may reach: `allow` names them, and `deny` names the ones that stay closed inside `allow`. */
|
|
12
|
+
readonly network: {
|
|
13
|
+
readonly allow: readonly string[];
|
|
14
|
+
readonly deny: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** When a denied action may be asked for again, which is the host's decision and never the sandbox's. */
|
|
18
|
+
export type ApprovalPolicy = "on-request" | "granular" | "never";
|
|
19
|
+
/**
|
|
20
|
+
* How strongly a backend confines a process. `none`: not at all. `os`: an operating-system sandbox that shares the
|
|
21
|
+
* host's kernel. `container`: a container. `gvisor`: a user-space kernel. `microvm`: a virtual machine.
|
|
22
|
+
*/
|
|
23
|
+
export type SandboxTier = "none" | "os" | "container" | "gvisor" | "microvm";
|
|
24
|
+
/**
|
|
25
|
+
* What a backend claims to stop. `mistakes`: the agent's own errors, such as a write outside the workspace.
|
|
26
|
+
* `exfiltration`: sending data to a host that is not allowed. `hostile_process`: a process that is trying to escape.
|
|
27
|
+
* A backend lists a stop only when its tier and its setup deliver it, and no tier here claims `hostile_process` yet.
|
|
28
|
+
*/
|
|
29
|
+
export type SandboxStop = "mistakes" | "exfiltration" | "hostile_process";
|
|
30
|
+
/** The workspace a sandbox is provisioned for: its root directory and the files to put there first. */
|
|
31
|
+
export interface WorkspaceManifest {
|
|
32
|
+
/** The workspace's absolute root. Relative paths and working directories resolve against it. */
|
|
33
|
+
readonly root: string;
|
|
34
|
+
/** Files to write under the root before the first command, by path relative to it. */
|
|
35
|
+
readonly files?: Readonly<Record<string, string | Uint8Array>>;
|
|
36
|
+
}
|
|
37
|
+
/** What the policy refused. `target` names the path or host, and `reason` says which rule. */
|
|
38
|
+
export interface SandboxDenial {
|
|
39
|
+
readonly kind: "filesystem_read" | "filesystem_write" | "network";
|
|
40
|
+
readonly target: string;
|
|
41
|
+
readonly reason: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* What a command did: its exit status and output, or the denial that stopped it. A failing command is a result.
|
|
45
|
+
* `exitCode` is 124 for a timeout, 127 for a program that can't be found, and 128 plus the signal's number for a
|
|
46
|
+
* command that a signal killed, with `signal` naming it. `truncated` is `true` when the output passed the cap and the
|
|
47
|
+
* rest was dropped.
|
|
48
|
+
*/
|
|
49
|
+
export type ExecResult = {
|
|
50
|
+
exitCode: number;
|
|
51
|
+
stdout: string;
|
|
52
|
+
stderr: string;
|
|
53
|
+
signal?: string;
|
|
54
|
+
truncated?: boolean;
|
|
55
|
+
} | {
|
|
56
|
+
denied: SandboxDenial;
|
|
57
|
+
};
|
|
58
|
+
/** The options of `Sandbox.exec()`. */
|
|
59
|
+
export interface ExecOptions {
|
|
60
|
+
/** The working directory, relative to the workspace root. Defaults to the root. */
|
|
61
|
+
readonly cwd?: string;
|
|
62
|
+
/** The command's whole environment. Build it with `spawnEnv()`: nothing else is added. */
|
|
63
|
+
readonly env: Readonly<Record<string, string>>;
|
|
64
|
+
/** Aborts the command and every process it started. An already aborted signal rejects before the command runs. */
|
|
65
|
+
readonly signal: AbortSignal;
|
|
66
|
+
/** Stops a command, and every process it started, that runs longer than this, with exit code 124. */
|
|
67
|
+
readonly timeoutMs?: number;
|
|
68
|
+
/** The most bytes of each of standard output and standard error to keep. Defaults to 8 MiB; the rest is dropped. */
|
|
69
|
+
readonly maxOutputBytes?: number;
|
|
70
|
+
}
|
|
71
|
+
/** A provisioned sandbox. */
|
|
72
|
+
export interface Sandbox {
|
|
73
|
+
/** Runs `command`, an executable and its arguments with no shell, and resolves with what it did. */
|
|
74
|
+
exec(command: readonly string[], options: ExecOptions): Promise<ExecResult>;
|
|
75
|
+
/** Reads a file by path relative to the workspace root, or absolute. A missing file rejects with `sandbox_not_found`. */
|
|
76
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
77
|
+
/** Writes a file by path relative to the workspace root, or absolute, making its folders. */
|
|
78
|
+
writeFile(path: string, data: Uint8Array): Promise<void>;
|
|
79
|
+
/** Stops what is still running, and releases the sandbox. Calling it again does nothing, and any other call afterwards rejects. */
|
|
80
|
+
dispose(): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
/** A sandbox backend. */
|
|
83
|
+
export interface SandboxClient {
|
|
84
|
+
readonly tier: SandboxTier;
|
|
85
|
+
readonly stops: readonly SandboxStop[];
|
|
86
|
+
/** Provisions a sandbox, or throws `SandboxUnavailableError` when the backend can't start. It never falls back. */
|
|
87
|
+
provision(manifest: WorkspaceManifest, policy: SandboxPolicy): Promise<Sandbox>;
|
|
88
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sandbox interface: a pluggable client with honest tiers. The host owns the policy and the approval, never the
|
|
3
|
+
* model, and a backend that can't start throws instead of running unconfined (harness guide section 6, ADR 0020).
|
|
4
|
+
*/
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sandbox/types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * The sandbox interface: a pluggable client with honest tiers. The host owns the policy and the approval, never the\n * model, and a backend that can't start throws instead of running unconfined (harness guide section 6, ADR 0020).\n */\n\n/** What a sandbox may touch. Roots are absolute directories; a backend that enforces them denies the rest. */\nexport interface SandboxPolicy {\n /** Directories the sandbox may read. The write roots are readable too. */\n readonly readRoots: readonly string[];\n /** Directories the sandbox may write. */\n readonly writeRoots: readonly string[];\n /** The hosts the sandbox may reach: `allow` names them, and `deny` names the ones that stay closed inside `allow`. */\n readonly network: { readonly allow: readonly string[]; readonly deny: readonly string[] };\n}\n\n/** When a denied action may be asked for again, which is the host's decision and never the sandbox's. */\nexport type ApprovalPolicy = \"on-request\" | \"granular\" | \"never\";\n\n/**\n * How strongly a backend confines a process. `none`: not at all. `os`: an operating-system sandbox that shares the\n * host's kernel. `container`: a container. `gvisor`: a user-space kernel. `microvm`: a virtual machine.\n */\nexport type SandboxTier = \"none\" | \"os\" | \"container\" | \"gvisor\" | \"microvm\";\n\n/**\n * What a backend claims to stop. `mistakes`: the agent's own errors, such as a write outside the workspace.\n * `exfiltration`: sending data to a host that is not allowed. `hostile_process`: a process that is trying to escape.\n * A backend lists a stop only when its tier and its setup deliver it, and no tier here claims `hostile_process` yet.\n */\nexport type SandboxStop = \"mistakes\" | \"exfiltration\" | \"hostile_process\";\n\n/** The workspace a sandbox is provisioned for: its root directory and the files to put there first. */\nexport interface WorkspaceManifest {\n /** The workspace's absolute root. Relative paths and working directories resolve against it. */\n readonly root: string;\n /** Files to write under the root before the first command, by path relative to it. */\n readonly files?: Readonly<Record<string, string | Uint8Array>>;\n}\n\n/** What the policy refused. `target` names the path or host, and `reason` says which rule. */\nexport interface SandboxDenial {\n readonly kind: \"filesystem_read\" | \"filesystem_write\" | \"network\";\n readonly target: string;\n readonly reason: string;\n}\n\n/**\n * What a command did: its exit status and output, or the denial that stopped it. A failing command is a result.\n * `exitCode` is 124 for a timeout, 127 for a program that can't be found, and 128 plus the signal's number for a\n * command that a signal killed, with `signal` naming it. `truncated` is `true` when the output passed the cap and the\n * rest was dropped.\n */\nexport type ExecResult =\n | { exitCode: number; stdout: string; stderr: string; signal?: string; truncated?: boolean }\n | { denied: SandboxDenial };\n\n/** The options of `Sandbox.exec()`. */\nexport interface ExecOptions {\n /** The working directory, relative to the workspace root. Defaults to the root. */\n readonly cwd?: string;\n /** The command's whole environment. Build it with `spawnEnv()`: nothing else is added. */\n readonly env: Readonly<Record<string, string>>;\n /** Aborts the command and every process it started. An already aborted signal rejects before the command runs. */\n readonly signal: AbortSignal;\n /** Stops a command, and every process it started, that runs longer than this, with exit code 124. */\n readonly timeoutMs?: number;\n /** The most bytes of each of standard output and standard error to keep. Defaults to 8 MiB; the rest is dropped. */\n readonly maxOutputBytes?: number;\n}\n\n/** A provisioned sandbox. */\nexport interface Sandbox {\n /** Runs `command`, an executable and its arguments with no shell, and resolves with what it did. */\n exec(command: readonly string[], options: ExecOptions): Promise<ExecResult>;\n /** Reads a file by path relative to the workspace root, or absolute. A missing file rejects with `sandbox_not_found`. */\n readFile(path: string): Promise<Uint8Array>;\n /** Writes a file by path relative to the workspace root, or absolute, making its folders. */\n writeFile(path: string, data: Uint8Array): Promise<void>;\n /** Stops what is still running, and releases the sandbox. Calling it again does nothing, and any other call afterwards rejects. */\n dispose(): Promise<void>;\n}\n\n/** A sandbox backend. */\nexport interface SandboxClient {\n readonly tier: SandboxTier;\n readonly stops: readonly SandboxStop[];\n /** Provisions a sandbox, or throws `SandboxUnavailableError` when the backend can't start. It never falls back. */\n provision(manifest: WorkspaceManifest, policy: SandboxPolicy): Promise<Sandbox>;\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a client's answers to the server's requests. An answer is checked before it reaches the approvals or a tool
|
|
3
|
+
* call, because it comes from outside the process: an approval answer must name the request it was asked about and
|
|
4
|
+
* nothing else, and a tool result must have the shape the SDK takes.
|
|
5
|
+
*/
|
|
6
|
+
import type { Resolution, SignedPendingRequest, ToolResult } from "@buildanagent/sdk";
|
|
7
|
+
/**
|
|
8
|
+
* The one resolution an answer to `approval/request` or `clarification/request` gives for `request`, or `undefined` when
|
|
9
|
+
* the answer is malformed, names another request, or gives more than one. An approval takes `allow` or `deny` with an
|
|
10
|
+
* optional `reason`; a clarification takes an `answer`. Either may carry `by`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolutionOf(result: unknown, request: SignedPendingRequest): Resolution | undefined;
|
|
13
|
+
/** An error result the model reads, for a tool call the client could not run. */
|
|
14
|
+
export declare function toolError(text: string): ToolResult;
|
|
15
|
+
/** The tool result a client's answer to `tool/call` gives, or an error result when the answer is not one. */
|
|
16
|
+
export declare function toolResultOf(result: unknown, tool: string): ToolResult;
|