@deepagents/context 4.0.0 → 4.1.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.
Files changed (35) hide show
  1. package/README.md +19 -14
  2. package/dist/browser.js +18 -8
  3. package/dist/browser.js.map +2 -2
  4. package/dist/index.js +2115 -1565
  5. package/dist/index.js.map +4 -4
  6. package/dist/lib/agent.d.ts.map +1 -1
  7. package/dist/lib/engine.d.ts +3 -3
  8. package/dist/lib/engine.d.ts.map +1 -1
  9. package/dist/lib/fragments/message/user.d.ts +16 -14
  10. package/dist/lib/fragments/message/user.d.ts.map +1 -1
  11. package/dist/lib/sandbox/apple-container-sandbox-errors.d.ts +44 -0
  12. package/dist/lib/sandbox/apple-container-sandbox-errors.d.ts.map +1 -0
  13. package/dist/lib/sandbox/apple-container-sandbox.d.ts +122 -0
  14. package/dist/lib/sandbox/apple-container-sandbox.d.ts.map +1 -0
  15. package/dist/lib/sandbox/cli-process.d.ts +24 -0
  16. package/dist/lib/sandbox/cli-process.d.ts.map +1 -0
  17. package/dist/lib/sandbox/container-engine.d.ts +149 -0
  18. package/dist/lib/sandbox/container-engine.d.ts.map +1 -0
  19. package/dist/lib/sandbox/container-sandbox-errors.d.ts +10 -0
  20. package/dist/lib/sandbox/container-sandbox-errors.d.ts.map +1 -0
  21. package/dist/lib/sandbox/container-sandbox.d.ts +90 -0
  22. package/dist/lib/sandbox/container-sandbox.d.ts.map +1 -0
  23. package/dist/lib/sandbox/docker-sandbox-errors.d.ts +2 -2
  24. package/dist/lib/sandbox/docker-sandbox-errors.d.ts.map +1 -1
  25. package/dist/lib/sandbox/docker-sandbox.d.ts +122 -218
  26. package/dist/lib/sandbox/docker-sandbox.d.ts.map +1 -1
  27. package/dist/lib/sandbox/index.d.ts +4 -0
  28. package/dist/lib/sandbox/index.d.ts.map +1 -1
  29. package/dist/lib/sandbox/shell-quote.d.ts +2 -2
  30. package/dist/lib/sandbox/strace/index.d.ts +6 -21
  31. package/dist/lib/sandbox/strace/index.d.ts.map +1 -1
  32. package/dist/lib/sandbox/strace/index.js +18 -7
  33. package/dist/lib/sandbox/strace/index.js.map +2 -2
  34. package/dist/lib/sandbox/types.d.ts +3 -3
  35. package/package.json +4 -3
@@ -1 +1 @@
1
- {"version":3,"file":"docker-sandbox-errors.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/docker-sandbox-errors.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;CAKlD;AAED,qBAAa,uBAAwB,SAAQ,kBAAkB;;CAK9D;AAED,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAM1D;AAED,qBAAa,mBAAoB,SAAQ,kBAAkB;IACzD,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,cAAc,EAAE,KAAK,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAGtB,QAAQ,EAAE,MAAM,EAAE,EAClB,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,KAAK,GAAG,SAAS,EACjC,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM;CAavB;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,gBAAgB,GAAG,KAAK,CAAC;AAE5E,MAAM,WAAW,mBAAmB;IAClC,qFAAqF;IACrF,MAAM,EAAE,MAAM,CAAC;IACf,uDAAu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,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CASlE;AAED,qBAAa,kBAAmB,SAAQ,kBAAkB;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAM3C;AAED,qBAAa,iBAAkB,SAAQ,kBAAkB;IACvD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAM3C;AAED,qBAAa,iBAAkB,SAAQ,kBAAkB;IACvD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAM3C;AAED,qBAAa,oBAAqB,SAAQ,kBAAkB;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM;CAK3B;AAED,qBAAa,iBAAkB,SAAQ,kBAAkB;IACvD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAMhD"}
@@ -1,95 +1,140 @@
1
1
  import { type CommandResult } from 'bash-tool';
2
+ import type { CommonSandboxOptions, ContainerEngine, SandboxResources, SandboxVolume } from './container-engine.ts';
3
+ import { ContainerSandboxStrategy } from './container-sandbox.ts';
2
4
  import { type Installer } from './installers/installer.ts';
