@ai-hero/sandcastle 0.12.0 → 0.14.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 -1368
- package/dist/LinuxCapability-B_PQfsY_.d.ts +32 -0
- package/dist/{SandboxProvider-EkSMuBp8.d.ts → SandboxProvider-Chsi-Zs6.d.ts} +31 -3
- package/dist/{chunk-NGBM7T3E.js → chunk-6NQPCXSG.js} +5 -2
- package/dist/chunk-6NQPCXSG.js.map +1 -0
- package/dist/chunk-7N7AMUYA.js +353 -0
- package/dist/chunk-7N7AMUYA.js.map +1 -0
- package/dist/chunk-ATA2V2TC.js +112 -0
- package/dist/chunk-ATA2V2TC.js.map +1 -0
- package/dist/chunk-BIF2X6QB.js +94 -0
- package/dist/chunk-BIF2X6QB.js.map +1 -0
- package/dist/{chunk-BIWNFKGV.js → chunk-BVZWLFFT.js} +2 -2
- package/dist/chunk-BVZWLFFT.js.map +1 -0
- package/dist/chunk-EXYXBRCX.js +60 -0
- package/dist/chunk-EXYXBRCX.js.map +1 -0
- package/dist/chunk-G2R53CVZ.js +3172 -0
- package/dist/chunk-G2R53CVZ.js.map +1 -0
- package/dist/{chunk-CP3TYXZA.js → chunk-GCLEXPXG.js} +95 -85
- package/dist/chunk-GCLEXPXG.js.map +1 -0
- package/dist/chunk-H2PEFS4W.js +1244 -0
- package/dist/chunk-H2PEFS4W.js.map +1 -0
- package/dist/chunk-HSXPRZKG.js +150 -0
- package/dist/chunk-HSXPRZKG.js.map +1 -0
- package/dist/chunk-IBK2XNSS.js +50 -0
- package/dist/chunk-IBK2XNSS.js.map +1 -0
- package/dist/chunk-RDW7FNN6.js +792 -0
- package/dist/chunk-RDW7FNN6.js.map +1 -0
- package/dist/{chunk-DJRHWPEH.js → chunk-S6UHPTRG.js} +284 -352
- package/dist/chunk-S6UHPTRG.js.map +1 -0
- package/dist/{chunk-VOG34SRF.js → chunk-STB2U7BB.js} +11823 -6977
- package/dist/chunk-STB2U7BB.js.map +1 -0
- package/dist/chunk-VRXR2T3S.js +24 -0
- package/dist/chunk-VRXR2T3S.js.map +1 -0
- package/dist/index.d.ts +241 -26
- package/dist/index.js +1082 -1679
- package/dist/index.js.map +1 -1
- package/dist/main.js +1248 -854
- package/dist/main.js.map +1 -1
- package/dist/sandboxes/bwrap.d.ts +58 -0
- package/dist/sandboxes/bwrap.js +296 -0
- package/dist/sandboxes/bwrap.js.map +1 -0
- package/dist/sandboxes/daytona.d.ts +1 -1
- package/dist/sandboxes/daytona.js +203 -98
- package/dist/sandboxes/daytona.js.map +1 -1
- package/dist/sandboxes/docker.d.ts +18 -4
- package/dist/sandboxes/docker.js +7 -4
- package/dist/sandboxes/e2b.d.ts +41 -0
- package/dist/sandboxes/e2b.js +202 -0
- package/dist/sandboxes/e2b.js.map +1 -0
- package/dist/sandboxes/modal.d.ts +78 -0
- package/dist/sandboxes/modal.js +171 -0
- package/dist/sandboxes/modal.js.map +1 -0
- package/dist/sandboxes/no-sandbox.d.ts +1 -1
- package/dist/sandboxes/no-sandbox.js +2 -2
- package/dist/sandboxes/podman.d.ts +18 -4
- package/dist/sandboxes/podman.js +72 -56
- package/dist/sandboxes/podman.js.map +1 -1
- package/dist/sandboxes/seatbelt.d.ts +65 -0
- package/dist/sandboxes/seatbelt.js +425 -0
- package/dist/sandboxes/seatbelt.js.map +1 -0
- package/dist/sandboxes/sprites.d.ts +54 -0
- package/dist/sandboxes/sprites.js +198 -0
- package/dist/sandboxes/sprites.js.map +1 -0
- package/dist/sandboxes/vercel.d.ts +12 -5
- package/dist/sandboxes/vercel.js +195 -126
- package/dist/sandboxes/vercel.js.map +1 -1
- package/dist/templates/parallel-planner/main.mts +13 -22
- package/dist/templates/parallel-planner-with-review/main.mts +13 -15
- package/package.json +63 -11
- package/dist/chunk-62WN33RK.js +0 -104
- package/dist/chunk-62WN33RK.js.map +0 -1
- package/dist/chunk-BIWNFKGV.js.map +0 -1
- package/dist/chunk-CP3TYXZA.js.map +0 -1
- package/dist/chunk-DJRHWPEH.js.map +0 -1
- package/dist/chunk-NGBM7T3E.js.map +0 -1
- package/dist/chunk-VOG34SRF.js.map +0 -1
- package/dist/mountUtils-CCA-bbpK.d.ts +0 -25
package/dist/sandboxes/podman.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { resolveUserMounts, processFileMountParents, formatVolumeMount, defaultImageName
|
|
3
|
-
export { defaultImageName } from '../chunk-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
2
|
+
import { resolveUserMounts, processFileMountParents, formatVolumeMount, defaultImageName } from '../chunk-G2R53CVZ.js';
|
|
3
|
+
export { defaultImageName } from '../chunk-G2R53CVZ.js';
|
|
4
|
+
import { registerShutdown } from '../chunk-EXYXBRCX.js';
|
|
5
|
+
import '../chunk-RDW7FNN6.js';
|
|
6
|
+
import '../chunk-STB2U7BB.js';
|
|
7
|
+
import { createBindMountSandboxProvider } from '../chunk-BVZWLFFT.js';
|
|
8
|
+
import { MAX_TAIL_CHARS, BoundedTail } from '../chunk-6NQPCXSG.js';
|
|
6
9
|
import { execFile, execFileSync, spawn } from 'child_process';
|
|
7
10
|
import { randomUUID } from 'crypto';
|
|
8
11
|
import { createInterface } from 'readline';
|
|
@@ -45,19 +48,24 @@ var podman = (options) => {
|
|
|
45
48
|
`${key}=${value}`
|
|
46
49
|
]);
|
|
47
50
|
const volumeArgs = volumeMounts.flatMap((v) => ["-v", v]);
|
|
48
|
-
const usernsArgs = userns ? [`--userns=keep-id:uid=${containerUid},gid=${containerGid}`]
|
|
51
|
+
const usernsArgs = userns === false ? [] : [`--userns=keep-id:uid=${containerUid},gid=${containerGid}`];
|
|
49
52
|
const userArgs = ["--user", `${containerUid}:${containerGid}`];
|
|
50
|
-
const
|
|
53
|
+
const network = options?.network;
|
|
54
|
+
const networks = network === void 0 || network === "" ? [] : [network].flat();
|
|
51
55
|
const networkArgs = networks.flatMap((n) => ["--network", n]);
|
|
52
56
|
const groupArgs = (options?.groups ?? []).flatMap((g) => [
|
|
53
57
|
"--group-add",
|
|
54
58
|
String(g)
|
|
55
59
|
]);
|
|
60
|
+
const capDropArgs = (options?.capDrop ?? []).flatMap((cap) => [
|
|
61
|
+
"--cap-drop",
|
|
62
|
+
cap
|
|
63
|
+
]);
|
|
56
64
|
const deviceArgs = (options?.devices ?? []).flatMap((d) => [
|
|
57
65
|
"--device",
|
|
58
66
|
d
|
|
59
67
|
]);
|
|
60
|
-
const cpusArgs = options?.cpus
|
|
68
|
+
const cpusArgs = options?.cpus === void 0 ? [] : ["--cpus", String(options.cpus)];
|
|
61
69
|
await new Promise((resolve, reject) => {
|
|
62
70
|
execFile(
|
|
63
71
|
"podman",
|
|
@@ -70,6 +78,7 @@ var podman = (options) => {
|
|
|
70
78
|
...usernsArgs,
|
|
71
79
|
...networkArgs,
|
|
72
80
|
...groupArgs,
|
|
81
|
+
...capDropArgs,
|
|
73
82
|
...deviceArgs,
|
|
74
83
|
...cpusArgs,
|
|
75
84
|
"-w",
|
|
@@ -122,7 +131,7 @@ var podman = (options) => {
|
|
|
122
131
|
}
|
|
123
132
|
const removeContainerSync = () => {
|
|
124
133
|
try {
|
|
125
|
-
execFileSync("podman", ["rm", "-f", containerName], {
|
|
134
|
+
execFileSync("podman", ["rm", "-f", "--time", "0", containerName], {
|
|
126
135
|
stdio: "ignore",
|
|
127
136
|
timeout: 5e3
|
|
128
137
|
});
|
|
@@ -132,29 +141,31 @@ var podman = (options) => {
|
|
|
132
141
|
const unregisterShutdown = registerShutdown(removeContainerSync);
|
|
133
142
|
const handle = {
|
|
134
143
|
worktreePath,
|
|
135
|
-
|
|
136
|
-
|
|
144
|
+
sandboxId: containerName,
|
|
145
|
+
exec: async (command, opts) => {
|
|
137
146
|
const args = ["exec"];
|
|
138
|
-
if (opts?.
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
if (opts?.sudo === true) {
|
|
148
|
+
args.push("--user", "0:0");
|
|
149
|
+
}
|
|
150
|
+
if (opts?.stdin !== void 0) {
|
|
151
|
+
args.push("-i");
|
|
152
|
+
}
|
|
153
|
+
if (opts?.cwd !== void 0 && opts.cwd !== "") {
|
|
154
|
+
args.push("-w", opts.cwd);
|
|
155
|
+
}
|
|
156
|
+
args.push(containerName, "sh", "-c", command);
|
|
141
157
|
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();
|
|
158
|
+
const stdin = opts?.stdin;
|
|
159
|
+
const proc = stdin === void 0 ? spawn("podman", args, { stdio: ["ignore", "pipe", "pipe"] }) : spawn("podman", args, { stdio: ["pipe", "pipe", "pipe"] });
|
|
160
|
+
if (stdin !== void 0) {
|
|
161
|
+
proc.stdin?.write(stdin);
|
|
162
|
+
proc.stdin?.end();
|
|
152
163
|
}
|
|
153
164
|
proc.on("error", (error) => {
|
|
154
165
|
reject(new Error(`podman exec failed: ${error.message}`));
|
|
155
166
|
});
|
|
156
167
|
if (opts?.onLine) {
|
|
157
|
-
const onLine = opts
|
|
168
|
+
const { onLine } = opts;
|
|
158
169
|
const stdoutTail = new BoundedTail(maxOutputTailChars, "\n");
|
|
159
170
|
const stderrTail = new BoundedTail(maxOutputTailChars, "");
|
|
160
171
|
const rl = createInterface({ input: proc.stdout });
|
|
@@ -191,28 +202,28 @@ var podman = (options) => {
|
|
|
191
202
|
}
|
|
192
203
|
});
|
|
193
204
|
},
|
|
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
|
-
});
|
|
205
|
+
interactiveExec: async (args, opts) => new Promise((resolve, reject) => {
|
|
206
|
+
const podmanArgs = ["exec"];
|
|
207
|
+
if ("isTTY" in opts.stdin && opts.stdin.isTTY === true) {
|
|
208
|
+
podmanArgs.push("-it");
|
|
209
|
+
} else {
|
|
210
|
+
podmanArgs.push("-i");
|
|
211
|
+
}
|
|
212
|
+
if (opts.cwd !== void 0 && opts.cwd !== "") {
|
|
213
|
+
podmanArgs.push("-w", opts.cwd);
|
|
214
|
+
}
|
|
215
|
+
podmanArgs.push(containerName, ...args);
|
|
216
|
+
const proc = spawn("podman", podmanArgs, {
|
|
217
|
+
stdio: [opts.stdin, opts.stdout, opts.stderr]
|
|
213
218
|
});
|
|
214
|
-
|
|
215
|
-
|
|
219
|
+
proc.on("error", (error) => {
|
|
220
|
+
reject(new Error(`podman exec failed: ${error.message}`));
|
|
221
|
+
});
|
|
222
|
+
proc.on("close", (code) => {
|
|
223
|
+
resolve({ exitCode: code ?? 0 });
|
|
224
|
+
});
|
|
225
|
+
}),
|
|
226
|
+
copyFileIn: async (hostPath, sandboxPath) => new Promise((resolve, reject) => {
|
|
216
227
|
execFile(
|
|
217
228
|
"podman",
|
|
218
229
|
["cp", hostPath, `${containerName}:${sandboxPath}`],
|
|
@@ -225,7 +236,7 @@ var podman = (options) => {
|
|
|
225
236
|
}
|
|
226
237
|
);
|
|
227
238
|
}),
|
|
228
|
-
copyFileOut: (sandboxPath, hostPath) => new Promise((resolve, reject) => {
|
|
239
|
+
copyFileOut: async (sandboxPath, hostPath) => new Promise((resolve, reject) => {
|
|
229
240
|
execFile(
|
|
230
241
|
"podman",
|
|
231
242
|
["cp", `${containerName}:${sandboxPath}`, hostPath],
|
|
@@ -241,13 +252,17 @@ var podman = (options) => {
|
|
|
241
252
|
close: async () => {
|
|
242
253
|
unregisterShutdown();
|
|
243
254
|
await new Promise((resolve, reject) => {
|
|
244
|
-
execFile(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
255
|
+
execFile(
|
|
256
|
+
"podman",
|
|
257
|
+
["rm", "-f", "--time", "0", containerName],
|
|
258
|
+
(error) => {
|
|
259
|
+
if (error) {
|
|
260
|
+
reject(new Error(`podman rm failed: ${error.message}`));
|
|
261
|
+
} else {
|
|
262
|
+
resolve();
|
|
263
|
+
}
|
|
249
264
|
}
|
|
250
|
-
|
|
265
|
+
);
|
|
251
266
|
});
|
|
252
267
|
}
|
|
253
268
|
};
|
|
@@ -255,7 +270,7 @@ var podman = (options) => {
|
|
|
255
270
|
}
|
|
256
271
|
});
|
|
257
272
|
};
|
|
258
|
-
var checkImageExists = (imageName) => new Promise((resolve, reject) => {
|
|
273
|
+
var checkImageExists = async (imageName) => new Promise((resolve, reject) => {
|
|
259
274
|
execFile("podman", ["image", "inspect", imageName], (error) => {
|
|
260
275
|
if (error) {
|
|
261
276
|
reject(
|
|
@@ -271,7 +286,7 @@ var checkImageExists = (imageName) => new Promise((resolve, reject) => {
|
|
|
271
286
|
var podmanMachineError = () => new Error(
|
|
272
287
|
"Podman Machine is not running. Run 'podman machine init && podman machine start' first."
|
|
273
288
|
);
|
|
274
|
-
var checkPodmanMachine = () => new Promise((resolve, reject) => {
|
|
289
|
+
var checkPodmanMachine = async () => new Promise((resolve, reject) => {
|
|
275
290
|
execFile(
|
|
276
291
|
"podman",
|
|
277
292
|
["machine", "list", "--format", "json"],
|
|
@@ -281,8 +296,8 @@ var checkPodmanMachine = () => new Promise((resolve, reject) => {
|
|
|
281
296
|
return;
|
|
282
297
|
}
|
|
283
298
|
try {
|
|
284
|
-
const machines = JSON.parse(stdout
|
|
285
|
-
if (machines.some((m) => m
|
|
299
|
+
const machines = JSON.parse(stdout);
|
|
300
|
+
if (Array.isArray(machines) && machines.some((m) => isRunningMachine(m))) {
|
|
286
301
|
resolve();
|
|
287
302
|
} else {
|
|
288
303
|
reject(podmanMachineError());
|
|
@@ -293,6 +308,7 @@ var checkPodmanMachine = () => new Promise((resolve, reject) => {
|
|
|
293
308
|
}
|
|
294
309
|
);
|
|
295
310
|
});
|
|
311
|
+
var isRunningMachine = (machine) => typeof machine === "object" && machine !== null && "Running" in machine && machine.Running === true;
|
|
296
312
|
|
|
297
313
|
export { podman };
|
|
298
314
|
//# 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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F;AACA,MAAA,IAAI;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-8\"), 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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A,IACE,KAAA,CAAM,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-Chsi-Zs6.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 };
|