@buildanagent/harness 0.1.0-alpha.28 → 0.1.0-alpha.29
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 +111 -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/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 +9 -5
- package/dist/errors.js +8 -4
- 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/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 +6 -4
- package/dist/sandbox/index.js +5 -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/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 +34 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sandbox/docker/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;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,MAAM,EACN,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAoB,WAAW,EAAsB,aAAa,EAAE,MAAM,eAAe,CAAC;AA2BjG,0EAA0E;AAC1E,MAAM,CAAC,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAElE,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAW,CAAC;AACtE,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACjC,mEAAmE;AACnE,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,yFAAyF;AACzF,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAClC,2HAA2H;AAC3H,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,uEAAuE;AACvE,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,kFAAkF;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AC,KAAc,EAAE,EAAE;QACxB,MAAM,WAAW,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IACL,IAAI,KAAK,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,WAAW,CAAC,aAAa,KAAK,sEAAsE,CAAC,CAAC;IAC9G,CAAC;AACH,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/sandbox/docker`: the container-tier backend. Each command runs in its own locked-down\n * container: all capabilities dropped, a read-only root file system, no network, no new privileges, and limits on\n * processes, CPUs and memory. Only the policy's write roots are writable, and only the policy's roots are mounted. It\n * claims `mistakes` and `exfiltration`, never a `hostile_process`: the kernel is shared with the host. Only Linux and a\n * rootful daemon are tested. A backend that can't start throws `SandboxUnavailableError` and runs nothing. It is\n * Node-only.\n *\n * The container has no network, so a command reaches a host only through a proxy socket the caller mounts. The file calls\n * run in the host on the mounted folders, checked by their real path.\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 inside,\n isProtectedPath,\n PROTECTED_TOP_LEVEL,\n realOrSelf,\n workspaceRoot,\n} from \"../host-files.js\";\nimport { type NodeModules, nodeModules, type ProcessResult, ProcessRunner } from \"../process.js\";\nimport type { ExecOptions, ExecResult, Sandbox, SandboxClient, SandboxPolicy, WorkspaceManifest } from \"../types.js\";\n\n/** The options of `dockerSandbox()`. */\nexport interface DockerSandboxOptions {\n /** The image to run, which must already be on the Docker host: `provision()` never pulls. Pin it by digest. */\n readonly image: string;\n /** CPUs a command may use. Defaults to 1. */\n readonly cpus?: number;\n /** Megabytes of memory a command may use, with no swap. Defaults to 1024. */\n readonly memoryMb?: number;\n /** Processes a command may start. Defaults to 256. */\n readonly pidsLimit?: number;\n /** The `docker` executable. Without it the backend finds `docker` on the absolute folders of the host's `PATH`. */\n readonly binary?: string;\n /** The Docker daemon's address. Without it the backend passes the host's `DOCKER_HOST` when it is set. */\n readonly dockerHost?: string;\n /** The user and group a command runs as, as `uid:gid`. Defaults to this process's, so its files stay yours. */\n readonly user?: string;\n /** Folders to read besides the policy's roots, mounted read-only. */\n readonly extraReadRoots?: readonly string[];\n /** Folders that stay read-only inside a write root, such as the session's own log folder. */\n readonly denyWrite?: readonly string[];\n /** A Unix socket on the host that a command may use to reach the hosts its policy allows, mounted at `DOCKER_PROXY_SOCKET_PATH`. */\n readonly proxySocket?: string;\n}\n\n/** Where a command finds the proxy socket, when the caller mounts one. */\nexport const DOCKER_PROXY_SOCKET_PATH = \"/run/harness/proxy.sock\";\n\nconst DEFAULTS = { cpus: 1, memoryMb: 1024, pidsLimit: 256 } as const;\nconst DAEMON_TIMEOUT_MS = 20_000;\n// The longest one call that kills or removes a container may take.\nconst CALL_TIMEOUT_MS = 5000;\n// Creating a container copies the image on some storage drivers, which can take a while.\nconst CREATE_TIMEOUT_MS = 120_000;\n// How long a stopped `docker run` client has to leave on its own, which lets it cancel a container that isn't started yet.\nconst GRACE_MS = 3000;\nconst KILL_ATTEMPTS = 5;\nconst KILL_RETRY_MS = 100;\nconst SWEEP_QUIET_PASSES = 2;\n// The longest the sweep at the end waits for the last container to go.\nconst SWEEP_MAX_MS = 20_000;\nconst SWEEP_PAUSE_MS = 200;\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// A path in a `--mount` value can't hold a comma or a quote, which that syntax reads as separators.\nconst MOUNTABLE = /^[^,\"\\n\\r]+$/;\n\n/** One bind mount: the real host path, mounted at the same path inside, or at `to`. */\ninterface Mount {\n readonly from: string;\n readonly to: string;\n readonly readOnly: boolean;\n}\n\n/** Everything a provisioned sandbox holds. */\ninterface DockerState {\n readonly modules: NodeModules;\n readonly docker: string;\n readonly image: string;\n readonly root: string;\n readonly files: HostFiles;\n readonly mounts: readonly Mount[];\n readonly flags: readonly string[];\n /** The environment the `docker` client runs with: where to find its programs, and a private empty `HOME`. */\n readonly clientEnv: Readonly<Record<string, string>>;\n /** A private folder that holds the client's `HOME`, removed on dispose. */\n readonly folder: string;\n /** Marks this sandbox's containers, so `dispose()` can find any that a stopped client left behind. */\n readonly label: string;\n}\n\nconst mountFlags = (mount: Mount): string[] => [\n \"--mount\",\n `type=bind,src=${mount.from},dst=${mount.to}${mount.readOnly ? \",readonly\" : \"\"}`,\n];\n\nclass DockerSandbox extends BackendSandbox {\n private started = 0;\n // Whether a creation was left to finish in the background, which a sweep at the end has to catch.\n private abandoned = false;\n // The containers being created, which `dispose()` waits for before it sweeps.\n private readonly pending = new Set<Promise<unknown>>();\n private readonly runner: ProcessRunner;\n // Runs the calls that manage containers, which `dispose()` must not cut short: a `create` that is stopped half way\n // leaves a container behind.\n private readonly manager: ProcessRunner;\n private readonly state: DockerState;\n\n constructor(state: DockerState) {\n super(state);\n this.state = state;\n this.runner = new ProcessRunner(state.modules);\n this.manager = new ProcessRunner(state.modules);\n }\n\n /** Runs the `docker` client with `args` and waits for it, for the calls that manage containers. */\n async client(args: readonly string[], timeoutMs: number) {\n return this.manager.run(\n {\n program: this.state.docker,\n args,\n cwd: this.state.root,\n env: this.state.clientEnv,\n missingProgram: \"reject\",\n },\n { env: {}, signal: new AbortController().signal, timeoutMs },\n );\n }\n\n /** The `docker run` arguments for one command in a container called `name`. */\n private runArguments(name: string, cwd: string, command: readonly string[], env: Readonly<Record<string, string>>) {\n const assignments: string[] = [];\n for (const [variable, value] of Object.entries(env)) {\n if (!VARIABLE_NAME.test(variable)) {\n throw new HarnessError(\"invalid_sandbox_options\", `${JSON.stringify(variable)} is not a variable name`);\n }\n assignments.push(`${variable}=${value}`);\n }\n const { state } = this;\n // `env -i` clears the image's own variables, so the command holds exactly the ones it was given.\n return [\n \"create\",\n \"--rm\",\n \"--name\",\n name,\n \"--label\",\n state.label,\n ...state.flags,\n ...state.mounts.flatMap(mountFlags),\n \"--workdir\",\n cwd,\n \"--entrypoint\",\n \"env\",\n state.image,\n \"-i\",\n // Ends `env`'s options, so a first word that starts with `-` is a program name.\n \"--\",\n ...assignments,\n ...command,\n ];\n }\n\n /** Removes the container if it exists, which is all a container that never started needs. */\n private async removeContainer(name: string): Promise<void> {\n await this.client([\"rm\", \"--force\", name], CALL_TIMEOUT_MS).catch(() => undefined);\n }\n\n /** Kills the container, trying again while the daemon is still creating it, and removes what is left. */\n private async killContainer(name: string): Promise<void> {\n for (let attempt = 0; attempt < KILL_ATTEMPTS; attempt += 1) {\n const result = await this.client([\"kill\", name], CALL_TIMEOUT_MS).catch(() => undefined);\n if (result?.exitCode === 0) break;\n await new Promise((resolve) => setTimeout(resolve, KILL_RETRY_MS));\n }\n await this.removeContainer(name);\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 located = prepared;\n const { root } = this.state;\n this.started += 1;\n const name = `${this.state.label.split(\"=\")[1]}-${this.started}`;\n const started = Date.now();\n // The container is created first and started after, so a stop never leaves a client half way through creating one.\n const created = this.client(this.runArguments(name, located.cwd, command, options.env), CREATE_TIMEOUT_MS);\n this.track(created);\n const made = await this.untilStopped(name, created, options);\n if (\"timedOut\" in made) return made.timedOut;\n if (made.exitCode !== 0) {\n await this.removeContainer(name);\n return { exitCode: made.exitCode, stdout: \"\", stderr: made.stderr };\n }\n try {\n this.live();\n options.signal.throwIfAborted();\n } catch (error) {\n await this.killContainer(name);\n throw error;\n }\n const remaining =\n options.timeoutMs === undefined ? {} : { timeoutMs: Math.max(1, options.timeoutMs - (Date.now() - started)) };\n const { stdoutBytes: _bytes, ...result } = await this.runner.run(\n {\n program: this.state.docker,\n args: [\"start\", \"--attach\", name],\n cwd: root,\n env: this.state.clientEnv,\n missingProgram: \"reject\",\n onStop: () => this.killContainer(name),\n graceMs: GRACE_MS,\n },\n { ...options, ...remaining },\n );\n return result;\n }\n\n /** Keeps `work` in the set that `dispose()` waits for, until it settles. */\n private track(work: Promise<unknown>): void {\n const tracked = work.then(\n () => undefined,\n () => undefined,\n );\n this.pending.add(tracked);\n void tracked.then(() => this.pending.delete(tracked));\n }\n\n /**\n * Waits for a container to be created, but settles the call when the caller's signal aborts or its timeout passes. The\n * creation can't be cut short without leaving a container behind, so it carries on in the background, and the container\n * is removed when it ends.\n */\n private untilStopped(\n name: string,\n created: Promise<ProcessResult>,\n options: ExecOptions,\n ): Promise<ProcessResult | { readonly timedOut: ExecResult }> {\n return new Promise((resolve, reject) => {\n let settled = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n const finish = (settle: () => void, discard: boolean) => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n options.signal.removeEventListener(\"abort\", onAbort);\n if (discard) {\n this.abandoned = true;\n this.track(created.then(() => this.killContainer(name)));\n }\n settle();\n };\n const onAbort = () => finish(() => reject(options.signal.reason), true);\n options.signal.addEventListener(\"abort\", onAbort, { once: true });\n if (options.timeoutMs !== undefined) {\n const note = `timed out after ${options.timeoutMs} ms\\n`;\n timer = setTimeout(\n () => finish(() => resolve({ timedOut: { exitCode: 124, stdout: \"\", stderr: note } }), true),\n options.timeoutMs,\n );\n }\n created.then(\n (result) => finish(() => resolve(result), false),\n (error: unknown) => finish(() => reject(error), false),\n );\n });\n }\n\n /**\n * Removes every container of this sandbox until none is left. A client stopped while the daemon was creating its\n * container can leave one behind, and a removal can take a while on a slow storage driver, so it waits for the last to go.\n * With no creation left in the background, an empty first pass ends it.\n */\n private async sweep(): Promise<void> {\n const deadline = Date.now() + SWEEP_MAX_MS;\n let quiet = 0;\n for (;;) {\n const left = await this.client(\n [\"ps\", \"--all\", \"--quiet\", \"--filter\", `label=${this.state.label}`],\n DAEMON_TIMEOUT_MS,\n )\n .then((result) => result.stdout.split(\"\\n\").filter((id) => id !== \"\"))\n .catch(() => []);\n quiet = left.length === 0 ? quiet + 1 : 0;\n if (left.length > 0) await this.client([\"rm\", \"--force\", ...left], DAEMON_TIMEOUT_MS).catch(() => undefined);\n if ((left.length === 0 && (!this.abandoned || quiet >= SWEEP_QUIET_PASSES)) || Date.now() > deadline) return;\n await new Promise((resolve) => setTimeout(resolve, SWEEP_PAUSE_MS));\n }\n }\n\n protected async shutDown(): Promise<void> {\n await this.runner.stopAll();\n await Promise.allSettled([...this.pending]);\n await this.sweep();\n await this.state.modules.fs.rm(this.state.folder, { recursive: true, force: true });\n }\n}\n\n/** Throws unless `image` is a name `docker run` takes as an image and not as an option. */\nfunction checkOptionValues(options: DockerSandboxOptions): void {\n const { image, cpus, memoryMb, pidsLimit, user } = options;\n if (typeof image !== \"string\" || image === \"\" || /\\s/.test(image) || image.startsWith(\"-\")) {\n throw new HarnessError(\n \"invalid_sandbox_options\",\n \"dockerSandbox needs an image name, such as one pinned by digest\",\n );\n }\n const bad = (what: string) => new HarnessError(\"invalid_sandbox_options\", `${what} is not usable`);\n if (cpus !== undefined && !(Number.isFinite(cpus) && cpus > 0)) throw bad(\"cpus\");\n if (memoryMb !== undefined && !(Number.isInteger(memoryMb) && memoryMb >= 6)) throw bad(\"memoryMb\");\n if (pidsLimit !== undefined && !(Number.isInteger(pidsLimit) && pidsLimit >= 1)) throw bad(\"pidsLimit\");\n if (user !== undefined && !/^[0-9]+(:[0-9]+)?$/.test(user)) throw bad(\"user\");\n}\n\n/** The sockets a Docker client may use: the default ones, and the one `dockerHost` names when it is a Unix socket. */\nfunction daemonSockets(dockerHost: string | undefined): string[] {\n const named = dockerHost?.startsWith(\"unix://\") ? [dockerHost.slice(\"unix://\".length)] : [];\n return [\"/var/run/docker.sock\", \"/run/docker.sock\", ...named];\n}\n\n/** Throws unless every source is mountable, and none is `/` or holds a Docker daemon socket, which would hand over the host. */\nasync function checkSources(modules: NodeModules, sources: readonly string[], dockerHost: string | undefined) {\n for (const from of sources) {\n if (!MOUNTABLE.test(from)) {\n throw new HarnessError(\"invalid_sandbox_options\", `a mounted folder can't have a comma or quote: ${from}`);\n }\n if (from === \"/\") throw new HarnessError(\"invalid_sandbox_options\", \"a mounted folder can't resolve to /\");\n }\n for (const socket of daemonSockets(dockerHost)) {\n const real = await modules.fs.realpath(socket).catch(() => undefined);\n if (real !== undefined && sources.some((from) => inside(modules, from, real))) {\n throw new HarnessError(\"invalid_sandbox_options\", `a mounted folder would hold the Docker socket ${socket}`);\n }\n }\n}\n\n/** One mount for each destination, read-only when any of the mounts for it is. */\nfunction onePerDestination(mounts: readonly Mount[]): Mount[] {\n const byDestination = new Map<string, Mount>();\n for (const mount of mounts) {\n const earlier = byDestination.get(mount.to);\n byDestination.set(\n mount.to,\n earlier === undefined ? mount : { ...mount, readOnly: earlier.readOnly || mount.readOnly },\n );\n }\n return [...byDestination.values()];\n}\n\n/**\n * The real mounts for a policy: write roots writable, read roots and extras read-only, and read-only again on top the\n * `denyWrite` folders inside a write root (made after the checks, so a later write can't find them writable) and the\n * protected files that exist. A `denyWrite` path outside every write root is not mounted: nothing there is writable.\n */\nasync function planMounts(modules: NodeModules, policy: SandboxPolicy, options: DockerSandboxOptions) {\n const real = (paths: readonly string[]) => Promise.all(paths.map((path) => realOrSelf(modules, path)));\n const [readRoots, writeRoots, extra, denyWrite] = await Promise.all([\n real(policy.readRoots),\n real(policy.writeRoots),\n real(options.extraReadRoots ?? []),\n real(options.denyWrite ?? []),\n ]);\n for (const root of writeRoots) {\n if (!(await modules.fs.stat(root).catch(() => undefined))?.isDirectory()) {\n throw new HarnessError(\"invalid_sandbox_options\", `a write root must be an existing folder: ${root}`);\n }\n }\n const underWrite = (path: string) => writeRoots.some((root) => inside(modules, root, path));\n const denied = denyWrite.filter(underWrite);\n const protectedPaths = writeRoots.flatMap((root) => PROTECTED_TOP_LEVEL.map((name) => modules.path.join(root, name)));\n const readOnlyRoots = [...readRoots, ...extra].filter((path) => !underWrite(path));\n const base: Mount[] = [\n ...writeRoots.map((from) => ({ from, to: from, readOnly: false })),\n ...(await existing(modules, readOnlyRoots)).map((from) => ({ from, to: from, readOnly: true })),\n ];\n const guarded = [...denied, ...(await existing(modules, protectedPaths))].map((from) => ({\n from,\n to: from,\n readOnly: true,\n }));\n return {\n base: onePerDestination(base),\n mounts: onePerDestination([...base, ...guarded]),\n roots: { read: readRoots, write: writeRoots, denyWrite: denied },\n };\n}\n\n/** The `docker run` flags that lock a container down, and limit what it may use. */\nfunction lockdownFlags(options: DockerSandboxOptions, user: string): string[] {\n const memory = `${options.memoryMb ?? DEFAULTS.memoryMb}m`;\n return [\n \"--pull\",\n \"never\",\n \"--network\",\n \"none\",\n \"--read-only\",\n \"--cap-drop\",\n \"ALL\",\n \"--security-opt\",\n \"no-new-privileges\",\n \"--ipc\",\n \"none\",\n \"--pids-limit\",\n String(options.pidsLimit ?? DEFAULTS.pidsLimit),\n \"--cpus\",\n String(options.cpus ?? DEFAULTS.cpus),\n \"--memory\",\n memory,\n \"--memory-swap\",\n memory,\n \"--user\",\n user,\n // The only writable place that isn't a mounted write root: memory-backed, so it is gone with the container.\n \"--tmpfs\",\n \"/tmp:rw,nosuid,size=64m\",\n ];\n}\n\n/** The `docker` executable, or a `SandboxUnavailableError` when there is none. */\nasync function dockerProgram(modules: NodeModules, options: DockerSandboxOptions, hostPath: string): Promise<string> {\n if (options.binary !== undefined) {\n const program = modules.path.resolve(options.binary);\n await modules.fs.access(program, modules.fs.constants.X_OK).catch((error: unknown) => {\n throw new SandboxUnavailableError(\"docker\", `${options.binary} is not an executable file`, { cause: error });\n });\n return program;\n }\n const found = await findOnPath(modules, hostPath, \"docker\");\n if (found === undefined) throw new SandboxUnavailableError(\"docker\", \"docker is not on the PATH\");\n return found;\n}\n\n/** The first line of what a client printed, for the message of a failure. */\nconst firstLine = (text: string): string => text.trim().split(\"\\n\")[0] ?? \"no output\";\n\n/**\n * Builds the Docker backend. `provision()` checks the platform, the `docker` client, the daemon and that the image is on\n * the host, so a host that can't run the container throws `SandboxUnavailableError` and runs nothing. The `docker`\n * client runs with a clean environment: a `PATH`, a private empty `HOME` and `DOCKER_HOST` when one is set, and never\n * the parent's environment. The policy's roots, `extraReadRoots`, `denyWrite` and `proxySocket` must be absolute, and\n * the workspace must lie inside a root. A command whose first word contains `=` resolves with exit code 127, as under\n * `none`.\n */\nexport function dockerSandbox(options: DockerSandboxOptions): SandboxClient {\n checkOptionValues(options);\n return {\n tier: \"container\",\n stops: [\"mistakes\", \"exfiltration\"],\n async provision(manifest: WorkspaceManifest, policy: SandboxPolicy): Promise<Sandbox> {\n const modules = nodeModules(\"docker\");\n if (process.platform !== \"linux\") {\n throw new SandboxUnavailableError(\n \"docker\",\n `only Linux is supported, because it is the only platform this backend is tested on, and this is ${process.platform}`,\n );\n }\n const hostPath = absolutePath(modules, process.env.PATH);\n const docker = await dockerProgram(modules, options, 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 folder = await modules.fs.mkdtemp(modules.path.join(modules.os.tmpdir(), \"harness-docker-\"));\n try {\n const sandbox = await startSandbox({ modules, docker, hostPath, root, folder, manifest, policy, options });\n return sandbox;\n } catch (error) {\n await modules.fs.rm(folder, { recursive: true, force: true });\n throw error;\n }\n },\n };\n}\n\ninterface StartInput {\n readonly modules: NodeModules;\n readonly docker: string;\n readonly hostPath: string;\n readonly root: string;\n readonly folder: string;\n readonly manifest: WorkspaceManifest;\n readonly policy: SandboxPolicy;\n readonly options: DockerSandboxOptions;\n}\n\nasync function startSandbox(input: StartInput): Promise<DockerSandbox> {\n const { modules, options } = input;\n await modules.fs.chmod(input.folder, 0o700);\n const home = modules.path.join(input.folder, \"home\");\n await modules.fs.mkdir(home, { mode: 0o700 });\n const dockerHost = options.dockerHost ?? process.env.DOCKER_HOST;\n const clientEnv = {\n PATH: input.hostPath,\n HOME: home,\n ...(dockerHost === undefined ? {} : { DOCKER_HOST: dockerHost }),\n };\n const plan = await planMounts(modules, input.policy, options);\n await checkSources(\n modules,\n plan.mounts.map((mount) => mount.from),\n dockerHost,\n );\n if (!plan.base.some((mount) => inside(modules, mount.from, input.root))) {\n throw new HarnessError(\"invalid_sandbox_options\", \"the workspace root must lie inside a read or write root\");\n }\n const mounts = [...plan.mounts];\n if (options.proxySocket !== undefined) {\n checkPaths(modules, [options.proxySocket], \"the proxy socket\");\n const stats = await modules.fs.stat(options.proxySocket).catch(() => undefined);\n if (!stats?.isSocket()) throw new HarnessError(\"invalid_sandbox_options\", \"proxySocket must be a Unix socket\");\n const from = await modules.fs.realpath(options.proxySocket);\n await checkSources(modules, [from], dockerHost);\n mounts.push({ from, to: DOCKER_PROXY_SOCKET_PATH, readOnly: false });\n }\n const user = options.user ?? `${process.getuid?.() ?? 0}:${process.getgid?.() ?? 0}`;\n const sandbox = new DockerSandbox({\n modules,\n docker: input.docker,\n image: options.image,\n root: input.root,\n files: new HostFiles(modules, input.root, plan.roots, isProtectedPath),\n mounts,\n flags: lockdownFlags(options, user),\n clientEnv,\n folder: input.folder,\n label: `harness.sandbox=harness-${modules.path.basename(input.folder).slice(\"harness-docker-\".length)}`,\n });\n await probe(sandbox, options.image);\n for (const folder of plan.roots.denyWrite) await modules.fs.mkdir(folder, { recursive: true });\n const encoder = new TextEncoder();\n for (const [path, data] of Object.entries(input.manifest.files ?? {})) {\n await sandbox.writeFile(path, typeof data === \"string\" ? encoder.encode(data) : data);\n }\n return sandbox;\n}\n\n/** Asks the daemon for its version and for the image, and throws `SandboxUnavailableError` when either fails. */\nasync function probe(sandbox: DockerSandbox, image: string): Promise<void> {\n const unavailable = (reason: string, cause?: unknown) => new SandboxUnavailableError(\"docker\", reason, { cause });\n const version = await sandbox\n .client([\"version\", \"--format\", \"{{.Server.Version}}\"], DAEMON_TIMEOUT_MS)\n .catch((error: unknown) => {\n throw unavailable(\"the docker client could not be started\", error);\n });\n if (version.exitCode !== 0) throw unavailable(`the daemon did not answer: ${firstLine(version.stderr)}`);\n const found = await sandbox\n .client([\"image\", \"inspect\", \"--format\", \"{{.Id}}\", image], DAEMON_TIMEOUT_MS)\n .catch((error: unknown) => {\n throw unavailable(\"the docker client could not be started\", error);\n });\n if (found.exitCode !== 0) {\n throw unavailable(`the image ${image} is not on the Docker host, and provision never pulls: pull it first`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sandbox/docker/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;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,MAAM,EACN,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAoB,WAAW,EAAsB,aAAa,EAAE,MAAM,eAAe,CAAC;AA+BjG,0EAA0E;AAC1E,MAAM,CAAC,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAElE,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAW,CAAC;AACtE,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACjC,mEAAmE;AACnE,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,yFAAyF;AACzF,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAClC,2HAA2H;AAC3H,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,uEAAuE;AACvE,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAM,cAAc,GA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CAAC,IAAI,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAClH,MAAM,OAAO,GAAG,MAAM,OAAO;SAC1B,MAAM,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,qBAAqB,CAAC,EAAE,iBAAiB,CAAC;SACzE,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACxB,MAAM,WAAW,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IACL,IAAI,OAAO,CAAC,QAAQ,KAAK,CAAC;QAAE,MAAM,WAAW,CAAC,8BAA8B,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACzG,MAAM,KAAK,GAAG,MAAM,OAAO;SACxB,MAAM,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,iBAAiB,CAAC;SAC7E,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACxB,MAAM,WAAW,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IACL,IAAI,KAAK,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,WAAW,CAAC,aAAa,KAAK,sEAAsE,CAAC,CAAC;IAC9G,CAAC;AACH,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/sandbox/docker`: the container-tier backend. Each command runs in its own locked-down\n * container: all capabilities dropped, a read-only root file system, no network, no new privileges, and limits on\n * processes, CPUs and memory. Only the policy's write roots are writable, and only the policy's roots are mounted. It\n * claims `mistakes` and `exfiltration`, never a `hostile_process`: the kernel is shared with the host. Only Linux and a\n * rootful daemon are tested. A backend that can't start throws `SandboxUnavailableError` and runs nothing. It is\n * Node-only.\n *\n * The container has no network, so a command reaches a host only through a proxy socket the caller mounts. The file calls\n * run in the host on the mounted folders, checked by their real path.\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 inside,\n isProtectedPath,\n PROTECTED_TOP_LEVEL,\n realOrSelf,\n spellings,\n workspaceRoot,\n} from \"../host-files.js\";\nimport { type NodeModules, nodeModules, type ProcessResult, ProcessRunner } from \"../process.js\";\nimport type { ExecOptions, ExecResult, Sandbox, SandboxClient, SandboxPolicy, WorkspaceManifest } from \"../types.js\";\n\n/** The options of `dockerSandbox()`. */\nexport interface DockerSandboxOptions {\n /** The image to run, which must already be on the Docker host: `provision()` never pulls. Pin it by digest. */\n readonly image: string;\n /** CPUs a command may use. Defaults to 1. */\n readonly cpus?: number;\n /** Megabytes of memory a command may use, with no swap. Defaults to 1024. */\n readonly memoryMb?: number;\n /** Processes a command may start. Defaults to 256. */\n readonly pidsLimit?: number;\n /** The `docker` executable. Without it the backend finds `docker` on the absolute folders of the host's `PATH`. */\n readonly binary?: string;\n /** The Docker daemon's address. Without it the backend passes the host's `DOCKER_HOST` when it is set. */\n readonly dockerHost?: string;\n /** The user and group a command runs as, as `uid:gid`. Defaults to this process's, so its files stay yours. */\n readonly user?: string;\n /** Folders to read besides the policy's roots, mounted read-only. */\n readonly extraReadRoots?: readonly string[];\n /** Folders that stay read-only inside a write root, such as the session's own log folder. */\n readonly denyWrite?: readonly string[];\n /**\n * A Unix socket on the host that a command may use to reach the hosts its policy allows, mounted at\n * `DOCKER_PROXY_SOCKET_PATH`. The proxy on it enforces the allowlist, so start `startEgressProxy()` there with the\n * policy's hosts, such as from `compileEgressPolicy()`; the read-back trusts it to.\n */\n readonly proxySocket?: string;\n}\n\n/** Where a command finds the proxy socket, when the caller mounts one. */\nexport const DOCKER_PROXY_SOCKET_PATH = \"/run/harness/proxy.sock\";\n\nconst DEFAULTS = { cpus: 1, memoryMb: 1024, pidsLimit: 256 } as const;\nconst DAEMON_TIMEOUT_MS = 20_000;\n// The longest one call that kills or removes a container may take.\nconst CALL_TIMEOUT_MS = 5000;\n// Creating a container copies the image on some storage drivers, which can take a while.\nconst CREATE_TIMEOUT_MS = 120_000;\n// How long a stopped `docker run` client has to leave on its own, which lets it cancel a container that isn't started yet.\nconst GRACE_MS = 3000;\nconst KILL_ATTEMPTS = 5;\nconst KILL_RETRY_MS = 100;\nconst SWEEP_QUIET_PASSES = 2;\n// The longest the sweep at the end waits for the last container to go.\nconst SWEEP_MAX_MS = 20_000;\nconst SWEEP_PAUSE_MS = 200;\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// A path in a `--mount` value can't hold a comma or a quote, which that syntax reads as separators.\nconst MOUNTABLE = /^[^,\"\\n\\r]+$/;\n\n/** One bind mount: the real host path, mounted at the same path inside, or at `to`. */\ninterface Mount {\n readonly from: string;\n readonly to: string;\n readonly readOnly: boolean;\n}\n\n/** Everything a provisioned sandbox holds. */\ninterface DockerState {\n readonly modules: NodeModules;\n readonly docker: string;\n readonly image: string;\n readonly root: string;\n readonly files: HostFiles;\n readonly mounts: readonly Mount[];\n readonly flags: readonly string[];\n /** The environment the `docker` client runs with: where to find its programs, and a private empty `HOME`. */\n readonly clientEnv: Readonly<Record<string, string>>;\n /** A private folder that holds the client's `HOME`, removed on dispose. */\n readonly folder: string;\n /** Marks this sandbox's containers, so `dispose()` can find any that a stopped client left behind. */\n readonly label: string;\n /** What the read-back needs to map the mounts back to the request's spelling. */\n readonly names: DockerPolicyNames;\n}\n\n/** How the mounts map back to the request, for the read-back. */\ninterface DockerPolicyNames {\n readonly requested: SandboxPolicy;\n /** The real path of each requested read root, in the request's order. */\n readonly readReal: readonly string[];\n /** For each real write root, the request's spellings that resolved to it. */\n readonly write: ReadonlyMap<string, readonly string[]>;\n /** Requested read roots that don't exist, which have nothing to mount and nothing to read. */\n readonly missing: ReadonlySet<string>;\n /** Read-only mounts the backend adds itself: the extra read roots, the denyWrite folders and the protected files. */\n readonly implicit: ReadonlySet<string>;\n}\n\nconst mountFlags = (mount: Mount): string[] => [\n \"--mount\",\n `type=bind,src=${mount.from},dst=${mount.to}${mount.readOnly ? \",readonly\" : \"\"}`,\n];\n\nclass DockerSandbox extends BackendSandbox {\n private started = 0;\n // Whether a creation was left to finish in the background, which a sweep at the end has to catch.\n private abandoned = false;\n // The containers being created, which `dispose()` waits for before it sweeps.\n private readonly pending = new Set<Promise<unknown>>();\n private readonly runner: ProcessRunner;\n // Runs the calls that manage containers, which `dispose()` must not cut short: a `create` that is stopped half way\n // leaves a container behind.\n private readonly manager: ProcessRunner;\n private readonly state: DockerState;\n\n constructor(state: DockerState) {\n super(state);\n this.state = state;\n this.runner = new ProcessRunner(state.modules);\n this.manager = new ProcessRunner(state.modules);\n }\n\n /** Runs the `docker` client with `args` and waits for it, for the calls that manage containers. */\n async client(args: readonly string[], timeoutMs: number) {\n return this.manager.run(\n {\n program: this.state.docker,\n args,\n cwd: this.state.root,\n env: this.state.clientEnv,\n missingProgram: \"reject\",\n },\n { env: {}, signal: new AbortController().signal, timeoutMs },\n );\n }\n\n /** The `docker run` arguments for one command in a container called `name`. */\n private runArguments(name: string, cwd: string, command: readonly string[], env: Readonly<Record<string, string>>) {\n const assignments: string[] = [];\n for (const [variable, value] of Object.entries(env)) {\n if (!VARIABLE_NAME.test(variable)) {\n throw new HarnessError(\"invalid_sandbox_options\", `${JSON.stringify(variable)} is not a variable name`);\n }\n assignments.push(`${variable}=${value}`);\n }\n const { state } = this;\n // `env -i` clears the image's own variables, so the command holds exactly the ones it was given.\n return [\n \"create\",\n \"--rm\",\n \"--name\",\n name,\n \"--label\",\n state.label,\n ...state.flags,\n ...state.mounts.flatMap(mountFlags),\n \"--workdir\",\n cwd,\n \"--entrypoint\",\n \"env\",\n state.image,\n \"-i\",\n // Ends `env`'s options, so a first word that starts with `-` is a program name.\n \"--\",\n ...assignments,\n ...command,\n ];\n }\n\n /** Removes the container if it exists, which is all a container that never started needs. */\n private async removeContainer(name: string): Promise<void> {\n await this.client([\"rm\", \"--force\", name], CALL_TIMEOUT_MS).catch(() => undefined);\n }\n\n /** Kills the container, trying again while the daemon is still creating it, and removes what is left. */\n private async killContainer(name: string): Promise<void> {\n for (let attempt = 0; attempt < KILL_ATTEMPTS; attempt += 1) {\n const result = await this.client([\"kill\", name], CALL_TIMEOUT_MS).catch(() => undefined);\n if (result?.exitCode === 0) break;\n await new Promise((resolve) => setTimeout(resolve, KILL_RETRY_MS));\n }\n await this.removeContainer(name);\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 located = prepared;\n const { root } = this.state;\n this.started += 1;\n const name = `${this.state.label.split(\"=\")[1]}-${this.started}`;\n const started = Date.now();\n // The container is created first and started after, so a stop never leaves a client half way through creating one.\n const created = this.client(this.runArguments(name, located.cwd, command, options.env), CREATE_TIMEOUT_MS);\n this.track(created);\n const made = await this.untilStopped(name, created, options);\n if (\"expired\" in made) return made.expired;\n if (made.exitCode !== 0) {\n await this.removeContainer(name);\n return { exitCode: made.exitCode, stdout: \"\", stderr: made.stderr };\n }\n try {\n this.live();\n options.signal.throwIfAborted();\n } catch (error) {\n await this.killContainer(name);\n throw error;\n }\n const remaining =\n options.timeoutMs === undefined ? {} : { timeoutMs: Math.max(1, options.timeoutMs - (Date.now() - started)) };\n const { stdoutBytes: _bytes, ...result } = await this.runner.run(\n {\n program: this.state.docker,\n args: [\"start\", \"--attach\", name],\n cwd: root,\n env: this.state.clientEnv,\n missingProgram: \"reject\",\n onStop: () => this.killContainer(name),\n graceMs: GRACE_MS,\n },\n { ...options, ...remaining },\n );\n return result;\n }\n\n /** Keeps `work` in the set that `dispose()` waits for, until it settles. */\n private track(work: Promise<unknown>): void {\n const tracked = work.then(\n () => undefined,\n () => undefined,\n );\n this.pending.add(tracked);\n void tracked.then(() => this.pending.delete(tracked));\n }\n\n /**\n * Waits for a container to be created, but settles the call when the caller's signal aborts or its timeout passes. The\n * creation can't be cut short without leaving a container behind, so it carries on in the background, and the container\n * is removed when it ends.\n */\n private untilStopped(\n name: string,\n created: Promise<ProcessResult>,\n options: ExecOptions,\n ): Promise<ProcessResult | { readonly expired: ExecResult }> {\n return new Promise((resolve, reject) => {\n let settled = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n const finish = (settle: () => void, discard: boolean) => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n options.signal.removeEventListener(\"abort\", onAbort);\n if (discard) {\n this.abandoned = true;\n this.track(created.then(() => this.killContainer(name)));\n }\n settle();\n };\n const onAbort = () => finish(() => reject(options.signal.reason), true);\n options.signal.addEventListener(\"abort\", onAbort, { once: true });\n if (options.timeoutMs !== undefined) {\n const note = `timed out after ${options.timeoutMs} ms\\n`;\n timer = setTimeout(\n () => finish(() => resolve({ expired: { exitCode: 124, stdout: \"\", stderr: note, timedOut: true } }), true),\n options.timeoutMs,\n );\n }\n created.then(\n (result) => finish(() => resolve(result), false),\n (error: unknown) => finish(() => reject(error), false),\n );\n });\n }\n\n /**\n * Removes every container of this sandbox until none is left. A client stopped while the daemon was creating its\n * container can leave one behind, and a removal can take a while on a slow storage driver, so it waits for the last to go.\n * With no creation left in the background, an empty first pass ends it.\n */\n private async sweep(): Promise<void> {\n const deadline = Date.now() + SWEEP_MAX_MS;\n let quiet = 0;\n for (;;) {\n const left = await this.client(\n [\"ps\", \"--all\", \"--quiet\", \"--filter\", `label=${this.state.label}`],\n DAEMON_TIMEOUT_MS,\n )\n .then((result) => result.stdout.split(\"\\n\").filter((id) => id !== \"\"))\n .catch(() => []);\n quiet = left.length === 0 ? quiet + 1 : 0;\n if (left.length > 0) await this.client([\"rm\", \"--force\", ...left], DAEMON_TIMEOUT_MS).catch(() => undefined);\n if ((left.length === 0 && (!this.abandoned || quiet >= SWEEP_QUIET_PASSES)) || Date.now() > deadline) return;\n await new Promise((resolve) => setTimeout(resolve, SWEEP_PAUSE_MS));\n }\n }\n\n /**\n * The policy the mounts and flags apply, which are what every command's container is created with. The network is\n * closed unless the caller mounted a proxy socket, and then the proxy on it enforces the requested allowlist. A\n * read-only mount the request doesn't explain reads back as a read root it didn't ask for.\n *\n * One narrowing is not caught: a write root that the caller's `denyWrite` names exactly is mounted read-only but still\n * reads back as a write root, because the read-back takes the caller's own `denyWrite` as part of the request. So\n * `provision()` accepts it, and nothing in that root is writable inside the container.\n */\n async readBack(): Promise<SandboxPolicy> {\n this.live();\n const { mounts, names, flags } = this.state;\n const own = mounts.filter((mount) => mount.to !== DOCKER_PROXY_SOCKET_PATH);\n // A write root that the caller's own denyWrite made read-only is still the root the request asked for.\n const granted = (mount: Mount) =>\n !mount.readOnly || (names.implicit.has(mount.from) && names.write.has(mount.from));\n const writable = own.filter(granted).map((mount) => mount.from);\n const inWritable = (path: string) => writable.some((root) => inside(this.state.modules, root, path));\n const readable = (real: string) => names.missing.has(real) || inWritable(real) || own.some((m) => m.from === real);\n const unexplained = own\n .filter((mount) => mount.readOnly && !names.readReal.includes(mount.from))\n .map((mount) => mount.from)\n .filter((from) => !names.implicit.has(from) && !inWritable(from));\n const closed = flags.join(\" \").includes(\"--network none\");\n const proxied = mounts.length !== own.length;\n return {\n readRoots: [\n ...names.requested.readRoots.filter((_, index) => readable(names.readReal[index] ?? \"\")),\n ...unexplained,\n ],\n writeRoots: writable.flatMap((path) => names.write.get(path) ?? [path]),\n network: !closed\n ? { allow: [\"*\"], deny: [] }\n : proxied\n ? names.requested.network\n : { allow: [], deny: names.requested.network.deny },\n };\n }\n\n protected async shutDown(): Promise<void> {\n await this.runner.stopAll();\n await Promise.allSettled([...this.pending]);\n await this.sweep();\n await this.state.modules.fs.rm(this.state.folder, { recursive: true, force: true });\n }\n}\n\n/** Throws unless `image` is a name `docker run` takes as an image and not as an option. */\nfunction checkOptionValues(options: DockerSandboxOptions): void {\n const { image, cpus, memoryMb, pidsLimit, user } = options;\n if (typeof image !== \"string\" || image === \"\" || /\\s/.test(image) || image.startsWith(\"-\")) {\n throw new HarnessError(\n \"invalid_sandbox_options\",\n \"dockerSandbox needs an image name, such as one pinned by digest\",\n );\n }\n const bad = (what: string) => new HarnessError(\"invalid_sandbox_options\", `${what} is not usable`);\n if (cpus !== undefined && !(Number.isFinite(cpus) && cpus > 0)) throw bad(\"cpus\");\n if (memoryMb !== undefined && !(Number.isInteger(memoryMb) && memoryMb >= 6)) throw bad(\"memoryMb\");\n if (pidsLimit !== undefined && !(Number.isInteger(pidsLimit) && pidsLimit >= 1)) throw bad(\"pidsLimit\");\n if (user !== undefined && !/^[0-9]+(:[0-9]+)?$/.test(user)) throw bad(\"user\");\n}\n\n/** The sockets a Docker client may use: the default ones, and the one `dockerHost` names when it is a Unix socket. */\nfunction daemonSockets(dockerHost: string | undefined): string[] {\n const named = dockerHost?.startsWith(\"unix://\") ? [dockerHost.slice(\"unix://\".length)] : [];\n return [\"/var/run/docker.sock\", \"/run/docker.sock\", ...named];\n}\n\n/** Throws unless every source is mountable, and none is `/` or holds a Docker daemon socket, which would hand over the host. */\nasync function checkSources(modules: NodeModules, sources: readonly string[], dockerHost: string | undefined) {\n for (const from of sources) {\n if (!MOUNTABLE.test(from)) {\n throw new HarnessError(\"invalid_sandbox_options\", `a mounted folder can't have a comma or quote: ${from}`);\n }\n if (from === \"/\") throw new HarnessError(\"invalid_sandbox_options\", \"a mounted folder can't resolve to /\");\n }\n for (const socket of daemonSockets(dockerHost)) {\n const real = await modules.fs.realpath(socket).catch(() => undefined);\n if (real !== undefined && sources.some((from) => inside(modules, from, real))) {\n throw new HarnessError(\"invalid_sandbox_options\", `a mounted folder would hold the Docker socket ${socket}`);\n }\n }\n}\n\n/** One mount for each destination, read-only when any of the mounts for it is. */\nfunction onePerDestination(mounts: readonly Mount[]): Mount[] {\n const byDestination = new Map<string, Mount>();\n for (const mount of mounts) {\n const earlier = byDestination.get(mount.to);\n byDestination.set(\n mount.to,\n earlier === undefined ? mount : { ...mount, readOnly: earlier.readOnly || mount.readOnly },\n );\n }\n return [...byDestination.values()];\n}\n\n/**\n * The real mounts for a policy: write roots writable, read roots and extras read-only, and read-only again on top the\n * `denyWrite` folders inside a write root (made after the checks, so a later write can't find them writable) and the\n * protected files that exist. A `denyWrite` path outside every write root is not mounted: nothing there is writable.\n */\nasync function planMounts(modules: NodeModules, policy: SandboxPolicy, options: DockerSandboxOptions) {\n const real = (paths: readonly string[]) => Promise.all(paths.map((path) => realOrSelf(modules, path)));\n const [readRoots, writeRoots, extra, denyWrite] = await Promise.all([\n real(policy.readRoots),\n real(policy.writeRoots),\n real(options.extraReadRoots ?? []),\n real(options.denyWrite ?? []),\n ]);\n for (const root of writeRoots) {\n if (!(await modules.fs.stat(root).catch(() => undefined))?.isDirectory()) {\n throw new HarnessError(\"invalid_sandbox_options\", `a write root must be an existing folder: ${root}`);\n }\n }\n const underWrite = (path: string) => writeRoots.some((root) => inside(modules, root, path));\n const denied = denyWrite.filter(underWrite);\n const protectedPaths = writeRoots.flatMap((root) => PROTECTED_TOP_LEVEL.map((name) => modules.path.join(root, name)));\n const readOnlyRoots = [...readRoots, ...extra].filter((path) => !underWrite(path));\n // One look at which read roots exist feeds both the mounts and the names, so a folder made in between can't make them\n // disagree.\n const present = await existing(modules, readOnlyRoots);\n const base: Mount[] = [\n ...writeRoots.map((from) => ({ from, to: from, readOnly: false })),\n ...present.map((from) => ({ from, to: from, readOnly: true })),\n ];\n const protectedPresent = await existing(modules, protectedPaths);\n const guarded = [...denied, ...protectedPresent].map((from) => ({ from, to: from, readOnly: true }));\n const names: DockerPolicyNames = {\n requested: policy,\n readReal: readRoots,\n write: spellings(writeRoots, policy.writeRoots),\n missing: new Set(readOnlyRoots.filter((path) => !present.includes(path))),\n implicit: new Set([...extra, ...denied, ...protectedPresent]),\n };\n return {\n base: onePerDestination(base),\n mounts: onePerDestination([...base, ...guarded]),\n roots: { read: readRoots, write: writeRoots, denyWrite: denied },\n names,\n };\n}\n\n/** The `docker run` flags that lock a container down, and limit what it may use. */\nfunction lockdownFlags(options: DockerSandboxOptions, user: string): string[] {\n const memory = `${options.memoryMb ?? DEFAULTS.memoryMb}m`;\n return [\n \"--pull\",\n \"never\",\n \"--network\",\n \"none\",\n \"--read-only\",\n \"--cap-drop\",\n \"ALL\",\n \"--security-opt\",\n \"no-new-privileges\",\n \"--ipc\",\n \"none\",\n \"--pids-limit\",\n String(options.pidsLimit ?? DEFAULTS.pidsLimit),\n \"--cpus\",\n String(options.cpus ?? DEFAULTS.cpus),\n \"--memory\",\n memory,\n \"--memory-swap\",\n memory,\n \"--user\",\n user,\n // The only writable place that isn't a mounted write root: memory-backed, so it is gone with the container.\n \"--tmpfs\",\n \"/tmp:rw,nosuid,size=64m\",\n ];\n}\n\n/** The `docker` executable, or a `SandboxUnavailableError` when there is none. */\nasync function dockerProgram(modules: NodeModules, options: DockerSandboxOptions, hostPath: string): Promise<string> {\n if (options.binary !== undefined) {\n const program = modules.path.resolve(options.binary);\n await modules.fs.access(program, modules.fs.constants.X_OK).catch((error: unknown) => {\n throw new SandboxUnavailableError(\"docker\", `${options.binary} is not an executable file`, { cause: error });\n });\n return program;\n }\n const found = await findOnPath(modules, hostPath, \"docker\");\n if (found === undefined) throw new SandboxUnavailableError(\"docker\", \"docker is not on the PATH\");\n return found;\n}\n\n/** The first line of what a client printed, for the message of a failure. */\nconst firstLine = (text: string): string => text.trim().split(\"\\n\")[0] ?? \"no output\";\n\n/**\n * Builds the Docker backend. `provision()` checks the platform, the `docker` client, the daemon and that the image is on\n * the host, so a host that can't run the container throws `SandboxUnavailableError` and runs nothing. The `docker`\n * client runs with a clean environment: a `PATH`, a private empty `HOME` and `DOCKER_HOST` when one is set, and never\n * the parent's environment. The policy's roots, `extraReadRoots`, `denyWrite` and `proxySocket` must be absolute, and\n * the workspace must lie inside a root. A command whose first word contains `=` resolves with exit code 127, as under\n * `none`. Before it returns, `provision()` reads back the policy its mounts and flags apply and throws\n * `SandboxPolicyMismatchError` on a difference. Without `proxySocket` the container reaches no host, so a policy whose\n * `network.allow` names one is refused. The backend lists no capability: it can't resume, snapshot or pause.\n */\nexport function dockerSandbox(options: DockerSandboxOptions): SandboxClient {\n checkOptionValues(options);\n const client: SandboxClient = {\n tier: \"container\",\n stops: [\"mistakes\", \"exfiltration\"],\n async provision(manifest: WorkspaceManifest, policy: SandboxPolicy): Promise<Sandbox> {\n const modules = nodeModules(\"docker\");\n if (process.platform !== \"linux\") {\n throw new SandboxUnavailableError(\n \"docker\",\n `only Linux is supported, because it is the only platform this backend is tested on, and this is ${process.platform}`,\n );\n }\n const hostPath = absolutePath(modules, process.env.PATH);\n const docker = await dockerProgram(modules, options, 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 folder = await modules.fs.mkdtemp(modules.path.join(modules.os.tmpdir(), \"harness-docker-\"));\n try {\n return await startSandbox({ modules, docker, hostPath, root, folder, manifest, policy, options, client });\n } catch (error) {\n await modules.fs.rm(folder, { recursive: true, force: true });\n throw error;\n }\n },\n };\n return client;\n}\n\ninterface StartInput {\n readonly modules: NodeModules;\n readonly docker: string;\n readonly hostPath: string;\n readonly root: string;\n readonly folder: string;\n readonly manifest: WorkspaceManifest;\n readonly policy: SandboxPolicy;\n readonly options: DockerSandboxOptions;\n readonly client: SandboxClient;\n}\n\nasync function startSandbox(input: StartInput): Promise<DockerSandbox> {\n const { modules, options } = input;\n await modules.fs.chmod(input.folder, 0o700);\n const home = modules.path.join(input.folder, \"home\");\n await modules.fs.mkdir(home, { mode: 0o700 });\n const dockerHost = options.dockerHost ?? process.env.DOCKER_HOST;\n const clientEnv = {\n PATH: input.hostPath,\n HOME: home,\n ...(dockerHost === undefined ? {} : { DOCKER_HOST: dockerHost }),\n };\n const plan = await planMounts(modules, input.policy, options);\n await checkSources(\n modules,\n plan.mounts.map((mount) => mount.from),\n dockerHost,\n );\n if (!plan.base.some((mount) => inside(modules, mount.from, input.root))) {\n throw new HarnessError(\"invalid_sandbox_options\", \"the workspace root must lie inside a read or write root\");\n }\n const mounts = [...plan.mounts];\n if (options.proxySocket !== undefined) {\n checkPaths(modules, [options.proxySocket], \"the proxy socket\");\n const stats = await modules.fs.stat(options.proxySocket).catch(() => undefined);\n if (!stats?.isSocket()) throw new HarnessError(\"invalid_sandbox_options\", \"proxySocket must be a Unix socket\");\n const from = await modules.fs.realpath(options.proxySocket);\n await checkSources(modules, [from], dockerHost);\n mounts.push({ from, to: DOCKER_PROXY_SOCKET_PATH, readOnly: false });\n }\n const user = options.user ?? `${process.getuid?.() ?? 0}:${process.getgid?.() ?? 0}`;\n const sandbox = new DockerSandbox({\n modules,\n docker: input.docker,\n image: options.image,\n root: input.root,\n files: new HostFiles(modules, input.root, plan.roots, isProtectedPath),\n mounts,\n flags: lockdownFlags(options, user),\n clientEnv,\n folder: input.folder,\n label: `harness.sandbox=harness-${modules.path.basename(input.folder).slice(\"harness-docker-\".length)}`,\n names: plan.names,\n });\n await probe(sandbox, options.image);\n await sandbox.confirm(input.client, input.policy);\n for (const folder of plan.roots.denyWrite) await modules.fs.mkdir(folder, { recursive: true });\n const encoder = new TextEncoder();\n for (const [path, data] of Object.entries(input.manifest.files ?? {})) {\n await sandbox.writeFile(path, typeof data === \"string\" ? encoder.encode(data) : data);\n }\n return sandbox;\n}\n\n/** Asks the daemon for its version and for the image, and throws `SandboxUnavailableError` when either fails. */\nasync function probe(sandbox: DockerSandbox, image: string): Promise<void> {\n const unavailable = (reason: string, cause?: unknown) => new SandboxUnavailableError(\"docker\", reason, { cause });\n const version = await sandbox\n .client([\"version\", \"--format\", \"{{.Server.Version}}\"], DAEMON_TIMEOUT_MS)\n .catch((error: unknown) => {\n throw unavailable(\"the docker client could not be started\", error);\n });\n if (version.exitCode !== 0) throw unavailable(`the daemon did not answer: ${firstLine(version.stderr)}`);\n const found = await sandbox\n .client([\"image\", \"inspect\", \"--format\", \"{{.Id}}\", image], DAEMON_TIMEOUT_MS)\n .catch((error: unknown) => {\n throw unavailable(\"the docker client could not be started\", error);\n });\n if (found.exitCode !== 0) {\n throw unavailable(`the image ${image} is not on the Docker host, and provision never pulls: pull it first`);\n }\n}\n"]}
|
package/dist/sandbox/errors.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/** The sandbox's
|
|
1
|
+
/** The sandbox's four named errors, each a `HarnessError` with its own code and its own fields. */
|
|
2
2
|
import { HarnessError } from "../errors.js";
|
|
3
|
-
import type { SandboxDenial } from "./types.js";
|
|
3
|
+
import type { SandboxCapability, SandboxDenial } from "./types.js";
|
|
4
4
|
/** Thrown by `provision()` when a backend can't start, such as a missing binary. The host must not run unconfined. */
|
|
5
5
|
export declare class SandboxUnavailableError extends HarnessError {
|
|
6
6
|
readonly name = "SandboxUnavailableError";
|
|
@@ -14,3 +14,31 @@ export declare class SandboxDeniedError extends HarnessError {
|
|
|
14
14
|
readonly denial: SandboxDenial;
|
|
15
15
|
constructor(denial: SandboxDenial);
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Thrown when the policy a backend read back from what it applied differs from the policy it was asked for, after
|
|
19
|
+
* `provision()` or a resume. After `provision()` the sandbox is disposed before the error is thrown, so nothing runs
|
|
20
|
+
* under the wrong policy; after `resumeSandbox()` it is left to the caller, who decides whether to dispose it. `field`
|
|
21
|
+
* names the first field that differs, such as `network.allow`. The message names only the field and, for `stops`, the
|
|
22
|
+
* cause, never a path or host from either policy.
|
|
23
|
+
*/
|
|
24
|
+
export declare class SandboxPolicyMismatchError extends HarnessError {
|
|
25
|
+
readonly name = "SandboxPolicyMismatchError";
|
|
26
|
+
/**
|
|
27
|
+
* What differs: `readRoots`, `writeRoots`, `network.allow` or `network.deny` for the first field that differs;
|
|
28
|
+
* `stops` when the applied policy can't deliver a stop the backend claims; `readBack` when a backend that claims a
|
|
29
|
+
* stop has no read-back or its read-back fails; and `settings` when a settings file isn't in the shape its backend
|
|
30
|
+
* writes.
|
|
31
|
+
*/
|
|
32
|
+
readonly field: string;
|
|
33
|
+
/** `options.reason` says why a claimed stop isn't delivered, and must not hold a path or host of either policy. */
|
|
34
|
+
constructor(field: string, options?: ErrorOptions & {
|
|
35
|
+
readonly reason?: string;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Thrown by `resumeSandbox()`, `snapshotSandbox()` and `pauseSandbox()` for a capability the backend doesn't list. */
|
|
39
|
+
export declare class SandboxUnsupportedError extends HarnessError {
|
|
40
|
+
readonly name = "SandboxUnsupportedError";
|
|
41
|
+
/** The capability that was asked for. */
|
|
42
|
+
readonly capability: SandboxCapability;
|
|
43
|
+
constructor(capability: SandboxCapability, tier: string);
|
|
44
|
+
}
|
package/dist/sandbox/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** The sandbox's
|
|
1
|
+
/** The sandbox's four named errors, each a `HarnessError` with its own code and its own fields. */
|
|
2
2
|
import { HarnessError } from "../errors.js";
|
|
3
3
|
/** Thrown by `provision()` when a backend can't start, such as a missing binary. The host must not run unconfined. */
|
|
4
4
|
export class SandboxUnavailableError extends HarnessError {
|
|
@@ -19,4 +19,39 @@ export class SandboxDeniedError extends HarnessError {
|
|
|
19
19
|
this.denial = denial;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Thrown when the policy a backend read back from what it applied differs from the policy it was asked for, after
|
|
24
|
+
* `provision()` or a resume. After `provision()` the sandbox is disposed before the error is thrown, so nothing runs
|
|
25
|
+
* under the wrong policy; after `resumeSandbox()` it is left to the caller, who decides whether to dispose it. `field`
|
|
26
|
+
* names the first field that differs, such as `network.allow`. The message names only the field and, for `stops`, the
|
|
27
|
+
* cause, never a path or host from either policy.
|
|
28
|
+
*/
|
|
29
|
+
export class SandboxPolicyMismatchError extends HarnessError {
|
|
30
|
+
name = "SandboxPolicyMismatchError";
|
|
31
|
+
/**
|
|
32
|
+
* What differs: `readRoots`, `writeRoots`, `network.allow` or `network.deny` for the first field that differs;
|
|
33
|
+
* `stops` when the applied policy can't deliver a stop the backend claims; `readBack` when a backend that claims a
|
|
34
|
+
* stop has no read-back or its read-back fails; and `settings` when a settings file isn't in the shape its backend
|
|
35
|
+
* writes.
|
|
36
|
+
*/
|
|
37
|
+
field;
|
|
38
|
+
/** `options.reason` says why a claimed stop isn't delivered, and must not hold a path or host of either policy. */
|
|
39
|
+
constructor(field, options) {
|
|
40
|
+
const { reason, ...rest } = options ?? {};
|
|
41
|
+
super("sandbox_policy_mismatch", reason === undefined
|
|
42
|
+
? `the sandbox applied a policy that differs from the one requested, in ${field}`
|
|
43
|
+
: `the sandbox can't deliver the ${field} its backend claims: ${reason}`, rest);
|
|
44
|
+
this.field = field;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Thrown by `resumeSandbox()`, `snapshotSandbox()` and `pauseSandbox()` for a capability the backend doesn't list. */
|
|
48
|
+
export class SandboxUnsupportedError extends HarnessError {
|
|
49
|
+
name = "SandboxUnsupportedError";
|
|
50
|
+
/** The capability that was asked for. */
|
|
51
|
+
capability;
|
|
52
|
+
constructor(capability, tier) {
|
|
53
|
+
super("sandbox_unsupported", `this ${tier}-tier sandbox backend can't ${capability}`);
|
|
54
|
+
this.capability = capability;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
22
57
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/sandbox/errors.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/sandbox/errors.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,sHAAsH;AACtH,MAAM,OAAO,uBAAwB,SAAQ,YAAY;IACrC,IAAI,GAAG,yBAAyB,CAAC;IACnD,sDAAsD;IAC7C,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B,UAAU,EAAE,CAAC,CAAC;QACtF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF","sourcesContent":["/** The sandbox's four named errors, each a `HarnessError` with its own code and its own fields. */\nimport { HarnessError } from \"../errors.js\";\nimport type { SandboxCapability, SandboxDenial } from \"./types.js\";\n\n/** Thrown by `provision()` when a backend can't start, such as a missing binary. The host must not run unconfined. */\nexport class SandboxUnavailableError extends HarnessError {\n override readonly name = \"SandboxUnavailableError\";\n /** The backend that is unavailable, such as `srt`. */\n readonly backend: string;\n\n constructor(backend: string, reason: string, options?: ErrorOptions) {\n super(\"sandbox_unavailable\", `the ${backend} sandbox is unavailable: ${reason}`, options);\n this.backend = backend;\n }\n}\n\n/** Thrown when the policy refuses a file read or write. A command's denial is an `ExecResult`, not an error. */\nexport class SandboxDeniedError extends HarnessError {\n override readonly name = \"SandboxDeniedError\";\n readonly denial: SandboxDenial;\n\n constructor(denial: SandboxDenial) {\n super(\n \"sandbox_denied\",\n `the sandbox denied a ${denial.kind.replace(\"_\", \" \")} of ${denial.target}: ${denial.reason}`,\n );\n this.denial = denial;\n }\n}\n\n/**\n * Thrown when the policy a backend read back from what it applied differs from the policy it was asked for, after\n * `provision()` or a resume. After `provision()` the sandbox is disposed before the error is thrown, so nothing runs\n * under the wrong policy; after `resumeSandbox()` it is left to the caller, who decides whether to dispose it. `field`\n * names the first field that differs, such as `network.allow`. The message names only the field and, for `stops`, the\n * cause, never a path or host from either policy.\n */\nexport class SandboxPolicyMismatchError extends HarnessError {\n override readonly name = \"SandboxPolicyMismatchError\";\n /**\n * What differs: `readRoots`, `writeRoots`, `network.allow` or `network.deny` for the first field that differs;\n * `stops` when the applied policy can't deliver a stop the backend claims; `readBack` when a backend that claims a\n * stop has no read-back or its read-back fails; and `settings` when a settings file isn't in the shape its backend\n * writes.\n */\n readonly field: string;\n\n /** `options.reason` says why a claimed stop isn't delivered, and must not hold a path or host of either policy. */\n constructor(field: string, options?: ErrorOptions & { readonly reason?: string }) {\n const { reason, ...rest } = options ?? {};\n super(\n \"sandbox_policy_mismatch\",\n reason === undefined\n ? `the sandbox applied a policy that differs from the one requested, in ${field}`\n : `the sandbox can't deliver the ${field} its backend claims: ${reason}`,\n rest,\n );\n this.field = field;\n }\n}\n\n/** Thrown by `resumeSandbox()`, `snapshotSandbox()` and `pauseSandbox()` for a capability the backend doesn't list. */\nexport class SandboxUnsupportedError extends HarnessError {\n override readonly name = \"SandboxUnsupportedError\";\n /** The capability that was asked for. */\n readonly capability: SandboxCapability;\n\n constructor(capability: SandboxCapability, tier: string) {\n super(\"sandbox_unsupported\", `this ${tier}-tier sandbox backend can't ${capability}`);\n this.capability = capability;\n }\n}\n"]}
|
|
@@ -61,3 +61,5 @@ export declare class HostFiles {
|
|
|
61
61
|
readFile(path: string): Promise<Uint8Array>;
|
|
62
62
|
writeFile(path: string, data: Uint8Array): Promise<void>;
|
|
63
63
|
}
|
|
64
|
+
/** For each real path, the spellings in the request that resolved to it, so a read-back can answer in them. */
|
|
65
|
+
export declare function spellings(real: readonly string[], requested: readonly string[]): ReadonlyMap<string, readonly string[]>;
|
|
@@ -245,4 +245,14 @@ export class HostFiles {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
+
/** For each real path, the spellings in the request that resolved to it, so a read-back can answer in them. */
|
|
249
|
+
export function spellings(real, requested) {
|
|
250
|
+
const names = new Map();
|
|
251
|
+
real.forEach((path, index) => {
|
|
252
|
+
const spelling = requested[index];
|
|
253
|
+
if (spelling !== undefined)
|
|
254
|
+
names.set(path, [...(names.get(path) ?? []), spelling]);
|
|
255
|
+
});
|
|
256
|
+
return names;
|
|
257
|
+
}
|
|
248
258
|
//# sourceMappingURL=host-files.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-files.js","sourceRoot":"","sources":["../../src/sandbox/host-files.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,cA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AAI,CAAC,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;oBACpC,MAAM,IAAI,YAAY,CAAC,mBAAmB,EAAE,YAAY,MAAM,wBAAwB,CAAC,CAAC;gBAC1F,CAAC;gBACD,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBACzB,MAAM,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;oBAAS,CAAC;gBACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACvB,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * The file calls that backends with a bind-mounted workspace share. A backend that confines commands with a kernel\n * feature still reads and writes the workspace's files from the host, and this checks every path first: by its real\n * path, so a symlink that leads out of a root is refused, and again on the opened file through `/proc`, so a path swapped\n * for a link in between is caught. A hostile process could still win that race, which is why no backend that uses this\n * claims a `hostile_process` stop. It is Node-only and Linux-only, because it reads `/proc`.\n */\nimport { HarnessError, isHarnessError } from \"../errors.js\";\nimport { SandboxDeniedError } from \"./errors.js\";\nimport type { NodeModules } from \"./process.js\";\nimport type { ExecOptions, ExecResult, SandboxDenial } from \"./types.js\";\n\n// The `PATH` a backend's tools run with when the host has none.\nexport const DEFAULT_PATH = \"/usr/local/bin:/usr/bin:/bin\";\n\n// The most bytes a file call reads or writes, because the whole file is held in memory.\nconst MAX_FILE_BYTES = 64 * 1024 * 1024;\n\n/** Whether `path` is inside `root`, or is `root`. Both are absolute, with symlinks resolved. */\nexport function inside(modules: NodeModules, root: string, path: string): boolean {\n const relative = modules.path.relative(root, path);\n const climbs = relative === \"..\" || relative.startsWith(`..${modules.path.sep}`);\n return relative === \"\" || (!climbs && !modules.path.isAbsolute(relative));\n}\n\n/** The real path of `path`, or `path` itself when it doesn't exist. */\nexport async function realOrSelf(modules: NodeModules, path: string): Promise<string> {\n return modules.fs.realpath(path).catch(() => path);\n}\n\n/**\n * The real path of `path`, which may not exist: the real path of its deepest folder that does, then the rest as written.\n * A symlink on the way is followed, so a link that points out of a root shows as outside it.\n */\nexport async function realPathOfMissing(modules: NodeModules, path: string): Promise<string> {\n const rest: string[] = [];\n let at = path;\n for (;;) {\n try {\n return modules.path.join(await modules.fs.realpath(at), ...rest);\n } catch {\n const parent = modules.path.dirname(at);\n if (parent === at) return path;\n rest.unshift(modules.path.basename(at));\n at = parent;\n }\n }\n}\n\n/** The paths that exist, without repeats. */\nexport async function existing(modules: NodeModules, paths: readonly string[]): Promise<string[]> {\n const present = await Promise.all(\n paths.map((path) =>\n modules.fs.access(path).then(\n () => path,\n () => undefined,\n ),\n ),\n );\n return [...new Set(present.filter((path): path is string => path !== undefined))];\n}\n\n/**\n * The absolute folders of `path`, or a default when there are none. A relative folder would be searched from the\n * workspace, where the agent can write, so `srt` could start a program the agent planted.\n */\nexport function absolutePath(modules: NodeModules, path: string | undefined): string {\n const folders = (path ?? \"\").split(modules.path.delimiter).filter((folder) => modules.path.isAbsolute(folder));\n return folders.length === 0 ? DEFAULT_PATH : folders.join(modules.path.delimiter);\n}\n\n/** The first folder of `hostPath` that holds an executable called `name`, or `undefined`. */\nexport async function findOnPath(modules: NodeModules, hostPath: string, name: string): Promise<string | undefined> {\n const folders = hostPath.split(modules.path.delimiter).filter((folder) => folder !== \"\");\n for (const folder of folders) {\n const candidate = modules.path.join(folder, name);\n try {\n await modules.fs.access(candidate, modules.fs.constants.X_OK);\n return candidate;\n } catch {\n // Not in this folder.\n }\n }\n return undefined;\n}\n\n/** Throws unless every path is absolute and is not `/`. */\nexport function checkPaths(modules: NodeModules, paths: readonly string[], what: string): void {\n for (const path of paths) {\n if (!modules.path.isAbsolute(path) || modules.path.resolve(path) === \"/\") {\n throw new HarnessError(\n \"invalid_sandbox_options\",\n `${what} must be an absolute path other than /, not ${JSON.stringify(path)}`,\n );\n }\n }\n}\n\n/** The workspace manifest's root as a real path, or an error when it isn't an existing absolute folder. */\nexport async function workspaceRoot(modules: NodeModules, root: string): Promise<string> {\n if (!modules.path.isAbsolute(root)) {\n throw new HarnessError(\"invalid_sandbox_options\", \"a workspace manifest's root must be an absolute path\");\n }\n const stats = await modules.fs.stat(root).catch(() => undefined);\n if (!stats?.isDirectory()) {\n throw new HarnessError(\"invalid_sandbox_options\", \"a workspace manifest's root must be an existing folder\");\n }\n return modules.fs.realpath(root);\n}\n\n/** The real roots a sandbox enforces on file calls. */\nexport interface RealRoots {\n readonly read: readonly string[];\n readonly write: readonly string[];\n readonly denyWrite: readonly string[];\n}\n\n/** The working directory as a real path inside `root`, or the denial for one outside it. */\nexport async function workingDirectory(\n modules: NodeModules,\n root: string,\n options: ExecOptions,\n): Promise<{ cwd: string } | Extract<ExecResult, { denied: SandboxDenial }>> {\n const wanted = modules.path.resolve(root, options.cwd ?? \".\");\n const cwd = await realPathOfMissing(modules, wanted);\n if (!inside(modules, root, cwd)) {\n return {\n denied: { kind: \"filesystem_read\", target: wanted, reason: \"the working directory is outside the workspace\" },\n };\n }\n const stats = await modules.fs.stat(cwd).catch(() => undefined);\n if (!stats?.isDirectory()) {\n throw new HarnessError(\"invalid_sandbox_options\", `the working directory ${cwd} is not an existing folder`);\n }\n return { cwd };\n}\n\n// What a backend that bind-mounts the workspace keeps read-only inside it, which the file calls keep read-only too: the\n// shell start-up files, the editor and agent settings, and a repository's hooks and config.\nconst PROTECTED_PATHS =\n /^(\\.bash_profile|\\.bashrc|\\.zshrc|\\.zprofile|\\.profile|\\.gitconfig|\\.gitmodules|\\.ripgreprc|\\.mcp\\.json|\\.vscode|\\.idea|\\.claude)(\\/|$)|(^|\\/)\\.git\\/(hooks|config)(\\/|$)/;\n\n/** The paths at the top of a write root that a backend can mount read-only when they exist. */\nexport const PROTECTED_TOP_LEVEL: readonly string[] = [\n \".bash_profile\",\n \".bashrc\",\n \".zshrc\",\n \".zprofile\",\n \".profile\",\n \".gitconfig\",\n \".gitmodules\",\n \".ripgreprc\",\n \".mcp.json\",\n \".vscode\",\n \".idea\",\n \".claude\",\n \".git/hooks\",\n \".git/config\",\n];\n\n/** Whether `relative`, a path under a write root with `/` between the parts, is one the file calls keep read-only. */\nexport const isProtectedPath = (relative: string): boolean => PROTECTED_PATHS.test(relative);\n\n/** Reads and writes workspace files from the host, inside the roots. */\nexport class HostFiles {\n private readonly modules: NodeModules;\n private readonly root: string;\n private readonly roots: RealRoots;\n private readonly protectedPath: ((relative: string) => boolean) | undefined;\n\n /**\n * `protectedPath` tells whether a path, relative to its write root with `/` between the parts, is one the backend\n * keeps read-only besides the `denyWrite` folders.\n */\n constructor(modules: NodeModules, root: string, roots: RealRoots, protectedPath?: (relative: string) => boolean) {\n this.modules = modules;\n this.root = root;\n this.roots = roots;\n this.protectedPath = protectedPath;\n }\n\n /** The real path of `path` against the workspace, or a denial when it is outside every one of `roots`. */\n private async contain(\n path: string,\n roots: readonly string[],\n kind: SandboxDenial[\"kind\"],\n rule: string,\n ): Promise<string> {\n const { modules } = this;\n const real = await realPathOfMissing(modules, modules.path.resolve(this.root, path));\n if (roots.some((root) => inside(modules, root, real))) return real;\n throw new SandboxDeniedError({ kind, target: path, reason: rule });\n }\n\n /** Throws a denial when `real` is a path that stays read-only: a `denyWrite` folder or one the backend protects. */\n private refuseProtected(real: string, path: string): void {\n const { modules, roots } = this;\n const inDenied = roots.denyWrite.some((folder) => inside(modules, folder, real));\n const owner = roots.write.find((root) => inside(modules, root, real));\n const relative = owner === undefined ? \"\" : modules.path.relative(owner, real).split(modules.path.sep).join(\"/\");\n if (inDenied || this.protectedPath?.(relative) === true) {\n throw new SandboxDeniedError({\n kind: \"filesystem_write\",\n target: path,\n reason: \"the path is one the sandbox keeps read-only\",\n });\n }\n }\n\n /** The real path of the file that `handle` opened, or a denial unless it is inside one of `roots`. */\n private async checkOpened(\n handle: import(\"node:fs/promises\").FileHandle,\n roots: readonly string[],\n kind: SandboxDenial[\"kind\"],\n path: string,\n ): Promise<string> {\n const { modules } = this;\n const opened = await modules.fs.realpath(`/proc/self/fd/${handle.fd}`).catch(() => undefined);\n if (opened === undefined || !roots.some((root) => inside(modules, root, opened))) {\n throw new SandboxDeniedError({ kind, target: path, reason: \"the file opened is outside the roots\" });\n }\n return opened;\n }\n\n /** The error for a file call that the OS failed: a denial when it refused, a missing file, or an I/O error. */\n private fileFailure(error: unknown, kind: SandboxDenial[\"kind\"], path: string): unknown {\n if (isHarnessError(error)) return error;\n const code = (error as NodeJS.ErrnoException).code;\n if (code === \"ENOENT\") return new HarnessError(\"sandbox_not_found\", `no such file: ${path}`, { cause: error });\n if (code === \"EACCES\" || code === \"EPERM\" || code === \"EROFS\" || code === \"ELOOP\") {\n return new SandboxDeniedError({ kind, target: path, reason: \"the OS refused it\" });\n }\n return new HarnessError(\"sandbox_io_failed\", `the file call on ${path} failed: ${code ?? String(error)}`, {\n cause: error,\n });\n }\n\n async readFile(path: string): Promise<Uint8Array> {\n const { modules, roots } = this;\n const readable = [...roots.read, ...roots.write];\n const target = await this.contain(path, readable, \"filesystem_read\", \"the path is outside the read roots\");\n const { O_RDONLY, O_NOFOLLOW, O_NONBLOCK } = modules.fs.constants;\n try {\n // Opened without blocking, so a pipe the agent made can't hold the call: only a regular file is read.\n const handle = await modules.fs.open(target, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);\n try {\n await this.checkOpened(handle, readable, \"filesystem_read\", path);\n const stats = await handle.stat();\n if (!stats.isFile()) {\n throw new HarnessError(\"sandbox_io_failed\", `the path ${target} is not a regular file`);\n }\n if (stats.size > MAX_FILE_BYTES) {\n throw new HarnessError(\"sandbox_io_failed\", `the file ${target} is larger than ${MAX_FILE_BYTES} bytes`);\n }\n const bytes = new Uint8Array(stats.size);\n const { bytesRead } = await handle.read(bytes, 0, stats.size, 0);\n return bytes.subarray(0, bytesRead);\n } finally {\n await handle.close();\n }\n } catch (error) {\n throw this.fileFailure(error, \"filesystem_read\", path);\n }\n }\n\n async writeFile(path: string, data: Uint8Array): Promise<void> {\n if (data.length > MAX_FILE_BYTES) {\n throw new HarnessError(\"sandbox_io_failed\", `a file larger than ${MAX_FILE_BYTES} bytes can't be written`);\n }\n const { modules, roots } = this;\n const rule = \"the path is outside the write roots\";\n const target = await this.contain(path, roots.write, \"filesystem_write\", rule);\n this.refuseProtected(target, path);\n const { O_WRONLY, O_CREAT, O_NOFOLLOW, O_NONBLOCK } = modules.fs.constants;\n try {\n await modules.fs.mkdir(modules.path.dirname(target), { recursive: true });\n // Opened without O_TRUNC, so a file that turns out to be outside the roots is not emptied before the check.\n const handle = await modules.fs.open(target, O_WRONLY | O_CREAT | O_NOFOLLOW | O_NONBLOCK, 0o666);\n try {\n this.refuseProtected(await this.checkOpened(handle, roots.write, \"filesystem_write\", path), path);\n if (!(await handle.stat()).isFile()) {\n throw new HarnessError(\"sandbox_io_failed\", `the path ${target} is not a regular file`);\n }\n await handle.truncate(0);\n await handle.writeFile(data);\n } finally {\n await handle.close();\n }\n } catch (error) {\n throw this.fileFailure(error, \"filesystem_write\", path);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"host-files.js","sourceRoot":"","sources":["../../src/sandbox/host-files.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAIjD,gEAAgE;AAChE,MAAM,CAAC,MAAM,YAAY,GAAG,8BAA8B,CAAC;AAE3D,wFAAwF;AACxF,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAExC,gGAAgG;AAChG,MAAM,UAAU,MAAM,CAAC,OAAoB,EAAE,IAAY,EAAE,IAAY;IACrE,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI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;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF;AAED,+GAA+G;AAC/G,MAAM,UAAU,SAAS,CACvB,IAAuB,EACvB,SAA4B;IAE5B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC1C,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,QAAQ,KAAK,SAAS;YAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;IACtF,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * The file calls that backends with a bind-mounted workspace share. A backend that confines commands with a kernel\n * feature still reads and writes the workspace's files from the host, and this checks every path first: by its real\n * path, so a symlink that leads out of a root is refused, and again on the opened file through `/proc`, so a path swapped\n * for a link in between is caught. A hostile process could still win that race, which is why no backend that uses this\n * claims a `hostile_process` stop. It is Node-only and Linux-only, because it reads `/proc`.\n */\nimport { HarnessError, isHarnessError } from \"../errors.js\";\nimport { SandboxDeniedError } from \"./errors.js\";\nimport type { NodeModules } from \"./process.js\";\nimport type { ExecOptions, ExecResult, SandboxDenial } from \"./types.js\";\n\n// The `PATH` a backend's tools run with when the host has none.\nexport const DEFAULT_PATH = \"/usr/local/bin:/usr/bin:/bin\";\n\n// The most bytes a file call reads or writes, because the whole file is held in memory.\nconst MAX_FILE_BYTES = 64 * 1024 * 1024;\n\n/** Whether `path` is inside `root`, or is `root`. Both are absolute, with symlinks resolved. */\nexport function inside(modules: NodeModules, root: string, path: string): boolean {\n const relative = modules.path.relative(root, path);\n const climbs = relative === \"..\" || relative.startsWith(`..${modules.path.sep}`);\n return relative === \"\" || (!climbs && !modules.path.isAbsolute(relative));\n}\n\n/** The real path of `path`, or `path` itself when it doesn't exist. */\nexport async function realOrSelf(modules: NodeModules, path: string): Promise<string> {\n return modules.fs.realpath(path).catch(() => path);\n}\n\n/**\n * The real path of `path`, which may not exist: the real path of its deepest folder that does, then the rest as written.\n * A symlink on the way is followed, so a link that points out of a root shows as outside it.\n */\nexport async function realPathOfMissing(modules: NodeModules, path: string): Promise<string> {\n const rest: string[] = [];\n let at = path;\n for (;;) {\n try {\n return modules.path.join(await modules.fs.realpath(at), ...rest);\n } catch {\n const parent = modules.path.dirname(at);\n if (parent === at) return path;\n rest.unshift(modules.path.basename(at));\n at = parent;\n }\n }\n}\n\n/** The paths that exist, without repeats. */\nexport async function existing(modules: NodeModules, paths: readonly string[]): Promise<string[]> {\n const present = await Promise.all(\n paths.map((path) =>\n modules.fs.access(path).then(\n () => path,\n () => undefined,\n ),\n ),\n );\n return [...new Set(present.filter((path): path is string => path !== undefined))];\n}\n\n/**\n * The absolute folders of `path`, or a default when there are none. A relative folder would be searched from the\n * workspace, where the agent can write, so `srt` could start a program the agent planted.\n */\nexport function absolutePath(modules: NodeModules, path: string | undefined): string {\n const folders = (path ?? \"\").split(modules.path.delimiter).filter((folder) => modules.path.isAbsolute(folder));\n return folders.length === 0 ? DEFAULT_PATH : folders.join(modules.path.delimiter);\n}\n\n/** The first folder of `hostPath` that holds an executable called `name`, or `undefined`. */\nexport async function findOnPath(modules: NodeModules, hostPath: string, name: string): Promise<string | undefined> {\n const folders = hostPath.split(modules.path.delimiter).filter((folder) => folder !== \"\");\n for (const folder of folders) {\n const candidate = modules.path.join(folder, name);\n try {\n await modules.fs.access(candidate, modules.fs.constants.X_OK);\n return candidate;\n } catch {\n // Not in this folder.\n }\n }\n return undefined;\n}\n\n/** Throws unless every path is absolute and is not `/`. */\nexport function checkPaths(modules: NodeModules, paths: readonly string[], what: string): void {\n for (const path of paths) {\n if (!modules.path.isAbsolute(path) || modules.path.resolve(path) === \"/\") {\n throw new HarnessError(\n \"invalid_sandbox_options\",\n `${what} must be an absolute path other than /, not ${JSON.stringify(path)}`,\n );\n }\n }\n}\n\n/** The workspace manifest's root as a real path, or an error when it isn't an existing absolute folder. */\nexport async function workspaceRoot(modules: NodeModules, root: string): Promise<string> {\n if (!modules.path.isAbsolute(root)) {\n throw new HarnessError(\"invalid_sandbox_options\", \"a workspace manifest's root must be an absolute path\");\n }\n const stats = await modules.fs.stat(root).catch(() => undefined);\n if (!stats?.isDirectory()) {\n throw new HarnessError(\"invalid_sandbox_options\", \"a workspace manifest's root must be an existing folder\");\n }\n return modules.fs.realpath(root);\n}\n\n/** The real roots a sandbox enforces on file calls. */\nexport interface RealRoots {\n readonly read: readonly string[];\n readonly write: readonly string[];\n readonly denyWrite: readonly string[];\n}\n\n/** The working directory as a real path inside `root`, or the denial for one outside it. */\nexport async function workingDirectory(\n modules: NodeModules,\n root: string,\n options: ExecOptions,\n): Promise<{ cwd: string } | Extract<ExecResult, { denied: SandboxDenial }>> {\n const wanted = modules.path.resolve(root, options.cwd ?? \".\");\n const cwd = await realPathOfMissing(modules, wanted);\n if (!inside(modules, root, cwd)) {\n return {\n denied: { kind: \"filesystem_read\", target: wanted, reason: \"the working directory is outside the workspace\" },\n };\n }\n const stats = await modules.fs.stat(cwd).catch(() => undefined);\n if (!stats?.isDirectory()) {\n throw new HarnessError(\"invalid_sandbox_options\", `the working directory ${cwd} is not an existing folder`);\n }\n return { cwd };\n}\n\n// What a backend that bind-mounts the workspace keeps read-only inside it, which the file calls keep read-only too: the\n// shell start-up files, the editor and agent settings, and a repository's hooks and config.\nconst PROTECTED_PATHS =\n /^(\\.bash_profile|\\.bashrc|\\.zshrc|\\.zprofile|\\.profile|\\.gitconfig|\\.gitmodules|\\.ripgreprc|\\.mcp\\.json|\\.vscode|\\.idea|\\.claude)(\\/|$)|(^|\\/)\\.git\\/(hooks|config)(\\/|$)/;\n\n/** The paths at the top of a write root that a backend can mount read-only when they exist. */\nexport const PROTECTED_TOP_LEVEL: readonly string[] = [\n \".bash_profile\",\n \".bashrc\",\n \".zshrc\",\n \".zprofile\",\n \".profile\",\n \".gitconfig\",\n \".gitmodules\",\n \".ripgreprc\",\n \".mcp.json\",\n \".vscode\",\n \".idea\",\n \".claude\",\n \".git/hooks\",\n \".git/config\",\n];\n\n/** Whether `relative`, a path under a write root with `/` between the parts, is one the file calls keep read-only. */\nexport const isProtectedPath = (relative: string): boolean => PROTECTED_PATHS.test(relative);\n\n/** Reads and writes workspace files from the host, inside the roots. */\nexport class HostFiles {\n private readonly modules: NodeModules;\n private readonly root: string;\n private readonly roots: RealRoots;\n private readonly protectedPath: ((relative: string) => boolean) | undefined;\n\n /**\n * `protectedPath` tells whether a path, relative to its write root with `/` between the parts, is one the backend\n * keeps read-only besides the `denyWrite` folders.\n */\n constructor(modules: NodeModules, root: string, roots: RealRoots, protectedPath?: (relative: string) => boolean) {\n this.modules = modules;\n this.root = root;\n this.roots = roots;\n this.protectedPath = protectedPath;\n }\n\n /** The real path of `path` against the workspace, or a denial when it is outside every one of `roots`. */\n private async contain(\n path: string,\n roots: readonly string[],\n kind: SandboxDenial[\"kind\"],\n rule: string,\n ): Promise<string> {\n const { modules } = this;\n const real = await realPathOfMissing(modules, modules.path.resolve(this.root, path));\n if (roots.some((root) => inside(modules, root, real))) return real;\n throw new SandboxDeniedError({ kind, target: path, reason: rule });\n }\n\n /** Throws a denial when `real` is a path that stays read-only: a `denyWrite` folder or one the backend protects. */\n private refuseProtected(real: string, path: string): void {\n const { modules, roots } = this;\n const inDenied = roots.denyWrite.some((folder) => inside(modules, folder, real));\n const owner = roots.write.find((root) => inside(modules, root, real));\n const relative = owner === undefined ? \"\" : modules.path.relative(owner, real).split(modules.path.sep).join(\"/\");\n if (inDenied || this.protectedPath?.(relative) === true) {\n throw new SandboxDeniedError({\n kind: \"filesystem_write\",\n target: path,\n reason: \"the path is one the sandbox keeps read-only\",\n });\n }\n }\n\n /** The real path of the file that `handle` opened, or a denial unless it is inside one of `roots`. */\n private async checkOpened(\n handle: import(\"node:fs/promises\").FileHandle,\n roots: readonly string[],\n kind: SandboxDenial[\"kind\"],\n path: string,\n ): Promise<string> {\n const { modules } = this;\n const opened = await modules.fs.realpath(`/proc/self/fd/${handle.fd}`).catch(() => undefined);\n if (opened === undefined || !roots.some((root) => inside(modules, root, opened))) {\n throw new SandboxDeniedError({ kind, target: path, reason: \"the file opened is outside the roots\" });\n }\n return opened;\n }\n\n /** The error for a file call that the OS failed: a denial when it refused, a missing file, or an I/O error. */\n private fileFailure(error: unknown, kind: SandboxDenial[\"kind\"], path: string): unknown {\n if (isHarnessError(error)) return error;\n const code = (error as NodeJS.ErrnoException).code;\n if (code === \"ENOENT\") return new HarnessError(\"sandbox_not_found\", `no such file: ${path}`, { cause: error });\n if (code === \"EACCES\" || code === \"EPERM\" || code === \"EROFS\" || code === \"ELOOP\") {\n return new SandboxDeniedError({ kind, target: path, reason: \"the OS refused it\" });\n }\n return new HarnessError(\"sandbox_io_failed\", `the file call on ${path} failed: ${code ?? String(error)}`, {\n cause: error,\n });\n }\n\n async readFile(path: string): Promise<Uint8Array> {\n const { modules, roots } = this;\n const readable = [...roots.read, ...roots.write];\n const target = await this.contain(path, readable, \"filesystem_read\", \"the path is outside the read roots\");\n const { O_RDONLY, O_NOFOLLOW, O_NONBLOCK } = modules.fs.constants;\n try {\n // Opened without blocking, so a pipe the agent made can't hold the call: only a regular file is read.\n const handle = await modules.fs.open(target, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);\n try {\n await this.checkOpened(handle, readable, \"filesystem_read\", path);\n const stats = await handle.stat();\n if (!stats.isFile()) {\n throw new HarnessError(\"sandbox_io_failed\", `the path ${target} is not a regular file`);\n }\n if (stats.size > MAX_FILE_BYTES) {\n throw new HarnessError(\"sandbox_io_failed\", `the file ${target} is larger than ${MAX_FILE_BYTES} bytes`);\n }\n const bytes = new Uint8Array(stats.size);\n const { bytesRead } = await handle.read(bytes, 0, stats.size, 0);\n return bytes.subarray(0, bytesRead);\n } finally {\n await handle.close();\n }\n } catch (error) {\n throw this.fileFailure(error, \"filesystem_read\", path);\n }\n }\n\n async writeFile(path: string, data: Uint8Array): Promise<void> {\n if (data.length > MAX_FILE_BYTES) {\n throw new HarnessError(\"sandbox_io_failed\", `a file larger than ${MAX_FILE_BYTES} bytes can't be written`);\n }\n const { modules, roots } = this;\n const rule = \"the path is outside the write roots\";\n const target = await this.contain(path, roots.write, \"filesystem_write\", rule);\n this.refuseProtected(target, path);\n const { O_WRONLY, O_CREAT, O_NOFOLLOW, O_NONBLOCK } = modules.fs.constants;\n try {\n await modules.fs.mkdir(modules.path.dirname(target), { recursive: true });\n // Opened without O_TRUNC, so a file that turns out to be outside the roots is not emptied before the check.\n const handle = await modules.fs.open(target, O_WRONLY | O_CREAT | O_NOFOLLOW | O_NONBLOCK, 0o666);\n try {\n this.refuseProtected(await this.checkOpened(handle, roots.write, \"filesystem_write\", path), path);\n if (!(await handle.stat()).isFile()) {\n throw new HarnessError(\"sandbox_io_failed\", `the path ${target} is not a regular file`);\n }\n await handle.truncate(0);\n await handle.writeFile(data);\n } finally {\n await handle.close();\n }\n } catch (error) {\n throw this.fileFailure(error, \"filesystem_write\", path);\n }\n }\n}\n\n/** For each real path, the spellings in the request that resolved to it, so a read-back can answer in them. */\nexport function spellings(\n real: readonly string[],\n requested: readonly string[],\n): ReadonlyMap<string, readonly string[]> {\n const names = new Map<string, string[]>();\n real.forEach((path, index) => {\n const spelling = requested[index];\n if (spelling !== undefined) names.set(path, [...(names.get(path) ?? []), spelling]);\n });\n return names;\n}\n"]}
|
package/dist/sandbox/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@buildanagent/harness/sandbox`: the sandbox interface, the unsafe `none` backend
|
|
3
|
-
* Docker backends have their own subpaths. `fakeSandbox()` and the
|
|
2
|
+
* `@buildanagent/harness/sandbox`: the sandbox interface, the unsafe `none` backend, `spawnEnv()`, and the policy
|
|
3
|
+
* read-back and capability helpers. The `srt` and Docker backends have their own subpaths. `fakeSandbox()` and the
|
|
4
|
+
* conformance suite are in `./testing`.
|
|
4
5
|
*/
|
|
5
|
-
export { SandboxDeniedError, SandboxUnavailableError } from "./errors.js";
|
|
6
|
+
export { SandboxDeniedError, SandboxPolicyMismatchError, SandboxUnavailableError, SandboxUnsupportedError, } from "./errors.js";
|
|
6
7
|
export { NONE_SANDBOX_WARNING, type NoneSandboxOptions, noneSandbox } from "./none.js";
|
|
8
|
+
export { confirmPolicy, hasCapability, pauseSandbox, policyDifference, resumeSandbox, snapshotSandbox, stopsFor, } from "./policy.js";
|
|
7
9
|
export { spawnEnv } from "./spawn-env.js";
|
|
8
|
-
export type { ApprovalPolicy, ExecOptions, ExecResult, Sandbox, SandboxClient, SandboxDenial, SandboxPolicy, SandboxStop, SandboxTier, WorkspaceManifest, } from "./types.js";
|
|
10
|
+
export type { ApprovalPolicy, ExecOptions, ExecResult, Sandbox, SandboxCapability, SandboxClient, SandboxDenial, SandboxPolicy, SandboxStop, SandboxTier, WorkspaceManifest, } from "./types.js";
|
package/dist/sandbox/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@buildanagent/harness/sandbox`: the sandbox interface, the unsafe `none` backend
|
|
3
|
-
* Docker backends have their own subpaths. `fakeSandbox()` and the
|
|
2
|
+
* `@buildanagent/harness/sandbox`: the sandbox interface, the unsafe `none` backend, `spawnEnv()`, and the policy
|
|
3
|
+
* read-back and capability helpers. The `srt` and Docker backends have their own subpaths. `fakeSandbox()` and the
|
|
4
|
+
* conformance suite are in `./testing`.
|
|
4
5
|
*/
|
|
5
|
-
export { SandboxDeniedError, SandboxUnavailableError } from "./errors.js";
|
|
6
|
+
export { SandboxDeniedError, SandboxPolicyMismatchError, SandboxUnavailableError, SandboxUnsupportedError, } from "./errors.js";
|
|
6
7
|
export { NONE_SANDBOX_WARNING, noneSandbox } from "./none.js";
|
|
8
|
+
export { confirmPolicy, hasCapability, pauseSandbox, policyDifference, resumeSandbox, snapshotSandbox, stopsFor, } from "./policy.js";
|
|
7
9
|
export { spawnEnv } from "./spawn-env.js";
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAA2B,WAAW,EAAE,MAAM,WAAW,CAAC;AACvF,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/sandbox`: the sandbox interface, the unsafe `none` backend, `spawnEnv()`, and the policy\n * read-back and capability helpers. The `srt` and Docker backends have their own subpaths. `fakeSandbox()` and the\n * conformance suite are in `./testing`.\n */\nexport {\n SandboxDeniedError,\n SandboxPolicyMismatchError,\n SandboxUnavailableError,\n SandboxUnsupportedError,\n} from \"./errors.js\";\nexport { NONE_SANDBOX_WARNING, type NoneSandboxOptions, noneSandbox } from \"./none.js\";\nexport {\n confirmPolicy,\n hasCapability,\n pauseSandbox,\n policyDifference,\n resumeSandbox,\n snapshotSandbox,\n stopsFor,\n} from \"./policy.js\";\nexport { spawnEnv } from \"./spawn-env.js\";\nexport type {\n ApprovalPolicy,\n ExecOptions,\n ExecResult,\n Sandbox,\n SandboxCapability,\n SandboxClient,\n SandboxDenial,\n SandboxPolicy,\n SandboxStop,\n SandboxTier,\n WorkspaceManifest,\n} from \"./types.js\";\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Sandbox, SandboxCapability, SandboxClient, SandboxPolicy, SandboxStop, SandboxTier } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The method by which `resumeSandbox()` sets the stops of a sandbox whose `stops` is a getter, such as a backend
|
|
4
|
+
* sandbox's, so that a later `confirm()` still updates what the getter reads. It is internal to the package.
|
|
5
|
+
*/
|
|
6
|
+
export declare const APPLY_STOPS: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* The stops a backend of `tier` delivers under `policy`. A `none` tier stops nothing. Any other tier stops `mistakes`
|
|
9
|
+
* unless a root is `/`, and `exfiltration` unless the allowlist holds an entry that opens every host (`*`, `0.0.0.0/0`
|
|
10
|
+
* or `::/0`). Only a `microvm` stops a `hostile_process`, because every other tier shares a kernel with the host or
|
|
11
|
+
* relies on one that runs in user space.
|
|
12
|
+
*/
|
|
13
|
+
export declare function stopsFor(tier: SandboxTier, policy: SandboxPolicy): SandboxStop[];
|
|
14
|
+
/**
|
|
15
|
+
* The first field in which `applied` differs from `requested`, or `undefined` when they hold the same entries. The
|
|
16
|
+
* fields are compared as sets in the order `readRoots`, `writeRoots`, `network.allow`, `network.deny`, and a field
|
|
17
|
+
* that isn't a list of strings differs. Paths and hosts compare as written, so a backend reads back in the request's
|
|
18
|
+
* spelling.
|
|
19
|
+
*/
|
|
20
|
+
export declare function policyDifference(requested: SandboxPolicy, applied: SandboxPolicy): string | undefined;
|
|
21
|
+
/** The options of `confirmPolicy()`. */
|
|
22
|
+
interface ConfirmOptions {
|
|
23
|
+
/** Whether a mismatch disposes the sandbox before it is thrown. Defaults to `true`. */
|
|
24
|
+
readonly dispose?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Reads back the policy `sandbox` applied and compares it with `requested`. It resolves with the stops the applied
|
|
28
|
+
* policy delivers, and it throws `SandboxPolicyMismatchError` when a field differs, when the client claims a stop that
|
|
29
|
+
* the applied policy doesn't deliver (`stops`, with the cause in the message), or when a client that claims a stop has
|
|
30
|
+
* no read-back or its read-back fails (`readBack`, or the read-back's own field when it threw a mismatch). A client
|
|
31
|
+
* that claims no stop needs no read-back. It disposes the sandbox before it throws, unless `options.dispose` is
|
|
32
|
+
* `false`, which leaves the sandbox to the caller.
|
|
33
|
+
*/
|
|
34
|
+
export declare function confirmPolicy(client: SandboxClient, sandbox: Sandbox, requested: SandboxPolicy, options?: ConfirmOptions): Promise<readonly SandboxStop[]>;
|
|
35
|
+
/** Whether `client` lists `capability`. A client that lists none has none. */
|
|
36
|
+
export declare function hasCapability(client: SandboxClient, capability: SandboxCapability): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Reattaches to a sandbox by its id, or starts one from a snapshot's id, then confirms its policy as `provision()`
|
|
39
|
+
* does and sets the sandbox's `stops` to what the confirmed policy delivers. It throws `SandboxUnsupportedError` when
|
|
40
|
+
* the client doesn't list `resume` or has no `resume()`, and `SandboxPolicyMismatchError` when the resumed sandbox's
|
|
41
|
+
* policy differs from `policy`. A mismatch does not dispose the sandbox, which may be a paused one worth keeping: the
|
|
42
|
+
* caller decides whether to dispose it, and must not run anything in it under the requested policy.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resumeSandbox(client: SandboxClient, id: string, policy: SandboxPolicy): Promise<Sandbox>;
|
|
45
|
+
/** Snapshots `sandbox` and resolves with the id `resumeSandbox()` takes, or throws `SandboxUnsupportedError`. */
|
|
46
|
+
export declare function snapshotSandbox(client: SandboxClient, sandbox: Sandbox): Promise<string>;
|
|
47
|
+
/** Pauses `sandbox` until `resumeSandbox()` with its `id`, or throws `SandboxUnsupportedError`. */
|
|
48
|
+
export declare function pauseSandbox(client: SandboxClient, sandbox: Sandbox): Promise<void>;
|
|
49
|
+
export {};
|