3
5
  import type { DisposableSandbox, ExecuteCommandOptions, SandboxProcess, SpawnOptions } from './types.ts';
4
6
  export type { CommandResult as ExecResult, Sandbox } from 'bash-tool';
7
+ export type { SandboxBindVolume as DockerBindVolume, SandboxNamedVolume as DockerNamedVolume, SandboxVolume as DockerSandboxVolume, } from './container-engine.ts';
5
8
  export { ComposeStartError, ContainerCreationError, DockerNotAvailableError, DockerSandboxError, DockerfileBuildError, type InstallErrorOptions, type InstallKind, InstallError, MissingRuntimeError, PackageInstallError, VolumeCreateError, VolumeInspectError, VolumePathError, VolumeRemoveError, } from './docker-sandbox-errors.ts';
6
- export interface DockerBindVolume {
7
- type: 'bind';
8
- hostPath: string;
9
- containerPath: string;
10
- /** Default: `true`. */
11
- readOnly?: boolean;
9
+ export interface DockerResources extends SandboxResources {
10
+ /**
11
+ * `--memory-swap` — total memory + swap (e.g. `'1g'`). Without it Docker
12
+ * allows swap up to 2× `memory`; set it equal to `memory` to forbid swap
13
+ * entirely. Must be ≥ `memory`.
14
+ */
15
+ memorySwap?: string;
16
+ /** `--shm-size` — size of `/dev/shm` (e.g. `'64m'`). Raise for Chromium/ML workloads. */
17
+ shmSize?: string;
18
+ /** `--pids-limit` — cap the container's process count (fork-bomb protection). */
19
+ pidsLimit?: number;
20
+ /** `--ulimit` per entry — e.g. `['nofile=1024:2048']`. */
21
+ ulimits?: string[];
22
+ /** `--cpuset-cpus` — CPUs the container may run on, e.g. `'0-1'`. */
23
+ cpusetCpus?: string;
24
+ /** `--cpu-shares` — relative CPU weight under contention. */
25
+ cpuShares?: number;
12
26
  }
13
- export interface DockerNamedVolume {
14
- type: 'volume';
15
- name: string;
16
- containerPath: string;
17
- /** Default: `true`. */
27
+ /**
28
+ * Container hardening for `docker run`. All optional — omit for the daemon's
29
+ * defaults (shared kernel, root user, writable root filesystem).
30
+ */
31
+ export interface DockerSecurity {
32
+ /**
33
+ * `--cap-drop` per entry. `['ALL']` drops every Linux capability — the
34
+ * baseline for running untrusted code; re-grant via {@link capAdd}.
35
+ */
36
+ capDrop?: string[];
37
+ /** `--cap-add` per entry. Re-grant only what's needed after dropping `ALL`. */
38
+ capAdd?: string[];
39
+ /**
40
+ * `--read-only` — mount the container root filesystem read-only. Writes then
41
+ * only land in `tmpfs`/volume mounts; pair with a writable `/workspace`
42
+ * (a {@link tmpfs} entry or volume) or the sandbox's `writeFiles` and the
43
+ * installer phase will fail.
44
+ */
18
45
  readOnly?: boolean;
19
- /** Default: `'external'`. */
20
- lifecycle?: 'external' | 'managed';
21
- /** Docker volume driver used when `lifecycle` is `'managed'`. */
22
- driver?: string;
23
- /** Docker volume driver options used when `lifecycle` is `'managed'`. */
24
- driverOptions?: Record<string, string>;
25
- subPath?: string;
26
- noCopy?: boolean;
27
- /** Default: `true` for managed volumes created by this sandbox. */
28
- removeOnDispose?: boolean;
46
+ /**
47
+ * `--user` (`uid[:gid]`) — run as a non-root user. The installer phase
48
+ * (`apk`/`apt`/`npm -g`/`pip`) needs root, so non-root suits a pre-baked
49
+ * Dockerfile image rather than the runtime-image + installers path.
50
+ */
51
+ user?: string;
52
+ /**
53
+ * `--tmpfs` per entry (e.g. `'/tmp'`, `'/workspace:size=64m'`) — ephemeral,
54
+ * in-memory writable directories. The companion to {@link readOnly}.
55
+ */
56
+ tmpfs?: string[];
57
+ /**
58
+ * `--security-opt` per entry — e.g. `['seccomp=/path/profile.json']` to apply
59
+ * a custom seccomp profile, or `['no-new-privileges']`.
60
+ */
61
+ securityOpt?: string[];
29
62
  }
30
- export type DockerSandboxVolume = DockerBindVolume | DockerNamedVolume;
31
- export interface DockerResources {
32
- /** e.g. `'1g'`, `'512m'`. */
33
- memory?: string;
34
- /** Number of CPUs. */
35
- cpus?: number;
63
+ /** Networking for `docker run`. */
64
+ export interface DockerNetwork {
65
+ /**
66
+ * `--network` — e.g. `'none'` (no network at all; strong isolation for
67
+ * untrusted code, but breaks network installers), a custom network name, or
68
+ * `'host'` (shares the host network stack — defeats isolation).
69
+ */
70
+ mode?: string;
71
+ /** `--publish` per entry — e.g. `['8080:80']` to expose a container port. */
72
+ publish?: string[];
73
+ /** `--dns` per entry — custom DNS servers. */
74
+ dns?: string[];
75
+ /** `--add-host` per entry — e.g. `['db:10.0.0.5']` host-to-IP mappings. */
76
+ addHost?: string[];
77
+ /** `--hostname` — the container hostname. */
78
+ hostname?: string;
36
79
  }
37
80
  /**
38
- * Stable identity suffix for the container. When provided, the container
39
- * is named `sandbox-<name>` instead of getting a randomized
40
- * `sandbox-<8hex>`. If a container with that name already exists on the
41
- * host, the sandbox attaches to it: installers, volume preparation, and
42
- * env are skipped (the pre-existing container is assumed already
43
- * configured). If it exists but is stopped, it is started first.
44
- * Otherwise the container is created fresh and installers run as usual.
45
- *
46
- * Must match `/^[A-Za-z0-9_.-]+$/`. The full Docker container name
47
- * (`sandbox-<name>`) is always legal because the prefix begins with an
48
- * alphanumeric character.
49
- *
50
- * Warning: `dispose()` stops (and `--rm` removes) the container regardless
51
- * of whether it was created or attached to. If two callers in the same
52
- * process share a name, the first `dispose()` destroys the container the
53
- * other one is still using.
81
+ * Run-configuration for the Docker engine. Extends the common options the shared
82
+ * skeleton reads with Docker-only `docker run` knobs that only `dockerEngine`
83
+ * sees.
54
84
  */
55
- type StableContainerName = string;
56
- export interface RuntimeSandboxOptions {
57
- /** Docker image to use (default: `'alpine:latest'`). */
58
- image?: string;
85
+ export interface DockerCommonOptions extends CommonSandboxOptions {
86
+ volumes?: SandboxVolume[];
87
+ resources?: DockerResources;
59
88
  /**
60
- * Ordered list of installers run after the container starts. Use
61
- * `pkg([...])`, `urlBinary({...})`, `npm(...)`, `pip(...)`,
62
- * `githubRelease({...})`, or any custom `Installer` subclass.
89
+ * `--platform` (e.g. `'linux/amd64'`) emulated when it differs from the host
90
+ * arch. For the Dockerfile strategy it also applies to `docker build` and is
91
+ * folded into the image-build cache key.
63
92
  */
64
- installers?: Installer[];
65
- volumes?: DockerSandboxVolume[];
66
- resources?: DockerResources;
67
- env?: Record<string, string>;
68
- name?: StableContainerName;
93
+ platform?: string;
69
94
  /**
70
- * Args appended after the image at `docker run` time.
71
- * - `undefined` (default): `['tail', '-f', '/dev/null']` keeps a bare
72
- * image (e.g. `alpine:latest`) alive so installers and `executeCommand`
73
- * have something to attach to.
74
- * - `[]` or `null`: nothing is appended; the image's own `CMD`/`ENTRYPOINT`
75
- * runs as declared (use this when your image already has a long-running
76
- * process, e.g. a daemon).
77
- * - A non-empty array: appended verbatim, overriding the image `CMD`.
95
+ * `--runtime` for `docker run` — selects the OCI runtime that backs the
96
+ * container (default: the daemon's default, usually `runc`). Set to a
97
+ * registered runtime such as `'kata-runtime'` (or `'io.containerd.kata.v2'`)
98
+ * to run the container inside a lightweight VM with its own guest kernel
99
+ * instead of sharing the host kernel. The runtime must already be installed on
100
+ * the host and registered in the Docker daemon and the host must have
101
+ * hardware virtualization (`/dev/kvm`); it is not provisioned here.
78
102
  */
79
- command?: readonly string[] | null;
103
+ runtime?: string;
104
+ /** Container hardening: capabilities, read-only rootfs, user, tmpfs, security-opt. */
105
+ security?: DockerSecurity;
106
+ /** Networking: network mode, published ports, DNS, host mappings, hostname. */
107
+ network?: DockerNetwork;
80
108
  /**
81
- * Extra `--security-opt` values for `docker run`. Each entry becomes one
82
- * `--security-opt <value>` e.g. `['seccomp=/path/profile.json']` to apply a
83
- * custom seccomp profile (denying a syscall), or `['no-new-privileges']`.
109
+ * `--gpus` e.g. `'all'`. Requires the nvidia container runtime on the host
110
+ * and is incompatible with a `runtime` such as `'kata-runtime'`.
84
111
  */
85
- securityOpt?: string[];
112
+ gpus?: string;
86
113
  /**
87
- * `--platform` for `docker run` (e.g. `'linux/amd64'`). Runs the container
88
- * under that platform emulated when it differs from the host arch.
114
+ * `--device` per entry expose a host device, e.g. `['/dev/fuse']`. Passed
115
+ * through verbatim; the library never injects a device implicitly.
89
116
  */
90
- platform?: string;
117
+ devices?: string[];
118
+ /** `--init` — run an init process as PID 1 that reaps zombie subprocesses. */
119
+ init?: boolean;
120
+ /** `--label` — container metadata, emitted as `key=value` per entry. */
121
+ labels?: Record<string, string>;
122
+ /** `--sysctl` — kernel parameters, emitted as `key=value` per entry. */
123
+ sysctls?: Record<string, string>;
124
+ /** `--entrypoint` — override the image `ENTRYPOINT`. */
125
+ entrypoint?: string;
126
+ }
127
+ export interface RuntimeSandboxOptions extends DockerCommonOptions {
128
+ /** Docker image to use (default: `'alpine:latest'`). */
129
+ image?: string;
130
+ /**
131
+ * Ordered list of installers run after the container starts. Use
132
+ * `pkg([...])`, `urlBinary({...})`, `npm(...)`, `pip(...)`,
133
+ * `githubRelease({...})`, or any custom `Installer` subclass.
134
+ */
135
+ installers?: Installer[];
91
136
  }
92
- export interface DockerfileSandboxOptions {
137
+ export interface DockerfileSandboxOptions extends DockerCommonOptions {
93
138
  /** Inline Dockerfile content (contains `\n`) or a path. */
94
139
  dockerfile: string;
95
140
  /** Build context directory (default: `'.'`). */
@@ -100,31 +145,6 @@ export interface DockerfileSandboxOptions {
100
145
  * otherwise runs silently. Default `false`.
101
146
  */
102
147
  showBuildLogs?: boolean;
103
- volumes?: DockerSandboxVolume[];
104
- resources?: DockerResources;
105
- env?: Record<string, string>;
106
- name?: StableContainerName;
107
- /**
108
- * Args appended after the image at `docker run` time.
109
- * - `undefined` (default): `['tail', '-f', '/dev/null']` — keep-alive.
110
- * - `[]` or `null`: nothing is appended; the Dockerfile's `CMD`/`ENTRYPOINT`
111
- * runs as declared. Use this when your Dockerfile already declares a
112
- * long-running process (e.g. `CMD ["node", "server.js"]`).
113
- * - A non-empty array: appended verbatim, overriding the image `CMD`.
114
- */
115
- command?: readonly string[] | null;
116
- /**
117
- * Extra `--security-opt` values for `docker run`. Each entry becomes one
118
- * `--security-opt <value>` — e.g. `['seccomp=/path/profile.json']` to apply a
119
- * custom seccomp profile (denying a syscall), or `['no-new-privileges']`.
120
- */
121
- securityOpt?: string[];
122
- /**
123
- * `--platform` for `docker build` and `docker run` (e.g. `'linux/amd64'`).
124
- * Builds and runs under that platform — emulated when it differs from the
125
- * host arch. Folded into the image-build cache key.
126
- */
127
- platform?: string;
128
148
  }
129
149
  export interface ComposeSandboxOptions {
130
150
  compose: string;
@@ -134,134 +154,18 @@ export interface ComposeSandboxOptions {
134
154
  export type DockerSandboxOptions = RuntimeSandboxOptions | DockerfileSandboxOptions | ComposeSandboxOptions;
135
155
  export declare function isDockerfileOptions(opts: DockerSandboxOptions): opts is DockerfileSandboxOptions;
136
156
  export declare function isComposeOptions(opts: DockerSandboxOptions): opts is ComposeSandboxOptions;
137
- interface StrategyContext {
138
- containerId: string;
139
- image: string;
140
- }
141
- export interface DockerSandboxStrategyArgs {
142
- volumes?: DockerSandboxVolume[];
143
- resources?: DockerResources;
144
- env?: Record<string, string>;
145
- name?: StableContainerName;
146
- /** See {@link RuntimeSandboxOptions.command}. */
147
- command?: readonly string[] | null;
148
- /** See {@link RuntimeSandboxOptions.securityOpt}. */
149
- securityOpt?: string[];
150
- /** See {@link RuntimeSandboxOptions.platform}. */
151
- platform?: string;
152
- }
153
- /**
154
- * Template Method base for sandbox creation strategies. Subclasses choose
155
- * the image and define post-start configuration; the base owns container
156
- * lifecycle, exec, and file I/O.
157
- */
158
- export declare abstract class DockerSandboxStrategy {
159
- protected context: StrategyContext;
160
- protected volumes: DockerSandboxVolume[];
161
- protected resources: DockerResources;
162
- protected env: Record<string, string>;
163
- protected name?: StableContainerName;
164
- protected command?: readonly string[] | null;
165
- protected securityOpt: string[];
166
- protected platform?: string;
167
- private createdVolumes;
168
- constructor(args?: DockerSandboxStrategyArgs);
169
- create(): Promise<DisposableSandbox>;
170
- private namedContainerId;
171
- protected defaultContainerId(): string;
172
- protected acquireContainer(image: string): Promise<{
173
- containerId: string;
174
- attached: boolean;
175
- }>;
176
- private startStoppedContainer;
177
- protected inspectContainer(containerId: string): Promise<'running' | 'stopped' | 'absent'>;
178
- private isMissingContainerError;
179
- private isNameConflictError;
180
- protected prepareVolumes(): Promise<void>;
181
- protected validateVolumes(): void;
182
- private validateMountValue;
183
- protected buildDockerArgs(image: string, containerId: string): string[];
184
- protected buildVolumeMountArg(volume: DockerSandboxVolume): string;
185
- private inspectVolume;
186
- private volumeExists;
187
- private createVolume;
188
- private cleanupCreatedVolumes;
189
- private cleanupCreatedVolumesAfterFailure;
190
- private getDockerErrorMessage;
191
- private isDockerUnavailableError;
192
- private isMissingVolumeInspectError;
193
- protected startContainer(image: string, containerId: string): Promise<void>;
194
- protected stopContainer(containerId: string): Promise<void>;
195
- protected exec(command: string, options?: ExecuteCommandOptions): Promise<CommandResult>;
196
- protected spawnProcess(command: string, options?: SpawnOptions): SandboxProcess;
197
- protected createSandboxMethods(): DisposableSandbox;
198
- protected abstract getImage(): Promise<string>;
199
- protected abstract configure(): Promise<void>;
200
- }
201
- export interface RuntimeStrategyArgs extends DockerSandboxStrategyArgs {
202
- image?: string;
203
- installers?: Installer[];
204
- }
205
- /**
206
- * Starts a vanilla image and runs the supplied installers in order.
207
- *
208
- * @example
209
- * ```ts
210
- * new RuntimeStrategy({
211
- * image: 'alpine:latest',
212
- * installers: [
213
- * pkg(['curl', 'jq']),
214
- * urlBinary({ name: 'presenterm', url: {...} }),
215
- * npm('prettier', { ensureRuntime: true }),
216
- * ],
217
- * });
218
- * ```
219
- */
220
- export declare class RuntimeStrategy extends DockerSandboxStrategy {
221
- private image;
222
- private installers;
223
- constructor(args?: RuntimeStrategyArgs);
224
- protected getImage(): Promise<string>;
225
- protected configure(): Promise<void>;
226
- }
227
- export interface DockerfileStrategyArgs extends DockerSandboxStrategyArgs {
228
- dockerfile: string;
229
- context?: string;
230
- showBuildLogs?: boolean;
231
- }
232
- /**
233
- * Builds a custom image from a Dockerfile (with content-hash caching).
234
- * Runs no post-start configuration — the Dockerfile defines the image.
235
- */
236
- export declare class DockerfileStrategy extends DockerSandboxStrategy {
237
- private imageTag;
238
- private dockerfile;
239
- private dockerContext;
240
- private showBuildLogs;
241
- constructor(args: DockerfileStrategyArgs);
242
- private computeImageTag;
243
- private isInlineDockerfile;
244
- protected getImage(): Promise<string>;
245
- protected configure(): Promise<void>;
246
- private imageExists;
247
- private buildImage;
248
- /**
249
- * Run a build command with stdio inherited so its output streams live to the
250
- * parent terminal. On failure the build error is already on screen; the
251
- * rejection just carries the exit code.
252
- */
253
- private runStreamed;
254
- }
157
+ export declare const dockerEngine: ContainerEngine<DockerCommonOptions>;
255
158
  export interface ComposeStrategyArgs {
256
159
  compose: string;
257
160
  service: string;
258
161
  resources?: DockerResources;
259
162
  }
260
163
  /**
261
- * Manages multi-container environments via `docker compose`.
262
- * Commands run inside the named service; `dispose()` brings the whole stack down.
164
+ * Manages multi-container environments via `docker compose`. Docker-only — not
165
+ * part of the engine bridge. Commands run inside the named service; `dispose()`
166
+ * brings the whole stack down.
263
167
  */
264
- export declare class ComposeStrategy extends DockerSandboxStrategy {
168
+ export declare class ComposeStrategy extends ContainerSandboxStrategy {
265
169
  private projectName;
266
170
  private composeFile;
267
171
  private service;
@@ -1 +1 @@
1
- {"version":3,"file":"docker-sandbox.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/docker-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAkB/C,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EAErB,cAAc,EACd,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,aAAa,IAAI,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;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iB,KAAK,OAAO,CAAC,CAAC,CAAC,GAC7C,OAAO,CAAC,CAAC,CAAC,CAOZ"}
@@ -1,9 +1,13 @@
1
1
  export * from './abort.ts';
2
2
  export * from './agent-os-sandbox.ts';
3
+ export * from './apple-container-sandbox.ts';
3
4
  export * from './bash-exception.ts';
4
5
  export * from './bash-meta.ts';
5
6
  export * from './bash-tool.ts';
6
7
  export * from './binary-bridges.ts';
8
+ export * from './container-engine.ts';
9
+ export * from './container-sandbox.ts';
10
+ export * from './container-sandbox-errors.ts';
7
11
  export * from './daytona-sandbox.ts';
8
12
  export * from './docker-sandbox.ts';
9
13
  export * from './strace/file-changes.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
@@ -2,8 +2,8 @@
2
2
  * POSIX shell single-quote escape: wrap in `'...'`, replace any embedded
3
3
  * `'` with `'\''`. Safe for arbitrary content inside `sh -c`.
4
4
  *
5
- * Lives in its own zero-import module so node-builtins-only consumers (e.g. the
6
- * lean `./sandbox/strace` leaf entry) can use it without dragging in the
5
+ * Lives in its own zero-import module so lean consumers such as the
6
+ * `./sandbox/strace` leaf entry can use it without dragging in the
7
7
  * installer/runtime surface.
8
8
  */
9
9
  export declare function shellQuote(s: string): string;
@@ -58,32 +58,17 @@ export declare function matchesGlobs(path: string, include: string[], exclude?:
58
58
  * treated as transient and dropped.
59
59
  */
60
60
  export declare function parseStraceTrace(raw: string, options: ParseStraceOptions): FileChange[];
61
- /**
62
- * The minimal structural surface {@link selfTestStrace} needs from its host.
63
- * Deliberately narrower than `DisposableSandbox` so the probe can run anywhere:
64
- * a remote/docker caller passes its sandbox unchanged (it satisfies this shape
65
- * structurally), and an in-process caller (e.g. a daemon running as PID 1
66
- * inside the container) implements just these two methods over
67
- * `node:child_process` + `node:fs`.
68
- */
69
- export interface StraceHost {
70
- executeCommand(command: string): Promise<{
71
- exitCode: number;
72
- stderr: string;
73
- }>;
74
- readFile(path: string): Promise<string>;
75
- }
76
61
  /**
77
62
  * One-time probe at sandbox setup. Runs a known create/write/rename sequence
78
- * under strace and asserts the trace is clean and parseable. Throws
63
+ * under strace on the host and asserts the trace is clean and parseable. Throws
79
64
  * {@link StraceUnavailableError} (hard-fail) when ptrace is blocked, strace is
80
65
  * absent, or the trace is garbled (e.g. amd64 under Rosetta).
81
66
  *
82
- * "strace works in this sandbox" is an invariant of the (image + host kernel +
83
- * seccomp/caps) — constant across every tool call and chat turn in a given
84
- * container — so this is the consumer's once-per-container responsibility (e.g.
85
- * a daemon boot gate), NOT a per-tool cost. `createBashTool` /
67
+ * "strace works here" is an invariant of the (image + host kernel + seccomp/caps)
68
+ * — constant across every tool call and chat turn in a given container — so this
69
+ * is the consumer's once-per-container responsibility (e.g. a daemon boot gate
70
+ * running as PID 1 inside the container), NOT a per-tool cost. `createBashTool` /
86
71
  * `withStraceFileChanges` no longer call it.
87
72
  */
88
- export declare function selfTestStrace(host: StraceHost): Promise<void>;
73
+ export declare function selfTestStrace(): Promise<void>;
89
74
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/strace/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEjE,MAAM,MAAM,uBAAuB,GAC/B,gBAAgB,GAChB,gBAAgB,GAChB,mBAAmB,CAAC;AAWxB;;;;;GAKG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAEjB,MAAM,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM;CAQjE;AAID;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,MAAM,CAKR;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ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1,7 @@
1
1
  // packages/context/src/lib/sandbox/strace/index.ts
2
+ import spawn from "nano-spawn";
2
3
  import { randomUUID } from "node:crypto";
4
+ import { readFile, rm } from "node:fs/promises";
3
5
  import { posix } from "node:path";
4
6
 
5
7
  // packages/context/src/lib/sandbox/shell-quote.ts
@@ -233,17 +235,24 @@ function parseStraceTrace(raw, options) {
233
235
  }
234
236
  var PTRACE_DENIED = /strace:[^\n]*(?:PTRACE_TRACEME|ptrace|Operation not permitted|EPERM)/i;
235
237
  var STRACE_MISSING = /strace:?\s+(?:command\s+)?not found/i;
236
- async function selfTestStrace(host) {
238
+ async function runOnHost(command) {
239
+ try {
240
+ const { stderr } = await spawn("sh", ["-c", command]);
241
+ return { exitCode: 0, stderr };
242
+ } catch (error) {
243
+ const e = error;
244
+ return { exitCode: e.exitCode ?? 1, stderr: e.stderr };
245
+ }
246
+ }
247
+ async function selfTestStrace() {
237
248
  const probeDir = `/tmp/dat-strace-${randomUUID()}`;
238
249
  const traceFile = `/tmp/dat-strace-${randomUUID()}.trace`;
239
250
  const q = shellQuote;
240
251
  const sequence = `mkdir -p ${q(probeDir)} && echo hi > ${q(`${probeDir}/a.txt`)} && mv ${q(`${probeDir}/a.txt`)} ${q(`${probeDir}/b.txt`)} && echo more > ${q(`${probeDir}/c.txt`)}`;
241
252
  const wrapped = buildStraceCommand(sequence, traceFile, "/tmp");
242
- let result;
243
- let raw = "";
244
253
  try {
245
- result = await host.executeCommand(wrapped);
246
- raw = await host.readFile(traceFile).catch(() => "");
254
+ const result = await runOnHost(wrapped);
255
+ const raw = await readFile(traceFile, "utf8").catch(() => "");
247
256
  const diagnostics = `exit=${result.exitCode}
248
257
  stderr=${result.stderr}
249
258
  trace[0:600]=${raw.slice(0, 600)}`;
@@ -269,8 +278,10 @@ trace[0:600]=${raw.slice(0, 600)}`;
269
278
  throw new StraceUnavailableError("trace-unparseable", diagnostics);
270
279
  }
271
280
  } finally {
272
- void host.executeCommand(`rm -rf ${q(probeDir)} ${q(traceFile)}`).catch(() => {
273
- });
281
+ await Promise.allSettled([
282
+ rm(probeDir, { recursive: true, force: true }),
283
+ rm(traceFile, { force: true })
284
+ ]);
274
285
  }
275
286
  }
276
287
  export {