@buildanagent/harness 0.1.0-alpha.28 → 0.1.0-alpha.30
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/README.md +152 -5
- package/dist/context/file-spill.d.ts +11 -1
- package/dist/context/file-spill.js +23 -8
- package/dist/context/file-spill.js.map +1 -1
- package/dist/context/spill.d.ts +5 -1
- package/dist/context/spill.js +6 -2
- package/dist/context/spill.js.map +1 -1
- package/dist/credentials/addresses.d.ts +11 -0
- package/dist/credentials/addresses.js +41 -2
- package/dist/credentials/addresses.js.map +1 -1
- package/dist/credentials/allowlist.d.ts +22 -2
- package/dist/credentials/allowlist.js +74 -17
- package/dist/credentials/allowlist.js.map +1 -1
- package/dist/credentials/egress-policy.d.ts +69 -0
- package/dist/credentials/egress-policy.js +170 -0
- package/dist/credentials/egress-policy.js.map +1 -0
- package/dist/credentials/egress-proxy.d.ts +13 -1
- package/dist/credentials/egress-proxy.js +179 -11
- package/dist/credentials/egress-proxy.js.map +1 -1
- package/dist/credentials/git-route.d.ts +68 -0
- package/dist/credentials/git-route.js +288 -0
- package/dist/credentials/git-route.js.map +1 -0
- package/dist/credentials/index.d.ts +5 -1
- package/dist/credentials/index.js +5 -1
- package/dist/credentials/index.js.map +1 -1
- package/dist/credentials/scrub.d.ts +7 -0
- package/dist/credentials/scrub.js +22 -0
- package/dist/credentials/scrub.js.map +1 -1
- package/dist/errors.d.ts +14 -7
- package/dist/errors.js +13 -6
- package/dist/errors.js.map +1 -1
- package/dist/sandbox/base.d.ts +11 -1
- package/dist/sandbox/base.js +14 -0
- package/dist/sandbox/base.js.map +1 -1
- package/dist/sandbox/docker/index.d.ts +8 -2
- package/dist/sandbox/docker/index.js +63 -14
- package/dist/sandbox/docker/index.js.map +1 -1
- package/dist/sandbox/errors.d.ts +30 -2
- package/dist/sandbox/errors.js +36 -1
- package/dist/sandbox/errors.js.map +1 -1
- package/dist/sandbox/escalation-table.d.ts +38 -0
- package/dist/sandbox/escalation-table.js +95 -0
- package/dist/sandbox/escalation-table.js.map +1 -0
- package/dist/sandbox/escalation.d.ts +191 -0
- package/dist/sandbox/escalation.js +370 -0
- package/dist/sandbox/escalation.js.map +1 -0
- package/dist/sandbox/host-files.d.ts +2 -0
- package/dist/sandbox/host-files.js +10 -0
- package/dist/sandbox/host-files.js.map +1 -1
- package/dist/sandbox/index.d.ts +9 -4
- package/dist/sandbox/index.js +8 -3
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/policy.d.ts +49 -0
- package/dist/sandbox/policy.js +149 -0
- package/dist/sandbox/policy.js.map +1 -0
- package/dist/sandbox/process.js +1 -1
- package/dist/sandbox/process.js.map +1 -1
- package/dist/sandbox/srt/index.d.ts +5 -2
- package/dist/sandbox/srt/index.js +27 -8
- package/dist/sandbox/srt/index.js.map +1 -1
- package/dist/sandbox/srt/settings.d.ts +17 -5
- package/dist/sandbox/srt/settings.js +53 -0
- package/dist/sandbox/srt/settings.js.map +1 -1
- package/dist/sandbox/types.d.ts +41 -4
- package/dist/sandbox/types.js.map +1 -1
- package/dist/sandbox/widen.d.ts +10 -0
- package/dist/sandbox/widen.js +150 -0
- package/dist/sandbox/widen.js.map +1 -0
- package/dist/session/approvals.d.ts +30 -1
- package/dist/session/approvals.js +12 -4
- package/dist/session/approvals.js.map +1 -1
- package/dist/session/code-call.d.ts +15 -1
- package/dist/session/code-call.js +2 -1
- package/dist/session/code-call.js.map +1 -1
- package/dist/session/escalation-log.d.ts +65 -0
- package/dist/session/escalation-log.js +84 -0
- package/dist/session/escalation-log.js.map +1 -0
- package/dist/session/rebuild.js +12 -3
- package/dist/session/rebuild.js.map +1 -1
- package/dist/testing/fake-sandbox.d.ts +21 -3
- package/dist/testing/fake-sandbox.js +157 -8
- package/dist/testing/fake-sandbox.js.map +1 -1
- package/dist/testing/sandbox-conformance.js +108 -1
- package/dist/testing/sandbox-conformance.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +9 -0
- package/dist/tools/builtins/bash.js +75 -0
- package/dist/tools/builtins/bash.js.map +1 -0
- package/dist/tools/builtins/builtins.d.ts +38 -0
- package/dist/tools/builtins/builtins.js +48 -0
- package/dist/tools/builtins/builtins.js.map +1 -0
- package/dist/tools/builtins/descriptions.d.ts +69 -0
- package/dist/tools/builtins/descriptions.js +94 -0
- package/dist/tools/builtins/descriptions.js.map +1 -0
- package/dist/tools/builtins/fetch.d.ts +12 -0
- package/dist/tools/builtins/fetch.js +157 -0
- package/dist/tools/builtins/fetch.js.map +1 -0
- package/dist/tools/builtins/files.d.ts +27 -0
- package/dist/tools/builtins/files.js +274 -0
- package/dist/tools/builtins/files.js.map +1 -0
- package/dist/tools/builtins/paths.d.ts +30 -0
- package/dist/tools/builtins/paths.js +62 -0
- package/dist/tools/builtins/paths.js.map +1 -0
- package/dist/tools/builtins/results.d.ts +15 -0
- package/dist/tools/builtins/results.js +31 -0
- package/dist/tools/builtins/results.js.map +1 -0
- package/dist/tools/builtins/search.d.ts +18 -0
- package/dist/tools/builtins/search.js +217 -0
- package/dist/tools/builtins/search.js.map +1 -0
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +5 -2
- package/dist/tools/index.js.map +1 -1
- package/llms.txt +52 -0
- package/package.json +5 -5
|
@@ -1 +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,CA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E;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"]}
|
|
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,SAAS,EACT,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAoB,WAAW,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE7E,OAAO,EAA8C,qBAAqB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG/G,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAkBnE,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,MA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Y;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 spellings,\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 SrtPolicyNames, type SrtSettingsInput, srtPolicyFromSettings, srtSettings } from \"./settings.js\";\n\nexport type { SrtPathEntry, SrtPolicyNames, SrtSettings, SrtSettingsInput } from \"./settings.js\";\nexport { srtPolicyFromSettings, 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 /** How the settings file's real paths map back to the request's spelling, for the read-back. */\n readonly names: SrtPolicyNames;\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 /** Reads the settings file `srt` is started with, as it is on disk now, and maps it back to a policy. */\n async readBack(): Promise<SandboxPolicy> {\n this.live();\n const text = await this.state.modules.fs.readFile(this.state.settingsFile, \"utf8\");\n return srtPolicyFromSettings(JSON.parse(text) as unknown, this.state.names);\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 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 const helperReadRoots = [runFolder, ...helpers, ...extra];\n const input: SrtSettingsInput = {\n policy: { ...policy, readRoots, writeRoots },\n systemReadRoots,\n helperReadRoots,\n denyWrite,\n ...(options.parentProxy === undefined ? {} : { parentProxy: options.parentProxy }),\n };\n const names: SrtPolicyNames = {\n read: spellings(readRoots, policy.readRoots),\n write: spellings(writeRoots, policy.writeRoots),\n implicitReads: [...systemReadRoots, ...helperReadRoots],\n };\n return { settings: srtSettings(input), roots: { read: readRoots, write: writeRoots, denyWrite }, names };\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 * Before it returns, `provision()` reads the settings file back from disk and throws `SandboxPolicyMismatchError` when\n * the policy it applies differs from the one requested. The backend lists no capability: it can't resume, snapshot or\n * pause.\n */\nexport function srtSandbox(options: SrtSandboxOptions = {}): SandboxClient {\n const client: SandboxClient = {\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 names: plan.names,\n });\n await probe(modules, sandbox, root);\n await sandbox.confirm(client, policy);\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 return client;\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"]}
|
|
@@ -1,8 +1,3 @@
|
|
|
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
1
|
import type { SandboxPolicy } from "../types.js";
|
|
7
2
|
/** A path that `srt` must read as written. Without `literal`, `srt` reads a spelling such as `*.ts` as a pattern. */
|
|
8
3
|
export interface SrtPathEntry {
|
|
@@ -46,3 +41,20 @@ export interface SrtSettingsInput {
|
|
|
46
41
|
* policy's hosts. Each path is `literal`, so a folder named `*` is never read as a pattern.
|
|
47
42
|
*/
|
|
48
43
|
export declare function srtSettings(input: SrtSettingsInput): SrtSettings;
|
|
44
|
+
/** How a settings file's real paths map back to the spelling of the request, for `srtPolicyFromSettings()`. */
|
|
45
|
+
export interface SrtPolicyNames {
|
|
46
|
+
/** For each real read root, the request's spellings that resolved to it. */
|
|
47
|
+
readonly read: ReadonlyMap<string, readonly string[]>;
|
|
48
|
+
/** For each real write root, the request's spellings that resolved to it. */
|
|
49
|
+
readonly write: ReadonlyMap<string, readonly string[]>;
|
|
50
|
+
/** The readable folders the backend adds itself: the system's, `srt`'s own and the caller's extra read roots. */
|
|
51
|
+
readonly implicitReads: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The policy a settings file applies, in the spelling of the request. A write root maps back through `names.write`,
|
|
55
|
+
* and a readable folder through `names.read`. A folder the backend adds itself, and a write root, which is readable
|
|
56
|
+
* anyway, are left out, so any other folder in the file shows up as a read root the request didn't ask for. A file
|
|
57
|
+
* that doesn't deny every read first reads back as the read root `/`. A file that isn't in the shape `srtSettings()`
|
|
58
|
+
* writes throws `SandboxPolicyMismatchError`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function srtPolicyFromSettings(settings: unknown, names: SrtPolicyNames): SandboxPolicy;
|
|
@@ -1,3 +1,9 @@
|
|
|
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 { SandboxPolicyMismatchError } from "../errors.js";
|
|
1
7
|
const literal = (path) => ({ path, literal: true });
|
|
2
8
|
/** Removes repeats, keeping the first of each. */
|
|
3
9
|
const unique = (paths) => [...new Set(paths)];
|
|
@@ -28,4 +34,51 @@ export function srtSettings(input) {
|
|
|
28
34
|
},
|
|
29
35
|
};
|
|
30
36
|
}
|
|
37
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
38
|
+
/** The strings of a list, or a mismatch naming `field` when it is anything else. */
|
|
39
|
+
function strings(value, field) {
|
|
40
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) {
|
|
41
|
+
throw new SandboxPolicyMismatchError(field);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
/** The paths of a list of literal entries. An entry `srt` would read as a pattern is a mismatch naming `field`. */
|
|
46
|
+
function literalPaths(value, field) {
|
|
47
|
+
if (!Array.isArray(value))
|
|
48
|
+
throw new SandboxPolicyMismatchError(field);
|
|
49
|
+
return value.map((entry) => {
|
|
50
|
+
if (!isRecord(entry) || typeof entry.path !== "string" || entry.literal !== true) {
|
|
51
|
+
throw new SandboxPolicyMismatchError(field);
|
|
52
|
+
}
|
|
53
|
+
return entry.path;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The policy a settings file applies, in the spelling of the request. A write root maps back through `names.write`,
|
|
58
|
+
* and a readable folder through `names.read`. A folder the backend adds itself, and a write root, which is readable
|
|
59
|
+
* anyway, are left out, so any other folder in the file shows up as a read root the request didn't ask for. A file
|
|
60
|
+
* that doesn't deny every read first reads back as the read root `/`. A file that isn't in the shape `srtSettings()`
|
|
61
|
+
* writes throws `SandboxPolicyMismatchError`.
|
|
62
|
+
*/
|
|
63
|
+
export function srtPolicyFromSettings(settings, names) {
|
|
64
|
+
const network = isRecord(settings) && isRecord(settings.network) ? settings.network : undefined;
|
|
65
|
+
const filesystem = isRecord(settings) && isRecord(settings.filesystem) ? settings.filesystem : undefined;
|
|
66
|
+
if (network === undefined || filesystem === undefined)
|
|
67
|
+
throw new SandboxPolicyMismatchError("settings");
|
|
68
|
+
const writeReal = literalPaths(filesystem.allowWrite, "writeRoots");
|
|
69
|
+
const denyRead = literalPaths(filesystem.denyRead, "readRoots");
|
|
70
|
+
const allowRead = literalPaths(filesystem.allowRead, "readRoots");
|
|
71
|
+
const implied = new Set([...writeReal, ...names.implicitReads]);
|
|
72
|
+
const readRoots = denyRead.length === 1 && denyRead[0] === "/"
|
|
73
|
+
? allowRead.flatMap((path) => names.read.get(path) ?? (implied.has(path) ? [] : [path]))
|
|
74
|
+
: ["/"];
|
|
75
|
+
return {
|
|
76
|
+
readRoots,
|
|
77
|
+
writeRoots: writeReal.flatMap((path) => names.write.get(path) ?? [path]),
|
|
78
|
+
network: {
|
|
79
|
+
allow: strings(network.allowedDomains, "network.allow"),
|
|
80
|
+
deny: strings(network.deniedDomains, "network.deny"),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
31
84
|
//# sourceMappingURL=settings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../src/sandbox/srt/settings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../src/sandbox/srt/settings.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAoC1D,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,CA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E;YACP,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc,EAAE,eAAe,CAAC;YACvD,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,cAAc,CAAC;SACrD;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 { SandboxPolicyMismatchError } from \"../errors.js\";\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\n/** How a settings file's real paths map back to the spelling of the request, for `srtPolicyFromSettings()`. */\nexport interface SrtPolicyNames {\n /** For each real read root, the request's spellings that resolved to it. */\n readonly read: ReadonlyMap<string, readonly string[]>;\n /** For each real write root, the request's spellings that resolved to it. */\n readonly write: ReadonlyMap<string, readonly string[]>;\n /** The readable folders the backend adds itself: the system's, `srt`'s own and the caller's extra read roots. */\n readonly implicitReads: readonly string[];\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && value !== null;\n\n/** The strings of a list, or a mismatch naming `field` when it is anything else. */\nfunction strings(value: unknown, field: string): string[] {\n if (!Array.isArray(value) || !value.every((item) => typeof item === \"string\")) {\n throw new SandboxPolicyMismatchError(field);\n }\n return value;\n}\n\n/** The paths of a list of literal entries. An entry `srt` would read as a pattern is a mismatch naming `field`. */\nfunction literalPaths(value: unknown, field: string): string[] {\n if (!Array.isArray(value)) throw new SandboxPolicyMismatchError(field);\n return value.map((entry: unknown) => {\n if (!isRecord(entry) || typeof entry.path !== \"string\" || entry.literal !== true) {\n throw new SandboxPolicyMismatchError(field);\n }\n return entry.path;\n });\n}\n\n/**\n * The policy a settings file applies, in the spelling of the request. A write root maps back through `names.write`,\n * and a readable folder through `names.read`. A folder the backend adds itself, and a write root, which is readable\n * anyway, are left out, so any other folder in the file shows up as a read root the request didn't ask for. A file\n * that doesn't deny every read first reads back as the read root `/`. A file that isn't in the shape `srtSettings()`\n * writes throws `SandboxPolicyMismatchError`.\n */\nexport function srtPolicyFromSettings(settings: unknown, names: SrtPolicyNames): SandboxPolicy {\n const network = isRecord(settings) && isRecord(settings.network) ? settings.network : undefined;\n const filesystem = isRecord(settings) && isRecord(settings.filesystem) ? settings.filesystem : undefined;\n if (network === undefined || filesystem === undefined) throw new SandboxPolicyMismatchError(\"settings\");\n const writeReal = literalPaths(filesystem.allowWrite, \"writeRoots\");\n const denyRead = literalPaths(filesystem.denyRead, \"readRoots\");\n const allowRead = literalPaths(filesystem.allowRead, \"readRoots\");\n const implied = new Set([...writeReal, ...names.implicitReads]);\n const readRoots =\n denyRead.length === 1 && denyRead[0] === \"/\"\n ? allowRead.flatMap((path) => names.read.get(path) ?? (implied.has(path) ? [] : [path]))\n : [\"/\"];\n return {\n readRoots,\n writeRoots: writeReal.flatMap((path) => names.write.get(path) ?? [path]),\n network: {\n allow: strings(network.allowedDomains, \"network.allow\"),\n deny: strings(network.deniedDomains, \"network.deny\"),\n },\n };\n}\n"]}
|
package/dist/sandbox/types.d.ts
CHANGED
|
@@ -24,7 +24,8 @@ export type SandboxTier = "none" | "os" | "container" | "gvisor" | "microvm";
|
|
|
24
24
|
/**
|
|
25
25
|
* What a backend claims to stop. `mistakes`: the agent's own errors, such as a write outside the workspace.
|
|
26
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
|
|
27
|
+
* A backend lists a stop only when its tier and its applied policy deliver it, which `stopsFor()` computes: only a
|
|
28
|
+
* `microvm` stops a `hostile_process`, and none of the backends in this package is one.
|
|
28
29
|
*/
|
|
29
30
|
export type SandboxStop = "mistakes" | "exfiltration" | "hostile_process";
|
|
30
31
|
/** The workspace a sandbox is provisioned for: its root directory and the files to put there first. */
|
|
@@ -43,14 +44,16 @@ export interface SandboxDenial {
|
|
|
43
44
|
/**
|
|
44
45
|
* What a command did: its exit status and output, or the denial that stopped it. A failing command is a result.
|
|
45
46
|
* `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. `
|
|
47
|
-
*
|
|
47
|
+
* command that a signal killed, with `signal` naming it. `timedOut` is `true` only when the sandbox stopped the command
|
|
48
|
+
* at its timeout, so a command that exits with 124 itself can be told apart. `truncated` is `true` when the output
|
|
49
|
+
* passed the cap and the rest was dropped.
|
|
48
50
|
*/
|
|
49
51
|
export type ExecResult = {
|
|
50
52
|
exitCode: number;
|
|
51
53
|
stdout: string;
|
|
52
54
|
stderr: string;
|
|
53
55
|
signal?: string;
|
|
56
|
+
timedOut?: boolean;
|
|
54
57
|
truncated?: boolean;
|
|
55
58
|
} | {
|
|
56
59
|
denied: SandboxDenial;
|
|
@@ -68,6 +71,12 @@ export interface ExecOptions {
|
|
|
68
71
|
/** The most bytes of each of standard output and standard error to keep. Defaults to 8 MiB; the rest is dropped. */
|
|
69
72
|
readonly maxOutputBytes?: number;
|
|
70
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* What a backend can do besides provisioning. `resume`: reattach to a sandbox by its id, such as after `pause` or a lost
|
|
76
|
+
* connection, or start one from a snapshot's id. `snapshot`: save a sandbox's state under an id that `resume` takes.
|
|
77
|
+
* `pause`: suspend a sandbox, keeping its state, until `resume`. A local backend has none of them.
|
|
78
|
+
*/
|
|
79
|
+
export type SandboxCapability = "resume" | "snapshot" | "pause";
|
|
71
80
|
/** A provisioned sandbox. */
|
|
72
81
|
export interface Sandbox {
|
|
73
82
|
/** Runs `command`, an executable and its arguments with no shell, and resolves with what it did. */
|
|
@@ -78,11 +87,39 @@ export interface Sandbox {
|
|
|
78
87
|
writeFile(path: string, data: Uint8Array): Promise<void>;
|
|
79
88
|
/** Stops what is still running, and releases the sandbox. Calling it again does nothing, and any other call afterwards rejects. */
|
|
80
89
|
dispose(): Promise<void>;
|
|
90
|
+
/** The id `SandboxClient.resume()` takes. Only a sandbox from a backend with the `resume` capability has one. */
|
|
91
|
+
readonly id?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The stops the applied policy delivers, as `stopsFor()` computes them from the read-back. A backend that reads its
|
|
94
|
+
* policy back sets it when it provisions, and one that enforces nothing leaves it out.
|
|
95
|
+
*/
|
|
96
|
+
readonly stops?: readonly SandboxStop[];
|
|
97
|
+
/**
|
|
98
|
+
* Reads back the policy the backend applied, from the backend's own record of it, such as the settings file it wrote
|
|
99
|
+
* or the policy a hosted provider reports. A backend that claims any stop has it, and `provision()` compares its
|
|
100
|
+
* answer with the request and throws `SandboxPolicyMismatchError` when they differ.
|
|
101
|
+
*/
|
|
102
|
+
readBack?(): Promise<SandboxPolicy>;
|
|
103
|
+
/** Saves the sandbox's state and resolves with an id that `resume()` starts a sandbox from. Needs `snapshot`. */
|
|
104
|
+
snapshot?(): Promise<string>;
|
|
105
|
+
/** Suspends the sandbox until `resume()` with its `id`. Needs `pause`. */
|
|
106
|
+
pause?(): Promise<void>;
|
|
81
107
|
}
|
|
82
108
|
/** A sandbox backend. */
|
|
83
109
|
export interface SandboxClient {
|
|
84
110
|
readonly tier: SandboxTier;
|
|
111
|
+
/** The stops the backend claims for every policy it accepts. `provision()` checks them against the applied policy. */
|
|
85
112
|
readonly stops: readonly SandboxStop[];
|
|
86
|
-
/**
|
|
113
|
+
/** What the backend can do besides provisioning. Leaving it out means none; call each one through its helper. */
|
|
114
|
+
readonly capabilities?: readonly SandboxCapability[];
|
|
115
|
+
/**
|
|
116
|
+
* Provisions a sandbox, or throws `SandboxUnavailableError` when the backend can't start. It never falls back. A
|
|
117
|
+
* backend that claims a stop reads its policy back first, and throws `SandboxPolicyMismatchError` on a difference.
|
|
118
|
+
*/
|
|
87
119
|
provision(manifest: WorkspaceManifest, policy: SandboxPolicy): Promise<Sandbox>;
|
|
120
|
+
/**
|
|
121
|
+
* Reattaches to the sandbox with this id, or starts one from the snapshot with this id. `policy` is the policy it must
|
|
122
|
+
* still apply. Needs `resume`; call it through `resumeSandbox()`, which checks the read-back.
|
|
123
|
+
*/
|
|
124
|
+
resume?(id: string, policy: SandboxPolicy): Promise<Sandbox>;
|
|
88
125
|
}
|
|
@@ -1 +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
|
|
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 applied policy deliver it, which `stopsFor()` computes: only a\n * `microvm` stops a `hostile_process`, and none of the backends in this package is one.\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. `timedOut` is `true` only when the sandbox stopped the command\n * at its timeout, so a command that exits with 124 itself can be told apart. `truncated` is `true` when the output\n * passed the cap and the rest was dropped.\n */\nexport type ExecResult =\n | { exitCode: number; stdout: string; stderr: string; signal?: string; timedOut?: boolean; 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/**\n * What a backend can do besides provisioning. `resume`: reattach to a sandbox by its id, such as after `pause` or a lost\n * connection, or start one from a snapshot's id. `snapshot`: save a sandbox's state under an id that `resume` takes.\n * `pause`: suspend a sandbox, keeping its state, until `resume`. A local backend has none of them.\n */\nexport type SandboxCapability = \"resume\" | \"snapshot\" | \"pause\";\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 /** The id `SandboxClient.resume()` takes. Only a sandbox from a backend with the `resume` capability has one. */\n readonly id?: string;\n /**\n * The stops the applied policy delivers, as `stopsFor()` computes them from the read-back. A backend that reads its\n * policy back sets it when it provisions, and one that enforces nothing leaves it out.\n */\n readonly stops?: readonly SandboxStop[];\n /**\n * Reads back the policy the backend applied, from the backend's own record of it, such as the settings file it wrote\n * or the policy a hosted provider reports. A backend that claims any stop has it, and `provision()` compares its\n * answer with the request and throws `SandboxPolicyMismatchError` when they differ.\n */\n readBack?(): Promise<SandboxPolicy>;\n /** Saves the sandbox's state and resolves with an id that `resume()` starts a sandbox from. Needs `snapshot`. */\n snapshot?(): Promise<string>;\n /** Suspends the sandbox until `resume()` with its `id`. Needs `pause`. */\n pause?(): Promise<void>;\n}\n\n/** A sandbox backend. */\nexport interface SandboxClient {\n readonly tier: SandboxTier;\n /** The stops the backend claims for every policy it accepts. `provision()` checks them against the applied policy. */\n readonly stops: readonly SandboxStop[];\n /** What the backend can do besides provisioning. Leaving it out means none; call each one through its helper. */\n readonly capabilities?: readonly SandboxCapability[];\n /**\n * Provisions a sandbox, or throws `SandboxUnavailableError` when the backend can't start. It never falls back. A\n * backend that claims a stop reads its policy back first, and throws `SandboxPolicyMismatchError` on a difference.\n */\n provision(manifest: WorkspaceManifest, policy: SandboxPolicy): Promise<Sandbox>;\n /**\n * Reattaches to the sandbox with this id, or starts one from the snapshot with this id. `policy` is the policy it must\n * still apply. Needs `resume`; call it through `resumeSandbox()`, which checks the read-back.\n */\n resume?(id: string, policy: SandboxPolicy): Promise<Sandbox>;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SandboxDenial, SandboxPolicy } from "./types.js";
|
|
2
|
+
/** True when `value` has the shape of a `SandboxDenial`. A record read from the log is checked with it. */
|
|
3
|
+
export declare function isDenial(value: unknown): value is SandboxDenial;
|
|
4
|
+
/**
|
|
5
|
+
* `policy` with exactly the denial's target added, or `undefined` when the denial can't be widened: a path that is the
|
|
6
|
+
* root, relative or untidy, a host with a wildcard or anything but a host and port, an address in a form other than
|
|
7
|
+
* its canonical one, a host that reaches the machine itself or its link (see `isWidenableHost()`), or a host an entry
|
|
8
|
+
* of the policy's own `network.deny` closes (see `isClosed()`), since the host closed it on purpose.
|
|
9
|
+
*/
|
|
10
|
+
export declare function widenPolicy(policy: SandboxPolicy, denial: SandboxDenial): SandboxPolicy | undefined;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place a sandbox policy grows: by exactly the path or host one denial named, and never to host-wide access.
|
|
3
|
+
* Only the escalation runner calls it, with the denial from a verified, signed record and the policy that record
|
|
4
|
+
* holds. No tool input or model output reaches it.
|
|
5
|
+
*/
|
|
6
|
+
import { ipv4Of, isAddressLiteral, isLocalAddress } from "../credentials/addresses.js";
|
|
7
|
+
// A plain host name or address with an optional port: no wildcard, no scheme, no path and no user.
|
|
8
|
+
const HOST = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::[0-9]{1,5})?$/;
|
|
9
|
+
const IPV6 = /^\[[0-9a-f:.]+\](?::[0-9]{1,5})?$/;
|
|
10
|
+
/** True for an absolute POSIX path in its tidy form, below the root: no `.`, `..`, empty segment or NUL. */
|
|
11
|
+
function isWidenablePath(target) {
|
|
12
|
+
if (!target.startsWith("/") || target === "/" || target.includes("\u0000"))
|
|
13
|
+
return false;
|
|
14
|
+
const parts = target.slice(1).split("/");
|
|
15
|
+
return parts.every((part) => part !== "" && part !== "." && part !== "..");
|
|
16
|
+
}
|
|
17
|
+
// Names that resolve to the host itself on common systems without asking DNS.
|
|
18
|
+
const LOCAL_NAMES = ["localhost", "localhost.localdomain", "ip6-localhost", "ip6-loopback"];
|
|
19
|
+
// A last label that a URL parser or `inet_aton()` reads as a number, which makes the whole host an IPv4 address.
|
|
20
|
+
const NUMERIC_LABEL = /^(?:0x[0-9a-f]*|[0-9]+)$/;
|
|
21
|
+
/**
|
|
22
|
+
* True for a host and optional port that a rerun may be allowed to reach. An address must be written in its one
|
|
23
|
+
* canonical form, so it can be compared with a deny entry: an IPv4 address as four decimal octets with no leading
|
|
24
|
+
* zero, and an IPv6 address that does not wrap an IPv4 one. A host whose last label is a number is an IPv4 address, so
|
|
25
|
+
* `127.1`, `2130706433` and `0x7f.1` are refused rather than read as names. A host that reaches the machine itself or
|
|
26
|
+
* its link is never widened, whatever `deny` says: `localhost` and the names under it, and the unspecified, loopback
|
|
27
|
+
* and link-local addresses, which hold the cloud metadata address.
|
|
28
|
+
*/
|
|
29
|
+
function isWidenableHost(target) {
|
|
30
|
+
if (target.length > 255)
|
|
31
|
+
return false;
|
|
32
|
+
const host = hostOf(target);
|
|
33
|
+
if (IPV6.test(target))
|
|
34
|
+
return isAddressLiteral(host) && ipv4Of(host) === undefined && !isLocalAddress(host);
|
|
35
|
+
if (!HOST.test(target))
|
|
36
|
+
return false;
|
|
37
|
+
if (LOCAL_NAMES.includes(host) || host.endsWith(".localhost"))
|
|
38
|
+
return false;
|
|
39
|
+
const last = host.slice(host.lastIndexOf(".") + 1);
|
|
40
|
+
if (NUMERIC_LABEL.test(last))
|
|
41
|
+
return isAddressLiteral(host) && !isLocalAddress(host);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
const KINDS = ["filesystem_read", "filesystem_write", "network"];
|
|
45
|
+
/** True when `value` has the shape of a `SandboxDenial`. A record read from the log is checked with it. */
|
|
46
|
+
export function isDenial(value) {
|
|
47
|
+
if (typeof value !== "object" || value === null)
|
|
48
|
+
return false;
|
|
49
|
+
const denial = value;
|
|
50
|
+
return (KINDS.includes(denial.kind) && typeof denial.target === "string" && typeof denial.reason === "string");
|
|
51
|
+
}
|
|
52
|
+
/** The host of a host-and-port entry, in lower case: brackets off an IPv6 address, and any `:port` and trailing dot off. */
|
|
53
|
+
function hostOf(entry) {
|
|
54
|
+
const lower = entry.trim().toLowerCase();
|
|
55
|
+
if (lower.startsWith("[")) {
|
|
56
|
+
const close = lower.indexOf("]");
|
|
57
|
+
return close < 0 ? lower : lower.slice(1, close);
|
|
58
|
+
}
|
|
59
|
+
const colon = lower.lastIndexOf(":");
|
|
60
|
+
// Two or more colons are an IPv6 address without brackets, which has no port to take off.
|
|
61
|
+
const host = colon >= 0 && lower.indexOf(":") === colon ? lower.slice(0, colon) : lower;
|
|
62
|
+
return host.endsWith(".") ? host.slice(0, -1) : host;
|
|
63
|
+
}
|
|
64
|
+
const isIpv6 = (host) => host.includes(":");
|
|
65
|
+
/** One part of an IPv4 address as `inet_aton()` reads it: decimal, octal after a `0`, or hex after `0x`. */
|
|
66
|
+
function looseOctets(part) {
|
|
67
|
+
if (/^0x[0-9a-f]*$/.test(part))
|
|
68
|
+
return part.length === 2 ? 0 : Number.parseInt(part.slice(2), 16);
|
|
69
|
+
if (/^0[0-7]+$/.test(part))
|
|
70
|
+
return Number.parseInt(part, 8);
|
|
71
|
+
return /^(?:0|[1-9][0-9]*)$/.test(part) ? Number(part) : undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The IPv4 address a deny entry's host names in any form `inet_aton()` accepts (`127.1`, `2130706433`, `0x7f.0.0.1`,
|
|
75
|
+
* `0177.0.0.1`), or in an IPv6 form that wraps one, as a number. `undefined` when it names no IPv4 address.
|
|
76
|
+
*/
|
|
77
|
+
function denyIpv4(pattern) {
|
|
78
|
+
if (isIpv6(pattern))
|
|
79
|
+
return ipv4Of(pattern);
|
|
80
|
+
const parts = pattern.split(".");
|
|
81
|
+
if (parts.length > 4)
|
|
82
|
+
return undefined;
|
|
83
|
+
const values = [];
|
|
84
|
+
for (const part of parts) {
|
|
85
|
+
const value = looseOctets(part);
|
|
86
|
+
if (value === undefined || !Number.isSafeInteger(value))
|
|
87
|
+
return undefined;
|
|
88
|
+
values.push(value);
|
|
89
|
+
}
|
|
90
|
+
const last = values.pop();
|
|
91
|
+
if (values.some((value) => value > 255) || last >= 256 ** (4 - values.length))
|
|
92
|
+
return undefined;
|
|
93
|
+
return values.reduce((sum, value, index) => sum + value * 256 ** (3 - index), 0) + last;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* True when an entry of `deny` closes `target` on some port. An entry matches as `srt` matches a denied domain: `*`
|
|
97
|
+
* matches every host, `*.name` every name under `name` but not `name` itself, and any other entry the host alone, with
|
|
98
|
+
* case ignored. A `*.name` entry also closes an IPv4 address that ends in `.name`, which `srt` would not match. That
|
|
99
|
+
* errs towards not asking. An entry's port is ignored, so a host closed on one port is never widened on any. An IPv4
|
|
100
|
+
* target is closed by an entry that names the same address in any spelling, such as `127.1`, `2130706433` or an IPv6
|
|
101
|
+
* form that wraps it. An IPv6 address counts as closed while `deny` names any IPv6 address, because one address has
|
|
102
|
+
* many spellings. A loopback or link-local entry needs no rule of its own: `isWidenableHost()` refuses every such
|
|
103
|
+
* target. A name that DNS resolves to a closed address can't be seen here; the backend's own deny list covers it.
|
|
104
|
+
*/
|
|
105
|
+
function isClosed(deny, target) {
|
|
106
|
+
const host = hostOf(target);
|
|
107
|
+
const address = isIpv6(host) ? undefined : ipv4Of(host);
|
|
108
|
+
return deny.some((entry) => {
|
|
109
|
+
const pattern = hostOf(entry);
|
|
110
|
+
if (pattern === "*")
|
|
111
|
+
return true;
|
|
112
|
+
if (isIpv6(host))
|
|
113
|
+
return isIpv6(pattern);
|
|
114
|
+
if (address !== undefined && denyIpv4(pattern) === address)
|
|
115
|
+
return true;
|
|
116
|
+
if (pattern.startsWith("*."))
|
|
117
|
+
return host.endsWith(pattern.slice(1));
|
|
118
|
+
return host === pattern;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const plus = (list, item) => (list.includes(item) ? [...list] : [...list, item]);
|
|
122
|
+
/**
|
|
123
|
+
* `policy` with exactly the denial's target added, or `undefined` when the denial can't be widened: a path that is the
|
|
124
|
+
* root, relative or untidy, a host with a wildcard or anything but a host and port, an address in a form other than
|
|
125
|
+
* its canonical one, a host that reaches the machine itself or its link (see `isWidenableHost()`), or a host an entry
|
|
126
|
+
* of the policy's own `network.deny` closes (see `isClosed()`), since the host closed it on purpose.
|
|
127
|
+
*/
|
|
128
|
+
export function widenPolicy(policy, denial) {
|
|
129
|
+
const { readRoots, writeRoots, network } = policy;
|
|
130
|
+
const base = {
|
|
131
|
+
readRoots: [...readRoots],
|
|
132
|
+
writeRoots: [...writeRoots],
|
|
133
|
+
network: { allow: [...network.allow], deny: [...network.deny] },
|
|
134
|
+
};
|
|
135
|
+
switch (denial.kind) {
|
|
136
|
+
case "filesystem_read":
|
|
137
|
+
return isWidenablePath(denial.target) ? { ...base, readRoots: plus(readRoots, denial.target) } : undefined;
|
|
138
|
+
case "filesystem_write":
|
|
139
|
+
return isWidenablePath(denial.target) ? { ...base, writeRoots: plus(writeRoots, denial.target) } : undefined;
|
|
140
|
+
case "network": {
|
|
141
|
+
const host = denial.target;
|
|
142
|
+
if (!isWidenableHost(host) || isClosed(network.deny, host))
|
|
143
|
+
return undefined;
|
|
144
|
+
return { ...base, network: { ...base.network, allow: plus(network.allow, host) } };
|
|
145
|
+
}
|
|
146
|
+
default:
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=widen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widen.js","sourceRoot":"","sources":["../../src/sandbox/widen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAGvF,mGAAmG;AACnG,MAAM,IAAI,GAAG,uGAAuG,CAAC;AACrH,MAAM,IAAI,GAAG,mCAAmC,CAAC;AAEjD,4GAA4G;AAC5G,SAAS,eAAe,CAAC,MAAc;IACrC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IACzF,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,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sourcesContent":["/**\n * The one place a sandbox policy grows: by exactly the path or host one denial named, and never to host-wide access.\n * Only the escalation runner calls it, with the denial from a verified, signed record and the policy that record\n * holds. No tool input or model output reaches it.\n */\nimport { ipv4Of, isAddressLiteral, isLocalAddress } from \"../credentials/addresses.js\";\nimport type { SandboxDenial, SandboxPolicy } from \"./types.js\";\n\n// A plain host name or address with an optional port: no wildcard, no scheme, no path and no user.\nconst HOST = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::[0-9]{1,5})?$/;\nconst IPV6 = /^\\[[0-9a-f:.]+\\](?::[0-9]{1,5})?$/;\n\n/** True for an absolute POSIX path in its tidy form, below the root: no `.`, `..`, empty segment or NUL. */\nfunction isWidenablePath(target: string): boolean {\n if (!target.startsWith(\"/\") || target === \"/\" || target.includes(\"\\u0000\")) return false;\n const parts = target.slice(1).split(\"/\");\n return parts.every((part) => part !== \"\" && part !== \".\" && part !== \"..\");\n}\n\n// Names that resolve to the host itself on common systems without asking DNS.\nconst LOCAL_NAMES: readonly string[] = [\"localhost\", \"localhost.localdomain\", \"ip6-localhost\", \"ip6-loopback\"];\n// A last label that a URL parser or `inet_aton()` reads as a number, which makes the whole host an IPv4 address.\nconst NUMERIC_LABEL = /^(?:0x[0-9a-f]*|[0-9]+)$/;\n\n/**\n * True for a host and optional port that a rerun may be allowed to reach. An address must be written in its one\n * canonical form, so it can be compared with a deny entry: an IPv4 address as four decimal octets with no leading\n * zero, and an IPv6 address that does not wrap an IPv4 one. A host whose last label is a number is an IPv4 address, so\n * `127.1`, `2130706433` and `0x7f.1` are refused rather than read as names. A host that reaches the machine itself or\n * its link is never widened, whatever `deny` says: `localhost` and the names under it, and the unspecified, loopback\n * and link-local addresses, which hold the cloud metadata address.\n */\nfunction isWidenableHost(target: string): boolean {\n if (target.length > 255) return false;\n const host = hostOf(target);\n if (IPV6.test(target)) return isAddressLiteral(host) && ipv4Of(host) === undefined && !isLocalAddress(host);\n if (!HOST.test(target)) return false;\n if (LOCAL_NAMES.includes(host) || host.endsWith(\".localhost\")) return false;\n const last = host.slice(host.lastIndexOf(\".\") + 1);\n if (NUMERIC_LABEL.test(last)) return isAddressLiteral(host) && !isLocalAddress(host);\n return true;\n}\n\nconst KINDS: readonly string[] = [\"filesystem_read\", \"filesystem_write\", \"network\"];\n\n/** True when `value` has the shape of a `SandboxDenial`. A record read from the log is checked with it. */\nexport function isDenial(value: unknown): value is SandboxDenial {\n if (typeof value !== \"object\" || value === null) return false;\n const denial = value as Record<string, unknown>;\n return (\n KINDS.includes(denial.kind as string) && typeof denial.target === \"string\" && typeof denial.reason === \"string\"\n );\n}\n\n/** The host of a host-and-port entry, in lower case: brackets off an IPv6 address, and any `:port` and trailing dot off. */\nfunction hostOf(entry: string): string {\n const lower = entry.trim().toLowerCase();\n if (lower.startsWith(\"[\")) {\n const close = lower.indexOf(\"]\");\n return close < 0 ? lower : lower.slice(1, close);\n }\n const colon = lower.lastIndexOf(\":\");\n // Two or more colons are an IPv6 address without brackets, which has no port to take off.\n const host = colon >= 0 && lower.indexOf(\":\") === colon ? lower.slice(0, colon) : lower;\n return host.endsWith(\".\") ? host.slice(0, -1) : host;\n}\n\nconst isIpv6 = (host: string): boolean => host.includes(\":\");\n\n/** One part of an IPv4 address as `inet_aton()` reads it: decimal, octal after a `0`, or hex after `0x`. */\nfunction looseOctets(part: string): number | undefined {\n if (/^0x[0-9a-f]*$/.test(part)) return part.length === 2 ? 0 : Number.parseInt(part.slice(2), 16);\n if (/^0[0-7]+$/.test(part)) return Number.parseInt(part, 8);\n return /^(?:0|[1-9][0-9]*)$/.test(part) ? Number(part) : undefined;\n}\n\n/**\n * The IPv4 address a deny entry's host names in any form `inet_aton()` accepts (`127.1`, `2130706433`, `0x7f.0.0.1`,\n * `0177.0.0.1`), or in an IPv6 form that wraps one, as a number. `undefined` when it names no IPv4 address.\n */\nfunction denyIpv4(pattern: string): number | undefined {\n if (isIpv6(pattern)) return ipv4Of(pattern);\n const parts = pattern.split(\".\");\n if (parts.length > 4) return undefined;\n const values: number[] = [];\n for (const part of parts) {\n const value = looseOctets(part);\n if (value === undefined || !Number.isSafeInteger(value)) return undefined;\n values.push(value);\n }\n const last = values.pop() as number;\n if (values.some((value) => value > 255) || last >= 256 ** (4 - values.length)) return undefined;\n return values.reduce((sum, value, index) => sum + value * 256 ** (3 - index), 0) + last;\n}\n\n/**\n * True when an entry of `deny` closes `target` on some port. An entry matches as `srt` matches a denied domain: `*`\n * matches every host, `*.name` every name under `name` but not `name` itself, and any other entry the host alone, with\n * case ignored. A `*.name` entry also closes an IPv4 address that ends in `.name`, which `srt` would not match. That\n * errs towards not asking. An entry's port is ignored, so a host closed on one port is never widened on any. An IPv4\n * target is closed by an entry that names the same address in any spelling, such as `127.1`, `2130706433` or an IPv6\n * form that wraps it. An IPv6 address counts as closed while `deny` names any IPv6 address, because one address has\n * many spellings. A loopback or link-local entry needs no rule of its own: `isWidenableHost()` refuses every such\n * target. A name that DNS resolves to a closed address can't be seen here; the backend's own deny list covers it.\n */\nfunction isClosed(deny: readonly string[], target: string): boolean {\n const host = hostOf(target);\n const address = isIpv6(host) ? undefined : ipv4Of(host);\n return deny.some((entry) => {\n const pattern = hostOf(entry);\n if (pattern === \"*\") return true;\n if (isIpv6(host)) return isIpv6(pattern);\n if (address !== undefined && denyIpv4(pattern) === address) return true;\n if (pattern.startsWith(\"*.\")) return host.endsWith(pattern.slice(1));\n return host === pattern;\n });\n}\n\nconst plus = (list: readonly string[], item: string): string[] => (list.includes(item) ? [...list] : [...list, item]);\n\n/**\n * `policy` with exactly the denial's target added, or `undefined` when the denial can't be widened: a path that is the\n * root, relative or untidy, a host with a wildcard or anything but a host and port, an address in a form other than\n * its canonical one, a host that reaches the machine itself or its link (see `isWidenableHost()`), or a host an entry\n * of the policy's own `network.deny` closes (see `isClosed()`), since the host closed it on purpose.\n */\nexport function widenPolicy(policy: SandboxPolicy, denial: SandboxDenial): SandboxPolicy | undefined {\n const { readRoots, writeRoots, network } = policy;\n const base = {\n readRoots: [...readRoots],\n writeRoots: [...writeRoots],\n network: { allow: [...network.allow], deny: [...network.deny] },\n };\n switch (denial.kind) {\n case \"filesystem_read\":\n return isWidenablePath(denial.target) ? { ...base, readRoots: plus(readRoots, denial.target) } : undefined;\n case \"filesystem_write\":\n return isWidenablePath(denial.target) ? { ...base, writeRoots: plus(writeRoots, denial.target) } : undefined;\n case \"network\": {\n const host = denial.target;\n if (!isWidenableHost(host) || isClosed(network.deny, host)) return undefined;\n return { ...base, network: { ...base.network, allow: plus(network.allow, host) } };\n }\n default:\n return undefined;\n }\n}\n"]}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createApprovals()`: the pause and resume of a call that waits for a person. A gate `ask` ends a turn
|
|
3
|
+
* `awaiting_approval` with the signed request in the log, as an `approval_requested` entry written before the harness's
|
|
4
|
+
* own observers hear of it, and a code call that asks writes the same entry. `pending()` reads the requests that still
|
|
5
|
+
* wait, and `resolve()` answers them from any process that can open the session and load the key ring, because the log
|
|
6
|
+
* holds everything the resume needs. A turn's answers resume the turn; a code call's answer runs the call with no model
|
|
7
|
+
* step. An answer may also cover more than its own call (sticky and grouped answers), and a quorum policy may need
|
|
8
|
+
* several answers before a call runs.
|
|
9
|
+
*/
|
|
10
|
+
import type { SessionEntry } from "@buildanagent/protocol";
|
|
1
11
|
import type { Resolution, SignedPendingRequest } from "@buildanagent/sdk";
|
|
2
12
|
import type { CodeCallResult, Harness } from "../harness.js";
|
|
3
13
|
import { type PendingApproval } from "./rebuild.js";
|
|
4
|
-
import { type ResumeOptions, type TurnResult } from "./runner.js";
|
|
14
|
+
import { type ResolutionRecord, type ResumeOptions, type TurnResult } from "./runner.js";
|
|
5
15
|
import type { Session } from "./session.js";
|
|
6
16
|
/** What a quorum policy says about one request: its answers are enough, not yet, a refusal, or too old. */
|
|
7
17
|
export type QuorumVerdict = "met" | "pending" | "rejected" | "expired";
|
|
@@ -77,5 +87,24 @@ export interface Approvals<H = unknown> {
|
|
|
77
87
|
*/
|
|
78
88
|
resolve(session: Session, resolutions: readonly Resolution[], options?: ResolveOptions<H>): Promise<TurnResult | CodeCallResult>;
|
|
79
89
|
}
|
|
90
|
+
/** The answers already written for each request, oldest first. */
|
|
91
|
+
export declare function answersByRequest(path: readonly SessionEntry[]): Map<string, Resolution[]>;
|
|
92
|
+
/** Refuses an answer set that can't be applied: no signer, an answer twice, a request that doesn't wait, a self-approval. */
|
|
93
|
+
export declare function checkAnswers<H>(harness: Harness<H>, waiting: ReadonlyMap<string, unknown>, resolutions: readonly Resolution[], requesterId: string | undefined): void;
|
|
94
|
+
/**
|
|
95
|
+
* What each waiting request gets once the quorum policy has looked at it: the answer the SDK applies for `met`, a denial
|
|
96
|
+
* for `rejected` and `expired`, and nothing for `pending`, whose new answers are marked as waited on so a crash
|
|
97
|
+
* of this resume never counts them as given. The records returned are the entries to write, denials by the policy
|
|
98
|
+
* included, so the log tells an expiry from any other refusal.
|
|
99
|
+
*/
|
|
100
|
+
export declare function settled(policy: QuorumPolicy, waiting: readonly Pick<PendingApproval, "request">[], earlier: ReadonlyMap<string, Resolution[]>, records: readonly ResolutionRecord[]): Promise<{
|
|
101
|
+
forRun: Resolution[];
|
|
102
|
+
records: ResolutionRecord[];
|
|
103
|
+
}>;
|
|
104
|
+
/** The harness and quorum policy `approvals` was made with, or `undefined` for one `createApprovals()` did not make. */
|
|
105
|
+
export declare function approvalsBinding<H>(approvals: Approvals<H>): {
|
|
106
|
+
readonly harness: Harness<H>;
|
|
107
|
+
readonly quorum: QuorumPolicy;
|
|
108
|
+
} | undefined;
|
|
80
109
|
/** Creates the approvals of `harness`, which needs a `signer` to check the requests it resumes. */
|
|
81
110
|
export declare function createApprovals<H = unknown>(harness: Harness<H>, settings?: ApprovalsOptions): Approvals<H>;
|