@zooid/runtime-docker 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zooid contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,26 @@
1
+ import { ChildProcess } from 'node:child_process';
2
+ import { AcpRuntime, AcpSpawnSpec } from '@zooid/core';
3
+
4
+ interface DockerAcpRuntimeOptions {
5
+ /** Default image when the spec doesn't specify one. */
6
+ defaultImage?: string;
7
+ /** docker (default) or podman. */
8
+ engine?: 'docker' | 'podman';
9
+ }
10
+ /**
11
+ * DockerAcpRuntime spawns the ACP shim inside a container.
12
+ *
13
+ * argv shape: `<engine> run --rm -i [-w cwd] [-v ...] [-e ...] --entrypoint cmd image [args...]`
14
+ *
15
+ * The image comes from the spec (preferred) or the runtime's defaultImage.
16
+ * If neither is set, spawn() throws.
17
+ */
18
+ declare class DockerAcpRuntime implements AcpRuntime {
19
+ private readonly opts;
20
+ private readonly engine;
21
+ constructor(opts?: DockerAcpRuntimeOptions);
22
+ buildArgv(spec: AcpSpawnSpec): string[];
23
+ spawn(spec: AcpSpawnSpec): ChildProcess;
24
+ }
25
+
26
+ export { DockerAcpRuntime, type DockerAcpRuntimeOptions };
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ // src/docker-acp.ts
2
+ import { spawn } from "child_process";
3
+ var DockerAcpRuntime = class {
4
+ constructor(opts = {}) {
5
+ this.opts = opts;
6
+ this.engine = opts.engine ?? "docker";
7
+ }
8
+ engine;
9
+ buildArgv(spec) {
10
+ const image = spec.image ?? this.opts.defaultImage;
11
+ if (!image) {
12
+ throw new Error(
13
+ "DockerAcpRuntime: no image set (provide DockerAcpRuntimeOptions.defaultImage or AcpSpawnSpec.image)"
14
+ );
15
+ }
16
+ const argv = ["run", "--rm", "-i"];
17
+ if (spec.cwd) {
18
+ argv.push("-w", spec.cwd);
19
+ }
20
+ for (const m of spec.mounts ?? []) {
21
+ argv.push("-v", `${m.path}:${m.target}:${m.mode}`);
22
+ }
23
+ const envEntries = Object.entries(spec.env ?? {}).sort(([a], [b]) => a.localeCompare(b));
24
+ for (const [k, v] of envEntries) {
25
+ argv.push("-e", `${k}=${v}`);
26
+ }
27
+ argv.push("--entrypoint", spec.command);
28
+ argv.push(image);
29
+ argv.push(...spec.args);
30
+ return argv;
31
+ }
32
+ spawn(spec) {
33
+ return spawn(this.engine, this.buildArgv(spec), {
34
+ stdio: ["pipe", "pipe", "pipe"]
35
+ });
36
+ }
37
+ };
38
+ export {
39
+ DockerAcpRuntime
40
+ };
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/docker-acp.ts"],"sourcesContent":["import { spawn, type ChildProcess } from 'node:child_process'\nimport type { AcpRuntime, AcpSpawnSpec } from '@zooid/core'\n\nexport interface DockerAcpRuntimeOptions {\n /** Default image when the spec doesn't specify one. */\n defaultImage?: string\n /** docker (default) or podman. */\n engine?: 'docker' | 'podman'\n}\n\n/**\n * DockerAcpRuntime spawns the ACP shim inside a container.\n *\n * argv shape: `<engine> run --rm -i [-w cwd] [-v ...] [-e ...] --entrypoint cmd image [args...]`\n *\n * The image comes from the spec (preferred) or the runtime's defaultImage.\n * If neither is set, spawn() throws.\n */\nexport class DockerAcpRuntime implements AcpRuntime {\n private readonly engine: 'docker' | 'podman'\n constructor(private readonly opts: DockerAcpRuntimeOptions = {}) {\n this.engine = opts.engine ?? 'docker'\n }\n\n buildArgv(spec: AcpSpawnSpec): string[] {\n const image = spec.image ?? this.opts.defaultImage\n if (!image) {\n throw new Error(\n 'DockerAcpRuntime: no image set (provide DockerAcpRuntimeOptions.defaultImage or AcpSpawnSpec.image)',\n )\n }\n const argv: string[] = ['run', '--rm', '-i']\n if (spec.cwd) {\n argv.push('-w', spec.cwd)\n }\n for (const m of spec.mounts ?? []) {\n argv.push('-v', `${m.path}:${m.target}:${m.mode}`)\n }\n const envEntries = Object.entries(spec.env ?? {}).sort(([a], [b]) => a.localeCompare(b))\n for (const [k, v] of envEntries) {\n argv.push('-e', `${k}=${v}`)\n }\n argv.push('--entrypoint', spec.command)\n argv.push(image)\n argv.push(...spec.args)\n return argv\n }\n\n spawn(spec: AcpSpawnSpec): ChildProcess {\n return spawn(this.engine, this.buildArgv(spec), {\n stdio: ['pipe', 'pipe', 'pipe'],\n })\n }\n}\n"],"mappings":";AAAA,SAAS,aAAgC;AAkBlC,IAAM,mBAAN,MAA6C;AAAA,EAElD,YAA6B,OAAgC,CAAC,GAAG;AAApC;AAC3B,SAAK,SAAS,KAAK,UAAU;AAAA,EAC/B;AAAA,EAHiB;AAAA,EAKjB,UAAU,MAA8B;AACtC,UAAM,QAAQ,KAAK,SAAS,KAAK,KAAK;AACtC,QAAI,CAAC,OAAO;AACV,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,UAAM,OAAiB,CAAC,OAAO,QAAQ,IAAI;AAC3C,QAAI,KAAK,KAAK;AACZ,WAAK,KAAK,MAAM,KAAK,GAAG;AAAA,IAC1B;AACA,eAAW,KAAK,KAAK,UAAU,CAAC,GAAG;AACjC,WAAK,KAAK,MAAM,GAAG,EAAE,IAAI,IAAI,EAAE,MAAM,IAAI,EAAE,IAAI,EAAE;AAAA,IACnD;AACA,UAAM,aAAa,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AACvF,eAAW,CAAC,GAAG,CAAC,KAAK,YAAY;AAC/B,WAAK,KAAK,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE;AAAA,IAC7B;AACA,SAAK,KAAK,gBAAgB,KAAK,OAAO;AACtC,SAAK,KAAK,KAAK;AACf,SAAK,KAAK,GAAG,KAAK,IAAI;AACtB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,MAAkC;AACtC,WAAO,MAAM,KAAK,QAAQ,KAAK,UAAU,IAAI,GAAG;AAAA,MAC9C,OAAO,CAAC,QAAQ,QAAQ,MAAM;AAAA,IAChC,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -0,0 +1,10 @@
1
+ FROM node:22-slim
2
+
3
+ RUN apt-get update \
4
+ && apt-get install -y --no-install-recommends git ca-certificates \
5
+ && rm -rf /var/lib/apt/lists/*
6
+
7
+ WORKDIR /workspace
8
+
9
+ # No CMD — DockerAcpRuntime always sets the entrypoint to the resolved
10
+ # ACP shim command at run time.
@@ -0,0 +1,25 @@
1
+ # agent-base
2
+
3
+ Container base image for `DockerAcpRuntime`. Contains node 22, git, and
4
+ CA certificates — nothing else. Each agent's ACP shim is invoked via
5
+ `docker run --entrypoint <shim-command>`, so the image itself does not
6
+ hard-code which CLI it hosts.
7
+
8
+ Build locally:
9
+
10
+ ```sh
11
+ docker build -t ghcr.io/zooid-ai/agent-base:local \
12
+ -f packages/runtime-docker/docker/agent-base/Dockerfile \
13
+ packages/runtime-docker/docker/agent-base
14
+ ```
15
+
16
+ Set as the runtime default in `zooid.yaml`:
17
+
18
+ ```yaml
19
+ transport: http
20
+ runtime: docker
21
+ docker:
22
+ image: ghcr.io/zooid-ai/agent-base:local
23
+ ```
24
+
25
+ Per-agent overrides are still possible via `agents.<name>.docker.image`.
@@ -0,0 +1,8 @@
1
+ FROM ghcr.io/zooid-ai/agent-base:latest
2
+
3
+ RUN npm install -g @agentclientprotocol/claude-agent-acp
4
+
5
+ # No CMD — DockerAcpRuntime sets the entrypoint to the resolved ACP shim
6
+ # command (e.g. `npx @agentclientprotocol/claude-agent-acp`). The npm install
7
+ # above pre-populates the global cache so the first turn doesn't pay the
8
+ # `npx -y` download tax.
@@ -0,0 +1,3 @@
1
+ FROM ghcr.io/zooid-ai/agent-base:latest
2
+
3
+ RUN npm install -g @zed-industries/codex-acp
@@ -0,0 +1,3 @@
1
+ FROM ghcr.io/zooid-ai/agent-base:latest
2
+
3
+ RUN npm install -g opencode-ai
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@zooid/runtime-docker",
3
+ "version": "0.7.0",
4
+ "description": "Docker runtime for zooid. Spawns the agent CLI inside a container with a workspace mount and an env allowlist.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "main": "./src/index.ts",
8
+ "types": "./src/index.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.ts",
12
+ "import": "./src/index.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "docker",
19
+ "README.md"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "engines": {
25
+ "node": ">=22"
26
+ },
27
+ "dependencies": {
28
+ "@zooid/core": "^0.7.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^22.0.0",
32
+ "tsup": "^8.5.1",
33
+ "typescript": "^5.5.0",
34
+ "vitest": "^3.2.0"
35
+ },
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "test": "vitest run",
39
+ "test:watch": "vitest",
40
+ "typecheck": "tsc --noEmit"
41
+ }
42
+ }
@@ -0,0 +1,123 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
2
+ import { EventEmitter } from 'node:events'
3
+ import { Readable, Writable } from 'node:stream'
4
+
5
+ const spawnMock = vi.fn()
6
+
7
+ vi.mock('node:child_process', () => ({
8
+ spawn: spawnMock,
9
+ }))
10
+
11
+ const { DockerAcpRuntime } = await import('./docker-acp.js')
12
+
13
+ class FakeChild extends EventEmitter {
14
+ stdout = new Readable({ read() {} })
15
+ stdin = new Writable({ write(_c, _e, cb) { cb() } })
16
+ stderr = new Readable({ read() {} })
17
+ pid = 1
18
+ kill = vi.fn(() => true)
19
+ }
20
+
21
+ function argvOf(call: number = 0): string[] {
22
+ return spawnMock.mock.calls[call][1] as string[]
23
+ }
24
+
25
+ describe('DockerAcpRuntime', () => {
26
+ beforeEach(() => {
27
+ spawnMock.mockReset()
28
+ spawnMock.mockReturnValue(new FakeChild())
29
+ })
30
+ afterEach(() => {
31
+ vi.restoreAllMocks()
32
+ })
33
+
34
+ it('uses docker run --rm -i base flags', () => {
35
+ const rt = new DockerAcpRuntime({ defaultImage: 'img:latest' })
36
+ rt.spawn({ command: 'cmd', args: [] })
37
+ expect(spawnMock.mock.calls[0][0]).toBe('docker')
38
+ const argv = argvOf()
39
+ expect(argv.slice(0, 3)).toEqual(['run', '--rm', '-i'])
40
+ })
41
+
42
+ it('engine: podman switches the binary from docker to podman', () => {
43
+ const rt = new DockerAcpRuntime({ defaultImage: 'img:latest', engine: 'podman' })
44
+ rt.spawn({ command: 'cmd', args: [] })
45
+ expect(spawnMock.mock.calls[0][0]).toBe('podman')
46
+ })
47
+
48
+ it('image: spec wins over runtime default', () => {
49
+ const rt = new DockerAcpRuntime({ defaultImage: 'default:1' })
50
+ rt.spawn({ command: 'cmd', args: [], image: 'override:2' })
51
+ const argv = argvOf()
52
+ expect(argv).toContain('override:2')
53
+ expect(argv).not.toContain('default:1')
54
+ })
55
+
56
+ it('throws if neither spec.image nor defaultImage set', () => {
57
+ const rt = new DockerAcpRuntime({})
58
+ expect(() => rt.spawn({ command: 'cmd', args: [] })).toThrow(/image/i)
59
+ })
60
+
61
+ it('emits -e KEY=value for each env entry', () => {
62
+ const rt = new DockerAcpRuntime({ defaultImage: 'img' })
63
+ rt.spawn({
64
+ command: 'cmd',
65
+ args: [],
66
+ env: { ANTHROPIC_API_KEY: 'sk', FOO: 'bar' },
67
+ })
68
+ const argv = argvOf()
69
+ expect(argv).toContain('-e')
70
+ expect(argv).toContain('ANTHROPIC_API_KEY=sk')
71
+ expect(argv).toContain('FOO=bar')
72
+ })
73
+
74
+ it('emits -v src:tgt:mode for each mount', () => {
75
+ const rt = new DockerAcpRuntime({ defaultImage: 'img' })
76
+ rt.spawn({
77
+ command: 'cmd',
78
+ args: [],
79
+ mounts: [
80
+ { path: '/host/a', target: '/c/a', mode: 'ro' },
81
+ { path: '/host/b', target: '/c/b', mode: 'rw' },
82
+ ],
83
+ })
84
+ const argv = argvOf()
85
+ expect(argv).toContain('/host/a:/c/a:ro')
86
+ expect(argv).toContain('/host/b:/c/b:rw')
87
+ })
88
+
89
+ it('emits -w <cwd> when cwd is set', () => {
90
+ const rt = new DockerAcpRuntime({ defaultImage: 'img' })
91
+ rt.spawn({ command: 'cmd', args: [], cwd: '/workspace' })
92
+ const argv = argvOf()
93
+ const wIdx = argv.indexOf('-w')
94
+ expect(wIdx).toBeGreaterThan(-1)
95
+ expect(argv[wIdx + 1]).toBe('/workspace')
96
+ })
97
+
98
+ it('args appear after the image (command is set via --entrypoint)', () => {
99
+ const rt = new DockerAcpRuntime({ defaultImage: 'img' })
100
+ rt.spawn({ command: 'opencode', args: ['acp', '--flag'] })
101
+ const argv = argvOf()
102
+ const imgIdx = argv.indexOf('img')
103
+ expect(imgIdx).toBeGreaterThan(-1)
104
+ expect(argv.slice(imgIdx + 1)).toEqual(['acp', '--flag'])
105
+ })
106
+
107
+ it('uses --entrypoint to override image entrypoint with spec command', () => {
108
+ const rt = new DockerAcpRuntime({ defaultImage: 'img' })
109
+ rt.spawn({ command: 'opencode', args: ['acp'] })
110
+ const argv = argvOf()
111
+ const epIdx = argv.indexOf('--entrypoint')
112
+ expect(epIdx).toBeGreaterThan(-1)
113
+ expect(argv[epIdx + 1]).toBe('opencode')
114
+ })
115
+
116
+ it('returns the ChildProcess from spawn', () => {
117
+ const child = new FakeChild()
118
+ spawnMock.mockReturnValue(child)
119
+ const rt = new DockerAcpRuntime({ defaultImage: 'img' })
120
+ const result = rt.spawn({ command: 'cmd', args: [] })
121
+ expect(result).toBe(child)
122
+ })
123
+ })
@@ -0,0 +1,54 @@
1
+ import { spawn, type ChildProcess } from 'node:child_process'
2
+ import type { AcpRuntime, AcpSpawnSpec } from '@zooid/core'
3
+
4
+ export interface DockerAcpRuntimeOptions {
5
+ /** Default image when the spec doesn't specify one. */
6
+ defaultImage?: string
7
+ /** docker (default) or podman. */
8
+ engine?: 'docker' | 'podman'
9
+ }
10
+
11
+ /**
12
+ * DockerAcpRuntime spawns the ACP shim inside a container.
13
+ *
14
+ * argv shape: `<engine> run --rm -i [-w cwd] [-v ...] [-e ...] --entrypoint cmd image [args...]`
15
+ *
16
+ * The image comes from the spec (preferred) or the runtime's defaultImage.
17
+ * If neither is set, spawn() throws.
18
+ */
19
+ export class DockerAcpRuntime implements AcpRuntime {
20
+ private readonly engine: 'docker' | 'podman'
21
+ constructor(private readonly opts: DockerAcpRuntimeOptions = {}) {
22
+ this.engine = opts.engine ?? 'docker'
23
+ }
24
+
25
+ buildArgv(spec: AcpSpawnSpec): string[] {
26
+ const image = spec.image ?? this.opts.defaultImage
27
+ if (!image) {
28
+ throw new Error(
29
+ 'DockerAcpRuntime: no image set (provide DockerAcpRuntimeOptions.defaultImage or AcpSpawnSpec.image)',
30
+ )
31
+ }
32
+ const argv: string[] = ['run', '--rm', '-i']
33
+ if (spec.cwd) {
34
+ argv.push('-w', spec.cwd)
35
+ }
36
+ for (const m of spec.mounts ?? []) {
37
+ argv.push('-v', `${m.path}:${m.target}:${m.mode}`)
38
+ }
39
+ const envEntries = Object.entries(spec.env ?? {}).sort(([a], [b]) => a.localeCompare(b))
40
+ for (const [k, v] of envEntries) {
41
+ argv.push('-e', `${k}=${v}`)
42
+ }
43
+ argv.push('--entrypoint', spec.command)
44
+ argv.push(image)
45
+ argv.push(...spec.args)
46
+ return argv
47
+ }
48
+
49
+ spawn(spec: AcpSpawnSpec): ChildProcess {
50
+ return spawn(this.engine, this.buildArgv(spec), {
51
+ stdio: ['pipe', 'pipe', 'pipe'],
52
+ })
53
+ }
54
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export {
2
+ DockerAcpRuntime,
3
+ type DockerAcpRuntimeOptions,
4
+ } from './docker-acp.js'