@ai-hero/sandcastle 0.10.0 → 0.13.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/README.md +15 -1316
- package/dist/LinuxCapability-B_PQfsY_.d.ts +32 -0
- package/dist/{SandboxProvider-EkSMuBp8.d.ts → SandboxProvider-YCL97qco.d.ts} +30 -3
- package/dist/chunk-4EIVTSOZ.js +93 -0
- package/dist/chunk-4EIVTSOZ.js.map +1 -0
- package/dist/{chunk-NGBM7T3E.js → chunk-6NQPCXSG.js} +5 -2
- package/dist/chunk-6NQPCXSG.js.map +1 -0
- package/dist/chunk-767EAJVT.js +112 -0
- package/dist/chunk-767EAJVT.js.map +1 -0
- package/dist/chunk-7N7AMUYA.js +353 -0
- package/dist/chunk-7N7AMUYA.js.map +1 -0
- package/dist/{chunk-52CIJF45.js → chunk-A4C2FG74.js} +258 -327
- package/dist/chunk-A4C2FG74.js.map +1 -0
- package/dist/chunk-J5J5YJ5S.js +50 -0
- package/dist/chunk-J5J5YJ5S.js.map +1 -0
- package/dist/{chunk-5VM5QZ26.js → chunk-LWNC4UTZ.js} +12097 -3252
- package/dist/chunk-LWNC4UTZ.js.map +1 -0
- package/dist/chunk-NMQ5Z6YG.js +148 -0
- package/dist/chunk-NMQ5Z6YG.js.map +1 -0
- package/dist/{chunk-NSFQW6ML.js → chunk-U42XXICG.js} +92 -85
- package/dist/chunk-U42XXICG.js.map +1 -0
- package/dist/chunk-XCWKLDH4.js +24 -0
- package/dist/chunk-XCWKLDH4.js.map +1 -0
- package/dist/{chunk-BIWNFKGV.js → chunk-XCYK7I45.js} +2 -2
- package/dist/chunk-XCYK7I45.js.map +1 -0
- package/dist/index.d.ts +335 -39
- package/dist/index.js +2854 -2090
- package/dist/index.js.map +1 -1
- package/dist/main.js +1006 -627
- package/dist/main.js.map +1 -1
- package/dist/sandboxes/bwrap.d.ts +58 -0
- package/dist/sandboxes/bwrap.js +293 -0
- package/dist/sandboxes/bwrap.js.map +1 -0
- package/dist/sandboxes/daytona.d.ts +1 -1
- package/dist/sandboxes/daytona.js +78 -17
- package/dist/sandboxes/daytona.js.map +1 -1
- package/dist/sandboxes/docker.d.ts +19 -5
- package/dist/sandboxes/docker.js +4 -4
- package/dist/sandboxes/no-sandbox.d.ts +2 -2
- package/dist/sandboxes/no-sandbox.js +2 -2
- package/dist/sandboxes/podman.d.ts +19 -5
- package/dist/sandboxes/podman.js +69 -56
- package/dist/sandboxes/podman.js.map +1 -1
- package/dist/sandboxes/seatbelt.d.ts +65 -0
- package/dist/sandboxes/seatbelt.js +422 -0
- package/dist/sandboxes/seatbelt.js.map +1 -0
- package/dist/sandboxes/vercel.d.ts +13 -6
- package/dist/sandboxes/vercel.js +195 -126
- package/dist/sandboxes/vercel.js.map +1 -1
- package/dist/templates/blank/main.mts +1 -1
- package/dist/templates/parallel-planner/main.mts +14 -23
- package/dist/templates/parallel-planner-with-review/main.mts +14 -16
- package/dist/templates/simple-loop/main.mts +1 -1
- package/package.json +34 -10
- package/dist/chunk-52CIJF45.js.map +0 -1
- package/dist/chunk-5VM5QZ26.js.map +0 -1
- package/dist/chunk-72UVAC7B.js +0 -99
- package/dist/chunk-72UVAC7B.js.map +0 -1
- package/dist/chunk-BIWNFKGV.js.map +0 -1
- package/dist/chunk-NGBM7T3E.js.map +0 -1
- package/dist/chunk-NSFQW6ML.js.map +0 -1
- package/dist/mountUtils-CCA-bbpK.d.ts +0 -25
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { S as
|
|
1
|
+
import { S as SelinuxLabel, L as LinuxCapability } from '../LinuxCapability-B_PQfsY_.js';
|
|
2
|
+
export { d as defaultImageName } from '../LinuxCapability-B_PQfsY_.js';
|
|
3
|
+
import { S as SandboxProvider } from '../SandboxProvider-YCL97qco.js';
|
|
2
4
|
import { M as MountConfig } from '../MountConfig-CmXclHA5.js';
|
|
3
|
-
import { S as SelinuxLabel } from '../mountUtils-CCA-bbpK.js';
|
|
4
|
-
export { d as defaultImageName } from '../mountUtils-CCA-bbpK.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Docker sandbox provider — wraps DockerLifecycle into a SandboxProvider.
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
10
|
* import { docker } from "sandcastle/sandboxes/docker";
|
|
11
|
-
* await run({ agent: claudeCode("claude-opus-4-
|
|
11
|
+
* await run({ agent: claudeCode("claude-opus-4-8"), sandbox: docker() });
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
interface DockerOptions {
|
|
@@ -66,6 +66,20 @@ interface DockerOptions {
|
|
|
66
66
|
* When omitted, no `--group-add` flags are added.
|
|
67
67
|
*/
|
|
68
68
|
readonly groups?: readonly (string | number)[];
|
|
69
|
+
/**
|
|
70
|
+
* Linux capabilities to drop from the container, via `--cap-drop`.
|
|
71
|
+
*
|
|
72
|
+
* Names are written without the `CAP_` prefix, as `docker run` accepts them,
|
|
73
|
+
* and a misspelt name is a type error:
|
|
74
|
+
*
|
|
75
|
+
* - `["NET_RAW"]` → `--cap-drop NET_RAW` (no raw sockets, so no `ping`)
|
|
76
|
+
* - `["NET_RAW", "MKNOD"]` → `--cap-drop NET_RAW --cap-drop MKNOD`
|
|
77
|
+
* - `["ALL"]` → `--cap-drop ALL` (drop every capability)
|
|
78
|
+
*
|
|
79
|
+
* When omitted, no `--cap-drop` flags are added and the container keeps
|
|
80
|
+
* Docker's default capability set.
|
|
81
|
+
*/
|
|
82
|
+
readonly capDrop?: readonly LinuxCapability[];
|
|
69
83
|
/**
|
|
70
84
|
* Host devices to expose to the container, via `--device`.
|
|
71
85
|
*
|
|
@@ -107,4 +121,4 @@ interface DockerOptions {
|
|
|
107
121
|
*/
|
|
108
122
|
declare const docker: (options?: DockerOptions) => SandboxProvider;
|
|
109
123
|
|
|
110
|
-
export { type DockerOptions, docker };
|
|
124
|
+
export { type DockerOptions, LinuxCapability, docker };
|
package/dist/sandboxes/docker.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
export { docker } from '../chunk-
|
|
3
|
-
export { defaultImageName } from '../chunk-
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
2
|
+
export { docker } from '../chunk-U42XXICG.js';
|
|
3
|
+
export { defaultImageName } from '../chunk-LWNC4UTZ.js';
|
|
4
|
+
import '../chunk-XCYK7I45.js';
|
|
5
|
+
import '../chunk-6NQPCXSG.js';
|
|
6
6
|
|
|
7
7
|
createRequire(import.meta.url);
|
|
8
8
|
//# sourceMappingURL=docker.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { N as NoSandboxProvider } from '../SandboxProvider-
|
|
1
|
+
import { N as NoSandboxProvider } from '../SandboxProvider-YCL97qco.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* No-sandbox provider — runs the agent directly on the host with no container isolation.
|
|
5
5
|
*
|
|
6
6
|
* Usage:
|
|
7
7
|
* import { noSandbox } from "sandcastle/sandboxes/no-sandbox";
|
|
8
|
-
* await interactive({ agent: claudeCode("claude-opus-4-
|
|
8
|
+
* await interactive({ agent: claudeCode("claude-opus-4-8"), sandbox: noSandbox() });
|
|
9
9
|
*
|
|
10
10
|
* Accepted by `run()`, `interactive()`, and `createSandbox()`. Skips
|
|
11
11
|
* container isolation entirely — the agent executes on the host. Does not
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
export { noSandbox } from '../chunk-
|
|
3
|
-
import '../chunk-
|
|
2
|
+
export { noSandbox } from '../chunk-7N7AMUYA.js';
|
|
3
|
+
import '../chunk-6NQPCXSG.js';
|
|
4
4
|
|
|
5
5
|
createRequire(import.meta.url);
|
|
6
6
|
//# sourceMappingURL=no-sandbox.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { S as SandboxProvider } from '../SandboxProvider-
|
|
1
|
+
import { S as SandboxProvider } from '../SandboxProvider-YCL97qco.js';
|
|
2
2
|
import { M as MountConfig } from '../MountConfig-CmXclHA5.js';
|
|
3
|
-
import { S as SelinuxLabel } from '../
|
|
4
|
-
export { d as defaultImageName } from '../
|
|
3
|
+
import { S as SelinuxLabel, L as LinuxCapability } from '../LinuxCapability-B_PQfsY_.js';
|
|
4
|
+
export { d as defaultImageName } from '../LinuxCapability-B_PQfsY_.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Podman sandbox provider — creates Podman containers with bind-mounts.
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
10
|
* import { podman } from "sandcastle/sandboxes/podman";
|
|
11
|
-
* await run({ agent: claudeCode("claude-opus-4-
|
|
11
|
+
* await run({ agent: claudeCode("claude-opus-4-8"), sandbox: podman() });
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
interface PodmanOptions {
|
|
@@ -76,6 +76,20 @@ interface PodmanOptions {
|
|
|
76
76
|
* When omitted, no `--group-add` flags are added.
|
|
77
77
|
*/
|
|
78
78
|
readonly groups?: readonly (string | number)[];
|
|
79
|
+
/**
|
|
80
|
+
* Linux capabilities to drop from the container, via `--cap-drop`.
|
|
81
|
+
*
|
|
82
|
+
* Names are written without the `CAP_` prefix, as `podman run` accepts them,
|
|
83
|
+
* and a misspelt name is a type error:
|
|
84
|
+
*
|
|
85
|
+
* - `["NET_RAW"]` → `--cap-drop NET_RAW` (no raw sockets, so no `ping`)
|
|
86
|
+
* - `["NET_RAW", "MKNOD"]` → `--cap-drop NET_RAW --cap-drop MKNOD`
|
|
87
|
+
* - `["ALL"]` → `--cap-drop ALL` (drop every capability)
|
|
88
|
+
*
|
|
89
|
+
* When omitted, no `--cap-drop` flags are added and the container keeps
|
|
90
|
+
* Podman's default capability set.
|
|
91
|
+
*/
|
|
92
|
+
readonly capDrop?: readonly LinuxCapability[];
|
|
79
93
|
/**
|
|
80
94
|
* Host devices to expose to the container, via `--device`.
|
|
81
95
|
*
|
|
@@ -121,4 +135,4 @@ interface PodmanOptions {
|
|
|
121
135
|
*/
|
|
122
136
|
declare const podman: (options?: PodmanOptions) => SandboxProvider;
|
|
123
137
|
|
|
124
|
-
export { type PodmanOptions, podman };
|
|
138
|
+
export { LinuxCapability, type PodmanOptions, podman };
|
package/dist/sandboxes/podman.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { resolveUserMounts, processFileMountParents, formatVolumeMount, defaultImageName, registerShutdown } from '../chunk-
|
|
3
|
-
export { defaultImageName } from '../chunk-
|
|
4
|
-
import { createBindMountSandboxProvider } from '../chunk-
|
|
5
|
-
import { MAX_TAIL_CHARS, BoundedTail } from '../chunk-
|
|
2
|
+
import { resolveUserMounts, processFileMountParents, formatVolumeMount, defaultImageName, registerShutdown } from '../chunk-LWNC4UTZ.js';
|
|
3
|
+
export { defaultImageName } from '../chunk-LWNC4UTZ.js';
|
|
4
|
+
import { createBindMountSandboxProvider } from '../chunk-XCYK7I45.js';
|
|
5
|
+
import { MAX_TAIL_CHARS, BoundedTail } from '../chunk-6NQPCXSG.js';
|
|
6
6
|
import { execFile, execFileSync, spawn } from 'child_process';
|
|
7
7
|
import { randomUUID } from 'crypto';
|
|
8
8
|
import { createInterface } from 'readline';
|
|
@@ -45,19 +45,24 @@ var podman = (options) => {
|
|
|
45
45
|
`${key}=${value}`
|
|
46
46
|
]);
|
|
47
47
|
const volumeArgs = volumeMounts.flatMap((v) => ["-v", v]);
|
|
48
|
-
const usernsArgs = userns ? [`--userns=keep-id:uid=${containerUid},gid=${containerGid}`]
|
|
48
|
+
const usernsArgs = userns === false ? [] : [`--userns=keep-id:uid=${containerUid},gid=${containerGid}`];
|
|
49
49
|
const userArgs = ["--user", `${containerUid}:${containerGid}`];
|
|
50
|
-
const
|
|
50
|
+
const network = options?.network;
|
|
51
|
+
const networks = network === void 0 || network === "" ? [] : [network].flat();
|
|
51
52
|
const networkArgs = networks.flatMap((n) => ["--network", n]);
|
|
52
53
|
const groupArgs = (options?.groups ?? []).flatMap((g) => [
|
|
53
54
|
"--group-add",
|
|
54
55
|
String(g)
|
|
55
56
|
]);
|
|
57
|
+
const capDropArgs = (options?.capDrop ?? []).flatMap((cap) => [
|
|
58
|
+
"--cap-drop",
|
|
59
|
+
cap
|
|
60
|
+
]);
|
|
56
61
|
const deviceArgs = (options?.devices ?? []).flatMap((d) => [
|
|
57
62
|
"--device",
|
|
58
63
|
d
|
|
59
64
|
]);
|
|
60
|
-
const cpusArgs = options?.cpus
|
|
65
|
+
const cpusArgs = options?.cpus === void 0 ? [] : ["--cpus", String(options.cpus)];
|
|
61
66
|
await new Promise((resolve, reject) => {
|
|
62
67
|
execFile(
|
|
63
68
|
"podman",
|
|
@@ -70,6 +75,7 @@ var podman = (options) => {
|
|
|
70
75
|
...usernsArgs,
|
|
71
76
|
...networkArgs,
|
|
72
77
|
...groupArgs,
|
|
78
|
+
...capDropArgs,
|
|
73
79
|
...deviceArgs,
|
|
74
80
|
...cpusArgs,
|
|
75
81
|
"-w",
|
|
@@ -122,7 +128,7 @@ var podman = (options) => {
|
|
|
122
128
|
}
|
|
123
129
|
const removeContainerSync = () => {
|
|
124
130
|
try {
|
|
125
|
-
execFileSync("podman", ["rm", "-f", containerName], {
|
|
131
|
+
execFileSync("podman", ["rm", "-f", "--time", "0", containerName], {
|
|
126
132
|
stdio: "ignore",
|
|
127
133
|
timeout: 5e3
|
|
128
134
|
});
|
|
@@ -132,29 +138,31 @@ var podman = (options) => {
|
|
|
132
138
|
const unregisterShutdown = registerShutdown(removeContainerSync);
|
|
133
139
|
const handle = {
|
|
134
140
|
worktreePath,
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
sandboxId: containerName,
|
|
142
|
+
exec: async (command, opts) => {
|
|
137
143
|
const args = ["exec"];
|
|
138
|
-
if (opts?.
|
|
139
|
-
|
|
140
|
-
|
|
144
|
+
if (opts?.sudo === true) {
|
|
145
|
+
args.push("--user", "0:0");
|
|
146
|
+
}
|
|
147
|
+
if (opts?.stdin !== void 0) {
|
|
148
|
+
args.push("-i");
|
|
149
|
+
}
|
|
150
|
+
if (opts?.cwd !== void 0 && opts.cwd !== "") {
|
|
151
|
+
args.push("-w", opts.cwd);
|
|
152
|
+
}
|
|
153
|
+
args.push(containerName, "sh", "-c", command);
|
|
141
154
|
return new Promise((resolve, reject) => {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
]
|
|
148
|
-
});
|
|
149
|
-
if (opts?.stdin !== void 0) {
|
|
150
|
-
proc.stdin.write(opts.stdin);
|
|
151
|
-
proc.stdin.end();
|
|
155
|
+
const stdin = opts?.stdin;
|
|
156
|
+
const proc = stdin === void 0 ? spawn("podman", args, { stdio: ["ignore", "pipe", "pipe"] }) : spawn("podman", args, { stdio: ["pipe", "pipe", "pipe"] });
|
|
157
|
+
if (stdin !== void 0) {
|
|
158
|
+
proc.stdin?.write(stdin);
|
|
159
|
+
proc.stdin?.end();
|
|
152
160
|
}
|
|
153
161
|
proc.on("error", (error) => {
|
|
154
162
|
reject(new Error(`podman exec failed: ${error.message}`));
|
|
155
163
|
});
|
|
156
164
|
if (opts?.onLine) {
|
|
157
|
-
const onLine = opts
|
|
165
|
+
const { onLine } = opts;
|
|
158
166
|
const stdoutTail = new BoundedTail(maxOutputTailChars, "\n");
|
|
159
167
|
const stderrTail = new BoundedTail(maxOutputTailChars, "");
|
|
160
168
|
const rl = createInterface({ input: proc.stdout });
|
|
@@ -191,28 +199,28 @@ var podman = (options) => {
|
|
|
191
199
|
}
|
|
192
200
|
});
|
|
193
201
|
},
|
|
194
|
-
interactiveExec: (args, opts) => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
proc.on("error", (error) => {
|
|
208
|
-
reject(new Error(`podman exec failed: ${error.message}`));
|
|
209
|
-
});
|
|
210
|
-
proc.on("close", (code) => {
|
|
211
|
-
resolve({ exitCode: code ?? 0 });
|
|
212
|
-
});
|
|
202
|
+
interactiveExec: async (args, opts) => new Promise((resolve, reject) => {
|
|
203
|
+
const podmanArgs = ["exec"];
|
|
204
|
+
if ("isTTY" in opts.stdin && opts.stdin.isTTY === true) {
|
|
205
|
+
podmanArgs.push("-it");
|
|
206
|
+
} else {
|
|
207
|
+
podmanArgs.push("-i");
|
|
208
|
+
}
|
|
209
|
+
if (opts.cwd !== void 0 && opts.cwd !== "") {
|
|
210
|
+
podmanArgs.push("-w", opts.cwd);
|
|
211
|
+
}
|
|
212
|
+
podmanArgs.push(containerName, ...args);
|
|
213
|
+
const proc = spawn("podman", podmanArgs, {
|
|
214
|
+
stdio: [opts.stdin, opts.stdout, opts.stderr]
|
|
213
215
|
});
|
|
214
|
-
|
|
215
|
-
|
|
216
|
+
proc.on("error", (error) => {
|
|
217
|
+
reject(new Error(`podman exec failed: ${error.message}`));
|
|
218
|
+
});
|
|
219
|
+
proc.on("close", (code) => {
|
|
220
|
+
resolve({ exitCode: code ?? 0 });
|
|
221
|
+
});
|
|
222
|
+
}),
|
|
223
|
+
copyFileIn: async (hostPath, sandboxPath) => new Promise((resolve, reject) => {
|
|
216
224
|
execFile(
|
|
217
225
|
"podman",
|
|
218
226
|
["cp", hostPath, `${containerName}:${sandboxPath}`],
|
|
@@ -225,7 +233,7 @@ var podman = (options) => {
|
|
|
225
233
|
}
|
|
226
234
|
);
|
|
227
235
|
}),
|
|
228
|
-
copyFileOut: (sandboxPath, hostPath) => new Promise((resolve, reject) => {
|
|
236
|
+
copyFileOut: async (sandboxPath, hostPath) => new Promise((resolve, reject) => {
|
|
229
237
|
execFile(
|
|
230
238
|
"podman",
|
|
231
239
|
["cp", `${containerName}:${sandboxPath}`, hostPath],
|
|
@@ -241,13 +249,17 @@ var podman = (options) => {
|
|
|
241
249
|
close: async () => {
|
|
242
250
|
unregisterShutdown();
|
|
243
251
|
await new Promise((resolve, reject) => {
|
|
244
|
-
execFile(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
252
|
+
execFile(
|
|
253
|
+
"podman",
|
|
254
|
+
["rm", "-f", "--time", "0", containerName],
|
|
255
|
+
(error) => {
|
|
256
|
+
if (error) {
|
|
257
|
+
reject(new Error(`podman rm failed: ${error.message}`));
|
|
258
|
+
} else {
|
|
259
|
+
resolve();
|
|
260
|
+
}
|
|
249
261
|
}
|
|
250
|
-
|
|
262
|
+
);
|
|
251
263
|
});
|
|
252
264
|
}
|
|
253
265
|
};
|
|
@@ -255,7 +267,7 @@ var podman = (options) => {
|
|
|
255
267
|
}
|
|
256
268
|
});
|
|
257
269
|
};
|
|
258
|
-
var checkImageExists = (imageName) => new Promise((resolve, reject) => {
|
|
270
|
+
var checkImageExists = async (imageName) => new Promise((resolve, reject) => {
|
|
259
271
|
execFile("podman", ["image", "inspect", imageName], (error) => {
|
|
260
272
|
if (error) {
|
|
261
273
|
reject(
|
|
@@ -271,7 +283,7 @@ var checkImageExists = (imageName) => new Promise((resolve, reject) => {
|
|
|
271
283
|
var podmanMachineError = () => new Error(
|
|
272
284
|
"Podman Machine is not running. Run 'podman machine init && podman machine start' first."
|
|
273
285
|
);
|
|
274
|
-
var checkPodmanMachine = () => new Promise((resolve, reject) => {
|
|
286
|
+
var checkPodmanMachine = async () => new Promise((resolve, reject) => {
|
|
275
287
|
execFile(
|
|
276
288
|
"podman",
|
|
277
289
|
["machine", "list", "--format", "json"],
|
|
@@ -281,8 +293,8 @@ var checkPodmanMachine = () => new Promise((resolve, reject) => {
|
|
|
281
293
|
return;
|
|
282
294
|
}
|
|
283
295
|
try {
|
|
284
|
-
const machines = JSON.parse(stdout
|
|
285
|
-
if (machines.some((m) => m
|
|
296
|
+
const machines = JSON.parse(stdout);
|
|
297
|
+
if (Array.isArray(machines) && machines.some((m) => isRunningMachine(m))) {
|
|
286
298
|
resolve();
|
|
287
299
|
} else {
|
|
288
300
|
reject(podmanMachineError());
|
|
@@ -293,6 +305,7 @@ var checkPodmanMachine = () => new Promise((resolve, reject) => {
|
|
|
293
305
|
}
|
|
294
306
|
);
|
|
295
307
|
});
|
|
308
|
+
var isRunningMachine = (machine) => typeof machine === "object" && machine !== null && "Running" in machine && machine.Running === true;
|
|
296
309
|
|
|
297
310
|
export { podman };
|
|
298
311
|
//# sourceMappingURL=podman.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sandboxes/podman.ts"],"names":[],"mappings":";;;;;;;;;;AAgJO,IAAM,MAAA,GAAS,CAAC,OAAA,KAA6C;AAClE,EAAA,MAAM,sBAAsB,OAAA,EAAS,SAAA;AACrC,EAAA,MAAM,YAAA,GAAe,SAAS,YAAA,IAAgB,GAAA;AAC9C,EAAA,MAAM,MAAA,GAAS,SAAS,MAAA,IAAU,SAAA;AAClC,EAAA,MAAM,YAAA,GAAe,SAAS,YAAA,IAAgB,GAAA;AAC9C,EAAA,MAAM,YAAA,GAAe,SAAS,YAAA,IAAgB,GAAA;AAC9C,EAAA,MAAM,kBAAA,GAAqB,SAAS,kBAAA,IAAsB,cAAA;AAC1D,EAAA,MAAM,cAAA,GAAiB,aAAA;AACvB,EAAA,MAAM,UAAA,GAAa,SAAS,MAAA,GACxB,iBAAA,CAAkB,QAAQ,MAAA,EAAQ,cAAc,IAChD,EAAC;AAGL,EAAA,MAAM,kBAAA,GAAqB,uBAAA;AAAA,IACzB,UAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,OAAO,8BAAA,CAA+B;AAAA,IACpC,IAAA,EAAM,QAAA;AAAA,IACN,KAAK,OAAA,EAAS,GAAA;AAAA,IACd,cAAA;AAAA,IACA,MAAA,EAAQ,OACN,aAAA,KACoC;AACpC,MAAA,MAAM,aAAA,GAAgB,CAAA,WAAA,EAAc,UAAA,EAAY,CAAA,CAAA;AAEhD,MAAA,MAAM,YAAA,GACJ,cAAc,MAAA,CAAO,IA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AI;AACF,QAAA,MAAM,QAAA,GAAW,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,UAAU,CAAA;AAG7C,QAAA,IAAI,SAAS,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,OAAO,CAAA,EAAG;AACnC,UAAA,OAAA,EAAQ;AAAA,QACV,CAAA,MAAO;AACL,UAAA,MAAA,CAAO,oBAAoB,CAAA;AAAA,QAC7B;AAAA,MACF,CAAA,CAAA,MAAQ;AACN,QAAA,MAAA,CAAO,oBAAoB,CAAA;AAAA,MAC7B;AAAA,IACF;AAAA,GACF;AACF,CAAC,CAAA","file":"podman.js","sourcesContent":["/**\n * Podman sandbox provider — creates Podman containers with bind-mounts.\n *\n * Usage:\n * import { podman } from \"sandcastle/sandboxes/podman\";\n * await run({ agent: claudeCode(\"claude-opus-4-7\"), sandbox: podman() });\n */\n\nimport {\n execFile,\n execFileSync,\n spawn,\n type StdioOptions,\n} from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { createInterface } from \"node:readline\";\nimport {\n createBindMountSandboxProvider,\n type SandboxProvider,\n type BindMountCreateOptions,\n type BindMountSandboxHandle,\n type ExecResult,\n type InteractiveExecOptions,\n} from \"../SandboxProvider.js\";\nimport type { MountConfig } from \"../MountConfig.js\";\nimport type { SelinuxLabel } from \"../mountUtils.js\";\nimport {\n defaultImageName,\n resolveUserMounts,\n formatVolumeMount,\n processFileMountParents,\n} from \"../mountUtils.js\";\nimport { BoundedTail, MAX_TAIL_CHARS } from \"../boundedTail.js\";\nimport { registerShutdown } from \"../shutdownRegistry.js\";\n\nexport interface PodmanOptions {\n /** Podman image name (default: derived from repo directory name). */\n readonly imageName?: string;\n /**\n * SELinux volume label suffix applied to bind mounts.\n *\n * - `\"z\"` — shared label (default). No-op on non-SELinux systems.\n * - `\"Z\"` — private label; only this container can access the mount.\n * - `false` — disable labeling entirely.\n */\n readonly selinuxLabel?: SelinuxLabel;\n /**\n * User namespace mode for rootless Podman.\n *\n * - `\"keep-id\"` (default) — maps host UID to `containerUid` inside the\n * container via `--userns=keep-id:uid=N,gid=N`, so both bind-mounted\n * files and image-built files have correct ownership without chown.\n * - `false` — disable; use for rootful Podman setups.\n */\n readonly userns?: \"keep-id\" | false;\n /**\n * The UID of the `agent` user inside the container image (default: 1000).\n *\n * Must match the UID set in the Containerfile. Used with `--userns=keep-id`\n * to map the host user to this UID inside the container.\n */\n readonly containerUid?: number;\n /**\n * The GID of the `agent` user inside the container image (default: 1000).\n *\n * Must match the GID set in the Containerfile. Used with `--userns=keep-id`\n * to map the host group to this GID inside the container.\n */\n readonly containerGid?: number;\n /**\n * Additional host directories to bind-mount into the sandbox.\n *\n * Each entry specifies a `hostPath` (tilde-expanded) and `sandboxPath`.\n * If `hostPath` does not exist, sandbox creation fails with a clear error.\n */\n readonly mounts?: readonly MountConfig[];\n /** Environment variables injected by this provider. Merged at launch time with env resolver and agent provider env. */\n readonly env?: Record<string, string>;\n /**\n * Podman network(s) to attach the container to.\n *\n * - `\"my-network\"` → `--network my-network`\n * - `[\"net1\", \"net2\"]` → `--network net1 --network net2`\n *\n * When omitted, Podman's default network is used.\n */\n readonly network?: string | readonly string[];\n /**\n * Supplementary groups to add the container user to, via `--group-add`.\n *\n * Accepts group names or numeric GIDs:\n *\n * - `[\"docker\"]` → `--group-add docker`\n * - `[999]` → `--group-add 999`\n * - `[\"docker\", 999]` → `--group-add docker --group-add 999`\n *\n * Useful for granting access to a bind-mounted Docker socket (Docker-outside-of-Docker).\n * When omitted, no `--group-add` flags are added.\n */\n readonly groups?: readonly (string | number)[];\n /**\n * Host devices to expose to the container, via `--device`.\n *\n * Each entry is a full device spec in `host[:container[:permissions]]` form:\n *\n * - `[\"/dev/kvm\"]` → `--device /dev/kvm`\n * - `[\"/dev/sda:/dev/xvda:rwm\"]` → `--device /dev/sda:/dev/xvda:rwm`\n * - `[\"/dev/kvm\", \"/dev/fuse\"]` → `--device /dev/kvm --device /dev/fuse`\n *\n * Under rootless Podman, exposing a host device often requires host-side\n * group/permission setup and may interact with `--userns=keep-id`.\n * When omitted, no `--device` flags are added.\n */\n readonly devices?: readonly string[];\n /**\n * Maximum number of characters of streamed `exec` output retained per stream\n * (stdout and stderr) when an `onLine` callback is supplied (default: 64KiB).\n *\n * Output is delivered live to `onLine` regardless; this only bounds the tail\n * returned in `ExecResult`, preventing a long-running agent's output from\n * overflowing V8's max string length and crashing the run.\n */\n readonly maxOutputTailChars?: number;\n /**\n * Limit the CPU resources available to the container, via `--cpus`.\n *\n * Maps directly to `podman run --cpus`. Accepts fractional values:\n *\n * - `2` → `--cpus 2` (at most 2 CPUs)\n * - `1.5` → `--cpus 1.5` (at most 1.5 CPUs)\n *\n * When omitted, no `--cpus` flag is added and the container is unconstrained.\n */\n readonly cpus?: number;\n}\n\n/**\n * Create a Podman sandbox provider.\n *\n * The returned provider creates Podman containers with bind-mounts\n * for the worktree and git directories. Calls the `podman` binary\n * on PATH directly. On macOS/Windows, verifies that a Podman Machine\n * is running before container creation.\n */\nexport const podman = (options?: PodmanOptions): SandboxProvider => {\n const configuredImageName = options?.imageName;\n const selinuxLabel = options?.selinuxLabel ?? \"z\";\n const userns = options?.userns ?? \"keep-id\";\n const containerUid = options?.containerUid ?? 1000;\n const containerGid = options?.containerGid ?? 1000;\n const maxOutputTailChars = options?.maxOutputTailChars ?? MAX_TAIL_CHARS;\n const sandboxHomedir = \"/home/agent\";\n const userMounts = options?.mounts\n ? resolveUserMounts(options.mounts, sandboxHomedir)\n : [];\n // Validate file mounts and collect parent dirs to create at container start.\n // Throws at construction time if any file mount parent is outside sandboxHomedir.\n const parentDirsToCreate = processFileMountParents(\n userMounts,\n sandboxHomedir,\n );\n\n return createBindMountSandboxProvider({\n name: \"podman\",\n env: options?.env,\n sandboxHomedir,\n create: async (\n createOptions: BindMountCreateOptions,\n ): Promise<BindMountSandboxHandle> => {\n const containerName = `sandcastle-${randomUUID()}`;\n\n const worktreePath =\n createOptions.mounts.find(\n (m) => m.hostPath === createOptions.worktreePath,\n )?.sandboxPath ?? \"/home/agent/workspace\";\n\n // Build volume mount strings with optional SELinux label (internal + user mounts)\n const allMounts = [...createOptions.mounts, ...userMounts];\n const volumeMounts = allMounts.map((m) =>\n formatVolumeMount(m, selinuxLabel),\n );\n\n // Resolve image name\n const imageName =\n configuredImageName ?? defaultImageName(createOptions.hostRepoPath);\n\n // Pre-flight: check Podman Machine on macOS/Windows\n if (process.platform === \"darwin\" || process.platform === \"win32\") {\n await checkPodmanMachine();\n }\n\n // Pre-flight: verify image exists locally\n await checkImageExists(imageName);\n\n const env = { ...createOptions.env, HOME: \"/home/agent\" };\n const envArgs = Object.entries(env).flatMap(([key, value]) => [\n \"-e\",\n `${key}=${value}`,\n ]);\n const volumeArgs = volumeMounts.flatMap((v) => [\"-v\", v]);\n const usernsArgs = userns\n ? [`--userns=keep-id:uid=${containerUid},gid=${containerGid}`]\n : [];\n const userArgs = [\"--user\", `${containerUid}:${containerGid}`];\n const networks = options?.network\n ? Array.isArray(options.network)\n ? options.network\n : [options.network]\n : [];\n const networkArgs = networks.flatMap((n) => [\"--network\", n]);\n const groupArgs = (options?.groups ?? []).flatMap((g) => [\n \"--group-add\",\n String(g),\n ]);\n const deviceArgs = (options?.devices ?? []).flatMap((d) => [\n \"--device\",\n d,\n ]);\n const cpusArgs =\n options?.cpus !== undefined ? [\"--cpus\", String(options.cpus)] : [];\n\n // Start container via podman run\n await new Promise<void>((resolve, reject) => {\n execFile(\n \"podman\",\n [\n \"run\",\n \"-d\",\n \"--name\",\n containerName,\n ...userArgs,\n ...usernsArgs,\n ...networkArgs,\n ...groupArgs,\n ...deviceArgs,\n ...cpusArgs,\n \"-w\",\n worktreePath,\n ...envArgs,\n ...volumeArgs,\n \"--entrypoint\",\n \"sleep\",\n imageName,\n \"infinity\",\n ],\n (error) => {\n if (error) {\n reject(new Error(`podman run failed: ${error.message}`));\n } else {\n resolve();\n }\n },\n );\n });\n\n // Create parent directories for file mounts and chown to the container user\n for (const dir of parentDirsToCreate) {\n await new Promise<void>((resolve, reject) => {\n execFile(\n \"podman\",\n [\n \"exec\",\n \"--user\",\n \"0:0\",\n containerName,\n \"sh\",\n \"-c\",\n `mkdir -p \"$1\" && chown \"$2\" \"$1\"`,\n \"sh\",\n dir,\n `${containerUid}:${containerGid}`,\n ],\n (error) => {\n if (error) {\n reject(\n new Error(\n `Failed to create parent directory '${dir}' in container: ${error.message}`,\n ),\n );\n } else {\n resolve();\n }\n },\n );\n });\n }\n\n // Register synchronous container cleanup via the shared shutdown registry\n // so concurrent sandboxes share a single exit/SIGINT/SIGTERM listener\n // instead of tripping Node's MaxListenersExceededWarning.\n const removeContainerSync = () => {\n try {\n execFileSync(\"podman\", [\"rm\", \"-f\", containerName], {\n stdio: \"ignore\",\n timeout: 5000,\n });\n } catch {\n /* best-effort */\n }\n };\n const unregisterShutdown = registerShutdown(removeContainerSync);\n\n const handle: BindMountSandboxHandle = {\n worktreePath,\n\n exec: (\n command: string,\n opts?: {\n onLine?: (line: string) => void;\n cwd?: string;\n sudo?: boolean;\n stdin?: string;\n },\n ): Promise<ExecResult> => {\n const effectiveCommand = opts?.sudo ? `sudo ${command}` : command;\n const args = [\"exec\"];\n if (opts?.stdin !== undefined) args.push(\"-i\");\n if (opts?.cwd) args.push(\"-w\", opts.cwd);\n args.push(containerName, \"sh\", \"-c\", effectiveCommand);\n\n return new Promise((resolve, reject) => {\n const proc = spawn(\"podman\", args, {\n stdio: [\n opts?.stdin !== undefined ? \"pipe\" : \"ignore\",\n \"pipe\",\n \"pipe\",\n ],\n });\n\n if (opts?.stdin !== undefined) {\n proc.stdin!.write(opts.stdin);\n proc.stdin!.end();\n }\n\n proc.on(\"error\", (error) => {\n reject(new Error(`podman exec failed: ${error.message}`));\n });\n\n if (opts?.onLine) {\n const onLine = opts.onLine;\n const stdoutTail = new BoundedTail(maxOutputTailChars, \"\\n\");\n const stderrTail = new BoundedTail(maxOutputTailChars, \"\");\n const rl = createInterface({ input: proc.stdout! });\n rl.on(\"line\", (line) => {\n stdoutTail.push(line);\n onLine(line);\n });\n proc.stderr!.on(\"data\", (chunk: Buffer) => {\n stderrTail.push(chunk.toString());\n });\n proc.on(\"close\", (code) => {\n resolve({\n stdout: stdoutTail.toString(),\n stderr: stderrTail.toString(),\n exitCode: code ?? 0,\n });\n });\n } else {\n const stdoutChunks: string[] = [];\n const stderrChunks: string[] = [];\n proc.stdout!.on(\"data\", (chunk: Buffer) => {\n stdoutChunks.push(chunk.toString());\n });\n proc.stderr!.on(\"data\", (chunk: Buffer) => {\n stderrChunks.push(chunk.toString());\n });\n proc.on(\"close\", (code) => {\n resolve({\n stdout: stdoutChunks.join(\"\"),\n stderr: stderrChunks.join(\"\"),\n exitCode: code ?? 0,\n });\n });\n }\n });\n },\n\n interactiveExec: (\n args: string[],\n opts: InteractiveExecOptions,\n ): Promise<{ exitCode: number }> => {\n return new Promise((resolve, reject) => {\n const podmanArgs = [\"exec\"];\n // Allocate a pseudo-terminal when stdin looks like a TTY\n if (\n \"isTTY\" in opts.stdin &&\n (opts.stdin as { isTTY?: boolean }).isTTY\n ) {\n podmanArgs.push(\"-it\");\n } else {\n podmanArgs.push(\"-i\");\n }\n if (opts.cwd) podmanArgs.push(\"-w\", opts.cwd);\n podmanArgs.push(containerName, ...args);\n\n const proc = spawn(\"podman\", podmanArgs, {\n stdio: [opts.stdin, opts.stdout, opts.stderr] as StdioOptions,\n });\n\n proc.on(\"error\", (error: Error) => {\n reject(new Error(`podman exec failed: ${error.message}`));\n });\n\n proc.on(\"close\", (code: number | null) => {\n resolve({ exitCode: code ?? 0 });\n });\n });\n },\n\n copyFileIn: (hostPath: string, sandboxPath: string): Promise<void> =>\n new Promise((resolve, reject) => {\n execFile(\n \"podman\",\n [\"cp\", hostPath, `${containerName}:${sandboxPath}`],\n (error) => {\n if (error) {\n reject(new Error(`podman cp (in) failed: ${error.message}`));\n } else {\n resolve();\n }\n },\n );\n }),\n\n copyFileOut: (sandboxPath: string, hostPath: string): Promise<void> =>\n new Promise((resolve, reject) => {\n execFile(\n \"podman\",\n [\"cp\", `${containerName}:${sandboxPath}`, hostPath],\n (error) => {\n if (error) {\n reject(new Error(`podman cp (out) failed: ${error.message}`));\n } else {\n resolve();\n }\n },\n );\n }),\n\n close: async (): Promise<void> => {\n unregisterShutdown();\n await new Promise<void>((resolve, reject) => {\n execFile(\"podman\", [\"rm\", \"-f\", containerName], (error) => {\n if (error) {\n reject(new Error(`podman rm failed: ${error.message}`));\n } else {\n resolve();\n }\n });\n });\n },\n };\n\n return handle;\n },\n });\n};\n\n// Re-export for backwards compatibility\nexport { defaultImageName };\n\nconst checkImageExists = (imageName: string): Promise<void> =>\n new Promise<void>((resolve, reject) => {\n execFile(\"podman\", [\"image\", \"inspect\", imageName], (error) => {\n if (error) {\n reject(\n new Error(\n `Image '${imageName}' not found locally. Build it first with 'podman build -t ${imageName} .'`,\n ),\n );\n } else {\n resolve();\n }\n });\n });\n\nconst podmanMachineError = () =>\n new Error(\n \"Podman Machine is not running. Run 'podman machine init && podman machine start' first.\",\n );\n\nconst checkPodmanMachine = (): Promise<void> =>\n new Promise<void>((resolve, reject) => {\n execFile(\n \"podman\",\n [\"machine\", \"list\", \"--format\", \"json\"],\n (error, stdout) => {\n if (error) {\n reject(podmanMachineError());\n return;\n }\n try {\n const machines = JSON.parse(stdout.toString()) as Array<{\n Running?: boolean;\n }>;\n if (machines.some((m) => m.Running)) {\n resolve();\n } else {\n reject(podmanMachineError());\n }\n } catch {\n reject(podmanMachineError());\n }\n },\n );\n });\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/sandboxes/podman.ts"],"names":[],"mappings":";;;;;;;;;;AA6JO,IAAM,MAAA,GAAS,CAAC,OAAA,KAA6C;AAClE,EAAA,MAAM,sBAAsB,OAAA,EAAS,SAAA;AACrC,EAAA,MAAM,YAAA,GAAe,SAAS,YAAA,IAAgB,GAAA;AAC9C,EAAA,MAAM,MAAA,GAAS,SAAS,MAAA,IAAU,SAAA;AAClC,EAAA,MAAM,YAAA,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OAAA,CAAQ,QAAQ,CAAA,IACtB,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA,KAAM,gBAAA,CAAiB,CAAC,CAAC,CAAA,EACxC;AACA,UAAA,OAAA,EAAQ;AAAA,QACV,CAAA,MAAO;AACL,UAAA,MAAA,CAAO,oBAAoB,CAAA;AAAA,QAC7B;AAAA,MACF,CAAA,CAAA,MAAQ;AACN,QAAA,MAAA,CAAO,oBAAoB,CAAA;AAAA,MAC7B;AAAA,IACF;AAAA,GACF;AACF,CAAC,CAAA;AAGH,IAAM,gBAAA,GAAmB,CAAC,OAAA,KACxB,OAAO,OAAA,KAAY,QAAA,IACnB,OAAA,KAAY,IAAA,IACZ,SAAA,IAAa,OAAA,IACb,OAAA,CAAQ,OAAA,KAAY,IAAA","file":"podman.js","sourcesContent":["/**\n * Podman sandbox provider — creates Podman containers with bind-mounts.\n *\n * Usage:\n * import { podman } from \"sandcastle/sandboxes/podman\";\n * await run({ agent: claudeCode(\"claude-opus-4-8\"), sandbox: podman() });\n */\n\nimport { execFile, execFileSync, spawn } from \"node:child_process\";\nimport type { StdioOptions } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { createInterface } from \"node:readline\";\nimport { createBindMountSandboxProvider } from \"../SandboxProvider.js\";\nimport type {\n SandboxProvider,\n BindMountCreateOptions,\n BindMountSandboxHandle,\n ExecResult,\n InteractiveExecOptions,\n} from \"../SandboxProvider.js\";\nimport type { MountConfig } from \"../MountConfig.js\";\nimport type { SelinuxLabel } from \"../mountUtils.js\";\nimport type { LinuxCapability } from \"../LinuxCapability.js\";\nimport {\n defaultImageName,\n resolveUserMounts,\n formatVolumeMount,\n processFileMountParents,\n} from \"../mountUtils.js\";\nimport { BoundedTail, MAX_TAIL_CHARS } from \"../boundedTail.js\";\nimport { registerShutdown } from \"../shutdownRegistry.js\";\n\nexport type { LinuxCapability } from \"../LinuxCapability.js\";\n\nexport interface PodmanOptions {\n /** Podman image name (default: derived from repo directory name). */\n readonly imageName?: string;\n /**\n * SELinux volume label suffix applied to bind mounts.\n *\n * - `\"z\"` — shared label (default). No-op on non-SELinux systems.\n * - `\"Z\"` — private label; only this container can access the mount.\n * - `false` — disable labeling entirely.\n */\n readonly selinuxLabel?: SelinuxLabel;\n /**\n * User namespace mode for rootless Podman.\n *\n * - `\"keep-id\"` (default) — maps host UID to `containerUid` inside the\n * container via `--userns=keep-id:uid=N,gid=N`, so both bind-mounted\n * files and image-built files have correct ownership without chown.\n * - `false` — disable; use for rootful Podman setups.\n */\n readonly userns?: \"keep-id\" | false;\n /**\n * The UID of the `agent` user inside the container image (default: 1000).\n *\n * Must match the UID set in the Containerfile. Used with `--userns=keep-id`\n * to map the host user to this UID inside the container.\n */\n readonly containerUid?: number;\n /**\n * The GID of the `agent` user inside the container image (default: 1000).\n *\n * Must match the GID set in the Containerfile. Used with `--userns=keep-id`\n * to map the host group to this GID inside the container.\n */\n readonly containerGid?: number;\n /**\n * Additional host directories to bind-mount into the sandbox.\n *\n * Each entry specifies a `hostPath` (tilde-expanded) and `sandboxPath`.\n * If `hostPath` does not exist, sandbox creation fails with a clear error.\n */\n readonly mounts?: readonly MountConfig[];\n /** Environment variables injected by this provider. Merged at launch time with env resolver and agent provider env. */\n readonly env?: Record<string, string>;\n /**\n * Podman network(s) to attach the container to.\n *\n * - `\"my-network\"` → `--network my-network`\n * - `[\"net1\", \"net2\"]` → `--network net1 --network net2`\n *\n * When omitted, Podman's default network is used.\n */\n readonly network?: string | readonly string[];\n /**\n * Supplementary groups to add the container user to, via `--group-add`.\n *\n * Accepts group names or numeric GIDs:\n *\n * - `[\"docker\"]` → `--group-add docker`\n * - `[999]` → `--group-add 999`\n * - `[\"docker\", 999]` → `--group-add docker --group-add 999`\n *\n * Useful for granting access to a bind-mounted Docker socket (Docker-outside-of-Docker).\n * When omitted, no `--group-add` flags are added.\n */\n readonly groups?: readonly (string | number)[];\n /**\n * Linux capabilities to drop from the container, via `--cap-drop`.\n *\n * Names are written without the `CAP_` prefix, as `podman run` accepts them,\n * and a misspelt name is a type error:\n *\n * - `[\"NET_RAW\"]` → `--cap-drop NET_RAW` (no raw sockets, so no `ping`)\n * - `[\"NET_RAW\", \"MKNOD\"]` → `--cap-drop NET_RAW --cap-drop MKNOD`\n * - `[\"ALL\"]` → `--cap-drop ALL` (drop every capability)\n *\n * When omitted, no `--cap-drop` flags are added and the container keeps\n * Podman's default capability set.\n */\n readonly capDrop?: readonly LinuxCapability[];\n /**\n * Host devices to expose to the container, via `--device`.\n *\n * Each entry is a full device spec in `host[:container[:permissions]]` form:\n *\n * - `[\"/dev/kvm\"]` → `--device /dev/kvm`\n * - `[\"/dev/sda:/dev/xvda:rwm\"]` → `--device /dev/sda:/dev/xvda:rwm`\n * - `[\"/dev/kvm\", \"/dev/fuse\"]` → `--device /dev/kvm --device /dev/fuse`\n *\n * Under rootless Podman, exposing a host device often requires host-side\n * group/permission setup and may interact with `--userns=keep-id`.\n * When omitted, no `--device` flags are added.\n */\n readonly devices?: readonly string[];\n /**\n * Maximum number of characters of streamed `exec` output retained per stream\n * (stdout and stderr) when an `onLine` callback is supplied (default: 64KiB).\n *\n * Output is delivered live to `onLine` regardless; this only bounds the tail\n * returned in `ExecResult`, preventing a long-running agent's output from\n * overflowing V8's max string length and crashing the run.\n */\n readonly maxOutputTailChars?: number;\n /**\n * Limit the CPU resources available to the container, via `--cpus`.\n *\n * Maps directly to `podman run --cpus`. Accepts fractional values:\n *\n * - `2` → `--cpus 2` (at most 2 CPUs)\n * - `1.5` → `--cpus 1.5` (at most 1.5 CPUs)\n *\n * When omitted, no `--cpus` flag is added and the container is unconstrained.\n */\n readonly cpus?: number;\n}\n\n/**\n * Create a Podman sandbox provider.\n *\n * The returned provider creates Podman containers with bind-mounts\n * for the worktree and git directories. Calls the `podman` binary\n * on PATH directly. On macOS/Windows, verifies that a Podman Machine\n * is running before container creation.\n */\nexport const podman = (options?: PodmanOptions): SandboxProvider => {\n const configuredImageName = options?.imageName;\n const selinuxLabel = options?.selinuxLabel ?? \"z\";\n const userns = options?.userns ?? \"keep-id\";\n const containerUid = options?.containerUid ?? 1000;\n const containerGid = options?.containerGid ?? 1000;\n const maxOutputTailChars = options?.maxOutputTailChars ?? MAX_TAIL_CHARS;\n const sandboxHomedir = \"/home/agent\";\n const userMounts = options?.mounts\n ? resolveUserMounts(options.mounts, sandboxHomedir)\n : [];\n // Validate file mounts and collect parent dirs to create at container start.\n // Throws at construction time if any file mount parent is outside sandboxHomedir.\n const parentDirsToCreate = processFileMountParents(\n userMounts,\n sandboxHomedir,\n );\n\n return createBindMountSandboxProvider({\n name: \"podman\",\n env: options?.env,\n sandboxHomedir,\n create: async (\n createOptions: BindMountCreateOptions,\n ): Promise<BindMountSandboxHandle> => {\n const containerName = `sandcastle-${randomUUID()}`;\n\n const worktreePath =\n createOptions.mounts.find(\n (m) => m.hostPath === createOptions.worktreePath,\n )?.sandboxPath ?? \"/home/agent/workspace\";\n\n // Build volume mount strings with optional SELinux label (internal + user mounts)\n const allMounts = [...createOptions.mounts, ...userMounts];\n const volumeMounts = allMounts.map((m) =>\n formatVolumeMount(m, selinuxLabel),\n );\n\n // Resolve image name\n const imageName =\n configuredImageName ?? defaultImageName(createOptions.hostRepoPath);\n\n // Pre-flight: check Podman Machine on macOS/Windows\n if (process.platform === \"darwin\" || process.platform === \"win32\") {\n await checkPodmanMachine();\n }\n\n // Pre-flight: verify image exists locally\n await checkImageExists(imageName);\n\n const env = { ...createOptions.env, HOME: \"/home/agent\" };\n const envArgs = Object.entries(env).flatMap(([key, value]) => [\n \"-e\",\n `${key}=${value}`,\n ]);\n const volumeArgs = volumeMounts.flatMap((v) => [\"-v\", v]);\n const usernsArgs =\n userns === false\n ? []\n : [`--userns=keep-id:uid=${containerUid},gid=${containerGid}`];\n const userArgs = [\"--user\", `${containerUid}:${containerGid}`];\n const network = options?.network;\n const networks =\n network === undefined || network === \"\" ? [] : [network].flat();\n const networkArgs = networks.flatMap((n) => [\"--network\", n]);\n const groupArgs = (options?.groups ?? []).flatMap((g) => [\n \"--group-add\",\n String(g),\n ]);\n const capDropArgs = (options?.capDrop ?? []).flatMap((cap) => [\n \"--cap-drop\",\n cap,\n ]);\n const deviceArgs = (options?.devices ?? []).flatMap((d) => [\n \"--device\",\n d,\n ]);\n const cpusArgs =\n options?.cpus === undefined ? [] : [\"--cpus\", String(options.cpus)];\n\n // Start container via podman run\n await new Promise<void>((resolve, reject) => {\n execFile(\n \"podman\",\n [\n \"run\",\n \"-d\",\n \"--name\",\n containerName,\n ...userArgs,\n ...usernsArgs,\n ...networkArgs,\n ...groupArgs,\n ...capDropArgs,\n ...deviceArgs,\n ...cpusArgs,\n \"-w\",\n worktreePath,\n ...envArgs,\n ...volumeArgs,\n \"--entrypoint\",\n \"sleep\",\n imageName,\n \"infinity\",\n ],\n (error) => {\n if (error) {\n reject(new Error(`podman run failed: ${error.message}`));\n } else {\n resolve();\n }\n },\n );\n });\n\n // Create parent directories for file mounts and chown to the container user\n for (const dir of parentDirsToCreate) {\n await new Promise<void>((resolve, reject) => {\n execFile(\n \"podman\",\n [\n \"exec\",\n \"--user\",\n \"0:0\",\n containerName,\n \"sh\",\n \"-c\",\n `mkdir -p \"$1\" && chown \"$2\" \"$1\"`,\n \"sh\",\n dir,\n `${containerUid}:${containerGid}`,\n ],\n (error) => {\n if (error) {\n reject(\n new Error(\n `Failed to create parent directory '${dir}' in container: ${error.message}`,\n ),\n );\n } else {\n resolve();\n }\n },\n );\n });\n }\n\n // Register synchronous container cleanup via the shared shutdown registry\n // so concurrent sandboxes share a single exit/SIGINT/SIGTERM listener\n // instead of tripping Node's MaxListenersExceededWarning.\n // `--time 0`: PID 1 is `sleep infinity`, which ignores SIGTERM, so a\n // plain `rm -f` waits out the 10 s StopTimeout before SIGKILL. The 5 s\n // timeout below would kill that `rm` mid-stop and leave the container\n // in `Stopping` indefinitely.\n const removeContainerSync = () => {\n try {\n execFileSync(\"podman\", [\"rm\", \"-f\", \"--time\", \"0\", containerName], {\n stdio: \"ignore\",\n timeout: 5000,\n });\n } catch {\n /* best-effort */\n }\n };\n const unregisterShutdown = registerShutdown(removeContainerSync);\n\n const handle: BindMountSandboxHandle = {\n worktreePath,\n sandboxId: containerName,\n\n exec: async (\n command: string,\n opts?: {\n onLine?: (line: string) => void;\n cwd?: string;\n sudo?: boolean;\n stdin?: string;\n },\n ): Promise<ExecResult> => {\n const args = [\"exec\"];\n // Elevate by running as root through the engine, not a `sudo`\n // prefix: the image needs no sudo binary, and the whole command\n // (`a && b`, not just `a`) runs as root.\n if (opts?.sudo === true) {\n args.push(\"--user\", \"0:0\");\n }\n if (opts?.stdin !== undefined) {\n args.push(\"-i\");\n }\n if (opts?.cwd !== undefined && opts.cwd !== \"\") {\n args.push(\"-w\", opts.cwd);\n }\n args.push(containerName, \"sh\", \"-c\", command);\n\n return new Promise((resolve, reject) => {\n const stdin = opts?.stdin;\n // Two literal `stdio` tuples, so the types know stdout and stderr\n // are always piped.\n const proc =\n stdin === undefined\n ? spawn(\"podman\", args, { stdio: [\"ignore\", \"pipe\", \"pipe\"] })\n : spawn(\"podman\", args, { stdio: [\"pipe\", \"pipe\", \"pipe\"] });\n\n if (stdin !== undefined) {\n proc.stdin?.write(stdin);\n proc.stdin?.end();\n }\n\n proc.on(\"error\", (error: Error) => {\n reject(new Error(`podman exec failed: ${error.message}`));\n });\n\n if (opts?.onLine) {\n const { onLine } = opts;\n const stdoutTail = new BoundedTail(maxOutputTailChars, \"\\n\");\n const stderrTail = new BoundedTail(maxOutputTailChars, \"\");\n const rl = createInterface({ input: proc.stdout });\n rl.on(\"line\", (line) => {\n stdoutTail.push(line);\n onLine(line);\n });\n proc.stderr.on(\"data\", (chunk: Buffer) => {\n stderrTail.push(chunk.toString());\n });\n proc.on(\"close\", (code: number | null) => {\n resolve({\n stdout: stdoutTail.toString(),\n stderr: stderrTail.toString(),\n exitCode: code ?? 0,\n });\n });\n } else {\n const stdoutChunks: string[] = [];\n const stderrChunks: string[] = [];\n proc.stdout.on(\"data\", (chunk: Buffer) => {\n stdoutChunks.push(chunk.toString());\n });\n proc.stderr.on(\"data\", (chunk: Buffer) => {\n stderrChunks.push(chunk.toString());\n });\n proc.on(\"close\", (code: number | null) => {\n resolve({\n stdout: stdoutChunks.join(\"\"),\n stderr: stderrChunks.join(\"\"),\n exitCode: code ?? 0,\n });\n });\n }\n });\n },\n\n interactiveExec: async (\n args: string[],\n opts: InteractiveExecOptions,\n ): Promise<{ exitCode: number }> =>\n new Promise((resolve, reject) => {\n const podmanArgs = [\"exec\"];\n // Allocate a pseudo-terminal when stdin looks like a TTY\n if (\n \"isTTY\" in opts.stdin &&\n (opts.stdin as { isTTY?: boolean }).isTTY === true\n ) {\n podmanArgs.push(\"-it\");\n } else {\n podmanArgs.push(\"-i\");\n }\n if (opts.cwd !== undefined && opts.cwd !== \"\") {\n podmanArgs.push(\"-w\", opts.cwd);\n }\n podmanArgs.push(containerName, ...args);\n\n const proc = spawn(\"podman\", podmanArgs, {\n stdio: [opts.stdin, opts.stdout, opts.stderr] as StdioOptions,\n });\n\n proc.on(\"error\", (error: Error) => {\n reject(new Error(`podman exec failed: ${error.message}`));\n });\n\n proc.on(\"close\", (code: number | null) => {\n resolve({ exitCode: code ?? 0 });\n });\n }),\n copyFileIn: async (\n hostPath: string,\n sandboxPath: string,\n ): Promise<void> =>\n new Promise((resolve, reject) => {\n execFile(\n \"podman\",\n [\"cp\", hostPath, `${containerName}:${sandboxPath}`],\n (error) => {\n if (error) {\n reject(new Error(`podman cp (in) failed: ${error.message}`));\n } else {\n resolve();\n }\n },\n );\n }),\n\n copyFileOut: async (\n sandboxPath: string,\n hostPath: string,\n ): Promise<void> =>\n new Promise((resolve, reject) => {\n execFile(\n \"podman\",\n [\"cp\", `${containerName}:${sandboxPath}`, hostPath],\n (error) => {\n if (error) {\n reject(new Error(`podman cp (out) failed: ${error.message}`));\n } else {\n resolve();\n }\n },\n );\n }),\n\n close: async (): Promise<void> => {\n unregisterShutdown();\n await new Promise<void>((resolve, reject) => {\n execFile(\n \"podman\",\n [\"rm\", \"-f\", \"--time\", \"0\", containerName],\n (error) => {\n if (error) {\n reject(new Error(`podman rm failed: ${error.message}`));\n } else {\n resolve();\n }\n },\n );\n });\n },\n };\n\n return handle;\n },\n });\n};\n\n// Re-export for backwards compatibility\nexport { defaultImageName } from \"../mountUtils.js\";\n\nconst checkImageExists = async (imageName: string): Promise<void> =>\n new Promise<void>((resolve, reject) => {\n execFile(\"podman\", [\"image\", \"inspect\", imageName], (error) => {\n if (error) {\n reject(\n new Error(\n `Image '${imageName}' not found locally. Build it first with 'podman build -t ${imageName} .'`,\n ),\n );\n } else {\n resolve();\n }\n });\n });\n\nconst podmanMachineError = () =>\n new Error(\n \"Podman Machine is not running. Run 'podman machine init && podman machine start' first.\",\n );\n\nconst checkPodmanMachine = async (): Promise<void> =>\n new Promise<void>((resolve, reject) => {\n execFile(\n \"podman\",\n [\"machine\", \"list\", \"--format\", \"json\"],\n (error, stdout) => {\n if (error) {\n reject(podmanMachineError());\n return;\n }\n try {\n const machines: unknown = JSON.parse(stdout);\n if (\n Array.isArray(machines) &&\n machines.some((m) => isRunningMachine(m))\n ) {\n resolve();\n } else {\n reject(podmanMachineError());\n }\n } catch {\n reject(podmanMachineError());\n }\n },\n );\n });\n\n/** One entry of `podman machine list --format json` that reports it is running. */\nconst isRunningMachine = (machine: unknown): boolean =>\n typeof machine === \"object\" &&\n machine !== null &&\n \"Running\" in machine &&\n machine.Running === true;\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { B as BindMountSandboxProvider } from '../SandboxProvider-YCL97qco.js';
|
|
2
|
+
import { M as MountConfig } from '../MountConfig-CmXclHA5.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Seatbelt sandbox provider — a native sandbox provider for macOS.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { seatbelt } from "@ai-hero/sandcastle/sandboxes/seatbelt";
|
|
9
|
+
* await run({ agent: claudeCode("claude-opus-4-8"), sandbox: seatbelt() });
|
|
10
|
+
*
|
|
11
|
+
* Each `exec` runs under the system `sandbox-exec` with a deny-by-default
|
|
12
|
+
* profile: the system toolchain read-only, the worktree and git dirs
|
|
13
|
+
* read/write at their host paths, a private home and temp dir, the host
|
|
14
|
+
* network, and only the env vars Sandcastle passes in. No image, no daemon.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Options for {@link seatbelt}. */
|
|
18
|
+
interface SeatbeltOptions {
|
|
19
|
+
/** Environment variables injected by this provider. Merged at launch time. */
|
|
20
|
+
readonly env?: Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of characters of streamed `exec` output retained per stream
|
|
23
|
+
* (stdout and stderr) when an `onLine` callback is supplied (default: 64KiB).
|
|
24
|
+
*
|
|
25
|
+
* Output is delivered live to `onLine` regardless; this only bounds the tail
|
|
26
|
+
* returned in `ExecResult`, preventing a long-running agent's output from
|
|
27
|
+
* overflowing V8's max string length and crashing the run.
|
|
28
|
+
*/
|
|
29
|
+
readonly maxOutputTailChars?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Extra host paths to make visible in the sandbox (a cache, a sibling
|
|
32
|
+
* checkout, `.beads/`). Each appears at its own host path, so after
|
|
33
|
+
* resolution `sandboxPath` must equal `hostPath`; `seatbelt()` throws
|
|
34
|
+
* otherwise. `readonly` defaults to `false`.
|
|
35
|
+
*/
|
|
36
|
+
readonly mounts?: readonly MountConfig[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a Seatbelt sandbox provider (macOS 14 or later).
|
|
40
|
+
*
|
|
41
|
+
* Each `exec` runs under the system `/usr/bin/sandbox-exec` with a
|
|
42
|
+
* deny-by-default profile. The agent runs the host's own toolchain,
|
|
43
|
+
* read-only, and can write only the worktree, the git dirs Sandcastle
|
|
44
|
+
* mounts, a private temp dir (`TMPDIR`) and a private home (`HOME`). The git
|
|
45
|
+
* control files stay read-only, and the dirs holding them can't be moved
|
|
46
|
+
* aside. It can't signal host processes, but Seatbelt can't fully hide them.
|
|
47
|
+
* The private home is exposed to Sandcastle as `/home/agent`: copies to and
|
|
48
|
+
* from paths under it land in the private dir. Both private dirs are removed
|
|
49
|
+
* on close, and every process an `exec` started is killed when it exits, on
|
|
50
|
+
* close, on shutdown and when this Node process is hard-killed (a detached
|
|
51
|
+
* host watchdog per `exec` does that). The toolchain comes from the host
|
|
52
|
+
* `PATH`: each `PATH` dir (never the home dir or an ancestor of it) and the
|
|
53
|
+
* install root of each executable symlinked from one. Add other paths with `mounts`. The network is
|
|
54
|
+
* open, including the host's localhost. It has no root: `exec` with
|
|
55
|
+
* `sudo: true` rejects.
|
|
56
|
+
*
|
|
57
|
+
* Checks once per process that Seatbelt is usable, and throws
|
|
58
|
+
* `NativeSandboxUnavailableError` if it isn't: on a non-macOS OS, on macOS
|
|
59
|
+
* older than 14, or when `sandbox-exec` is missing or fails (for instance
|
|
60
|
+
* inside another Seatbelt sandbox). It never falls back to running
|
|
61
|
+
* unsandboxed.
|
|
62
|
+
*/
|
|
63
|
+
declare const seatbelt: (options?: SeatbeltOptions) => BindMountSandboxProvider;
|
|
64
|
+
|
|
65
|
+
export { type SeatbeltOptions, seatbelt };
|