@ai-hero/sandcastle 0.13.0 → 0.14.1
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 +3 -3
- package/dist/{SandboxProvider-YCL97qco.d.ts → SandboxProvider-CwRLxIXZ.d.ts} +5 -41
- package/dist/{chunk-XCYK7I45.js → chunk-4BB7DNPW.js} +3 -3
- package/dist/chunk-4BB7DNPW.js.map +1 -0
- package/dist/chunk-4GZMUHVO.js +60 -0
- package/dist/chunk-4GZMUHVO.js.map +1 -0
- package/dist/{chunk-A4C2FG74.js → chunk-7JUTKCHL.js} +43 -42
- package/dist/chunk-7JUTKCHL.js.map +1 -0
- package/dist/chunk-7PHPLDVS.js +284 -0
- package/dist/chunk-7PHPLDVS.js.map +1 -0
- package/dist/{chunk-NMQ5Z6YG.js → chunk-BXLS4HRY.js} +15 -4
- package/dist/chunk-BXLS4HRY.js.map +1 -0
- package/dist/chunk-EM4QNWKF.js +3161 -0
- package/dist/chunk-EM4QNWKF.js.map +1 -0
- package/dist/chunk-EXYXBRCX.js +60 -0
- package/dist/chunk-EXYXBRCX.js.map +1 -0
- package/dist/{chunk-LWNC4UTZ.js → chunk-JEQ4IVQM.js} +1520 -5375
- package/dist/chunk-JEQ4IVQM.js.map +1 -0
- package/dist/{chunk-XCWKLDH4.js → chunk-L3BU47F6.js} +3 -3
- package/dist/{chunk-XCWKLDH4.js.map → chunk-L3BU47F6.js.map} +1 -1
- package/dist/{chunk-7N7AMUYA.js → chunk-PTJEKJPQ.js} +7 -5
- package/dist/chunk-PTJEKJPQ.js.map +1 -0
- package/dist/chunk-SAQXFLO2.js +1268 -0
- package/dist/chunk-SAQXFLO2.js.map +1 -0
- package/dist/{chunk-767EAJVT.js → chunk-TBVRAXYF.js} +3 -3
- package/dist/{chunk-767EAJVT.js.map → chunk-TBVRAXYF.js.map} +1 -1
- package/dist/{chunk-J5J5YJ5S.js → chunk-VUOXFCWO.js} +3 -3
- package/dist/{chunk-J5J5YJ5S.js.map → chunk-VUOXFCWO.js.map} +1 -1
- package/dist/{chunk-U42XXICG.js → chunk-WYOGXC72.js} +47 -82
- package/dist/chunk-WYOGXC72.js.map +1 -0
- package/dist/chunk-YDQW5IOY.js +799 -0
- package/dist/chunk-YDQW5IOY.js.map +1 -0
- package/dist/index.d.ts +51 -4
- package/dist/index.js +892 -2018
- package/dist/index.js.map +1 -1
- package/dist/main.js +322 -251
- package/dist/main.js.map +1 -1
- package/dist/sandboxes/bwrap.d.ts +1 -1
- package/dist/sandboxes/bwrap.js +9 -14
- package/dist/sandboxes/bwrap.js.map +1 -1
- package/dist/sandboxes/daytona.d.ts +1 -1
- package/dist/sandboxes/daytona.js +183 -136
- package/dist/sandboxes/daytona.js.map +1 -1
- package/dist/sandboxes/docker.d.ts +23 -1
- package/dist/sandboxes/docker.js +7 -3
- 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 +1 -1
- package/dist/sandboxes/podman.d.ts +27 -4
- package/dist/sandboxes/podman.js +19 -43
- package/dist/sandboxes/podman.js.map +1 -1
- package/dist/sandboxes/seatbelt.d.ts +2 -2
- package/dist/sandboxes/seatbelt.js +10 -7
- package/dist/sandboxes/seatbelt.js.map +1 -1
- package/dist/sandboxes/sprites.d.ts +54 -0
- package/dist/sandboxes/sprites.js +219 -0
- package/dist/sandboxes/sprites.js.map +1 -0
- package/dist/sandboxes/vercel.d.ts +10 -1
- package/dist/sandboxes/vercel.js +74 -46
- package/dist/sandboxes/vercel.js.map +1 -1
- package/dist/templates/parallel-planner/main.mts +43 -21
- package/dist/templates/parallel-planner-with-review/main.mts +55 -27
- package/dist/templates/sequential-reviewer/main.mts +1 -1
- package/package.json +36 -4
- package/dist/chunk-4EIVTSOZ.js +0 -93
- package/dist/chunk-4EIVTSOZ.js.map +0 -1
- package/dist/chunk-7N7AMUYA.js.map +0 -1
- package/dist/chunk-A4C2FG74.js.map +0 -1
- package/dist/chunk-LWNC4UTZ.js.map +0 -1
- package/dist/chunk-NMQ5Z6YG.js.map +0 -1
- package/dist/chunk-U42XXICG.js.map +0 -1
- package/dist/chunk-XCYK7I45.js.map +0 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { createIsolatedSandboxProvider } from '../chunk-4BB7DNPW.js';
|
|
3
|
+
import { MAX_TAIL_CHARS, BoundedTail } from '../chunk-6NQPCXSG.js';
|
|
4
|
+
import { stat, readdir } from 'fs/promises';
|
|
5
|
+
import { relative, sep, posix, join } from 'path';
|
|
6
|
+
|
|
7
|
+
createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// src/sandboxes/modalExec.ts
|
|
10
|
+
var forEachLine = async (stream, onLine) => {
|
|
11
|
+
let partial = "";
|
|
12
|
+
for await (const chunk of stream) {
|
|
13
|
+
const lines = (partial + chunk).split("\n");
|
|
14
|
+
partial = lines.pop() ?? "";
|
|
15
|
+
for (const line of lines) {
|
|
16
|
+
onLine(line);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (partial !== "") {
|
|
20
|
+
onLine(partial);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var drainInto = async (stream, tail) => {
|
|
24
|
+
for await (const chunk of stream) {
|
|
25
|
+
tail.push(chunk);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var feedStdin = async (proc, stdin) => {
|
|
29
|
+
if (stdin !== void 0 && stdin !== "") {
|
|
30
|
+
await proc.stdin.writeText(stdin);
|
|
31
|
+
}
|
|
32
|
+
await proc.stdin.close();
|
|
33
|
+
};
|
|
34
|
+
var collectStreamed = async (proc, onLine, maxOutputTailChars) => {
|
|
35
|
+
const stdoutTail = new BoundedTail(maxOutputTailChars, "\n");
|
|
36
|
+
const stderrTail = new BoundedTail(maxOutputTailChars, "");
|
|
37
|
+
await Promise.all([
|
|
38
|
+
forEachLine(proc.stdout, (line) => {
|
|
39
|
+
stdoutTail.push(line);
|
|
40
|
+
onLine(line);
|
|
41
|
+
}),
|
|
42
|
+
drainInto(proc.stderr, stderrTail)
|
|
43
|
+
]);
|
|
44
|
+
const exitCode = await proc.wait();
|
|
45
|
+
return {
|
|
46
|
+
stdout: stdoutTail.toString(),
|
|
47
|
+
stderr: stderrTail.toString(),
|
|
48
|
+
exitCode
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
var collectBuffered = async (proc) => {
|
|
52
|
+
const [stdout, stderr] = await Promise.all([
|
|
53
|
+
proc.stdout.readText(),
|
|
54
|
+
proc.stderr.readText()
|
|
55
|
+
]);
|
|
56
|
+
const exitCode = await proc.wait();
|
|
57
|
+
return { stdout, stderr, exitCode };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/sandboxes/modal.ts
|
|
61
|
+
var MODAL_REPO_PATH = "/workspace";
|
|
62
|
+
var DEFAULT_APP_NAME = "sandcastle";
|
|
63
|
+
var DEFAULT_TIMEOUT_MS = 60 * 60 * 1e3;
|
|
64
|
+
var DEFAULT_BASE_IMAGE = "node:24-bookworm";
|
|
65
|
+
var DEFAULT_IMAGE_COMMANDS = [
|
|
66
|
+
"RUN npm install -g @anthropic-ai/claude-code && npm cache clean --force"
|
|
67
|
+
];
|
|
68
|
+
var toClientParams = (options) => Object.fromEntries(
|
|
69
|
+
Object.entries({
|
|
70
|
+
tokenId: options?.tokenId,
|
|
71
|
+
tokenSecret: options?.tokenSecret,
|
|
72
|
+
environment: options?.environment
|
|
73
|
+
}).filter(([, value]) => value !== void 0 && value !== "")
|
|
74
|
+
);
|
|
75
|
+
var toImage = (client, image) => {
|
|
76
|
+
if (typeof image === "string" && image !== "") {
|
|
77
|
+
return client.images.fromRegistry(image);
|
|
78
|
+
}
|
|
79
|
+
if (image !== void 0 && typeof image !== "string") {
|
|
80
|
+
return image;
|
|
81
|
+
}
|
|
82
|
+
return client.images.fromRegistry(DEFAULT_BASE_IMAGE).dockerfileCommands(DEFAULT_IMAGE_COMMANDS);
|
|
83
|
+
};
|
|
84
|
+
var listFiles = async (dir) => {
|
|
85
|
+
const entries = await readdir(dir, { withFileTypes: true, recursive: true });
|
|
86
|
+
return entries.filter((entry) => !entry.isDirectory()).map((entry) => join(entry.parentPath, entry.name));
|
|
87
|
+
};
|
|
88
|
+
var copyIn = async (sandbox, hostPath, sandboxPath) => {
|
|
89
|
+
const info = await stat(hostPath);
|
|
90
|
+
if (!info.isDirectory()) {
|
|
91
|
+
await sandbox.filesystem.copyFromLocal(hostPath, sandboxPath);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await sandbox.filesystem.makeDirectory(sandboxPath);
|
|
95
|
+
const files = await listFiles(hostPath);
|
|
96
|
+
await files.reduce(async (previous, file) => {
|
|
97
|
+
await previous;
|
|
98
|
+
const rel = relative(hostPath, file).split(sep).join("/");
|
|
99
|
+
await sandbox.filesystem.copyFromLocal(file, posix.join(sandboxPath, rel));
|
|
100
|
+
}, Promise.resolve());
|
|
101
|
+
};
|
|
102
|
+
var setUpOrTerminate = async (sandbox) => {
|
|
103
|
+
try {
|
|
104
|
+
await sandbox.filesystem.makeDirectory(MODAL_REPO_PATH);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
await sandbox.terminate().catch(() => void 0);
|
|
107
|
+
throw new Error(
|
|
108
|
+
`modal(): could not create ${MODAL_REPO_PATH}: ${error instanceof Error ? error.message : String(error)}`,
|
|
109
|
+
{ cause: error }
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var makeHandle = (client, sandbox, maxOutputTailChars) => ({
|
|
114
|
+
worktreePath: MODAL_REPO_PATH,
|
|
115
|
+
sandboxId: sandbox.sandboxId,
|
|
116
|
+
// Commands already run as root, so `sudo` needs nothing more.
|
|
117
|
+
exec: async (command, opts) => {
|
|
118
|
+
const proc = await sandbox.exec(["sh", "-c", command], {
|
|
119
|
+
workdir: opts?.cwd ?? MODAL_REPO_PATH
|
|
120
|
+
});
|
|
121
|
+
await feedStdin(proc, opts?.stdin);
|
|
122
|
+
return opts?.onLine ? collectStreamed(proc, opts.onLine, maxOutputTailChars) : collectBuffered(proc);
|
|
123
|
+
},
|
|
124
|
+
copyIn: async (hostPath, sandboxPath) => copyIn(sandbox, hostPath, sandboxPath),
|
|
125
|
+
copyFileOut: async (sandboxPath, hostPath) => sandbox.filesystem.copyToLocal(sandboxPath, hostPath),
|
|
126
|
+
close: async () => {
|
|
127
|
+
try {
|
|
128
|
+
await sandbox.terminate();
|
|
129
|
+
} finally {
|
|
130
|
+
client.close();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
var modal = (options) => createIsolatedSandboxProvider({
|
|
135
|
+
name: "modal",
|
|
136
|
+
// Modal runs every command as root, where Claude Code refuses
|
|
137
|
+
// --dangerously-skip-permissions unless it knows it is in a sandbox.
|
|
138
|
+
env: { IS_SANDBOX: "1", ...options?.env },
|
|
139
|
+
create: async (createOptions) => {
|
|
140
|
+
const { ModalClient } = await import('modal');
|
|
141
|
+
const client = new ModalClient(toClientParams(options));
|
|
142
|
+
try {
|
|
143
|
+
const app = await client.apps.fromName(
|
|
144
|
+
options?.appName ?? DEFAULT_APP_NAME,
|
|
145
|
+
{ createIfMissing: true }
|
|
146
|
+
);
|
|
147
|
+
const sandbox = await client.sandboxes.create(
|
|
148
|
+
app,
|
|
149
|
+
toImage(client, options?.image),
|
|
150
|
+
{
|
|
151
|
+
...options?.create,
|
|
152
|
+
timeoutMs: options?.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
153
|
+
env: { ...createOptions.env, ...options?.create?.env }
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
await setUpOrTerminate(sandbox);
|
|
157
|
+
return makeHandle(
|
|
158
|
+
client,
|
|
159
|
+
sandbox,
|
|
160
|
+
options?.maxOutputTailChars ?? MAX_TAIL_CHARS
|
|
161
|
+
);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
client.close();
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
export { modal };
|
|
170
|
+
//# sourceMappingURL=modal.js.map
|
|
171
|
+
//# sourceMappingURL=modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/sandboxes/modalExec.ts","../../src/sandboxes/modal.ts"],"names":[],"mappings":";;;;;;;;;AAUA,IAAM,WAAA,GAAc,OAClB,MAAA,EACA,MAAA,KACkB;AAClB,EAAA,IAAI,OAAA,GAAU,EAAA;AACd,EAAA,WAAA,MAAiB,SAAS,MAAA,EAAQ;AAChC,IAAA,MAAM,KAAA,GAAA,CAAS,OAAA,GAAU,KAAA,EAAO,KAAA,CAAM,IAAI,CAAA;AAC1C,IAAA,OAAA,GAAU,KAAA,CAAM,KAAI,IAAK,EAAA;AACzB,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,MAAA,CAAO,IAAI,CAAA;AAAA,IACb;AAAA,EACF;AAEA,EAAA,IAAI,YAAY,EAAA,EAAI;AAClB,IAAA,MAAA,CAAO,OAAO,CAAA;AAAA,EAChB;AACF,CAAA;AAGA,IAAM,SAAA,GAAY,OAChB,MAAA,EACA,IAAA,KACkB;AAClB,EAAA,WAAA,MAAiB,SAAS,MAAA,EAAQ;AAChC,IAAA,IAAA,CAAK,KAAK,KAAK,CAAA;AAAA,EACjB;AACF,CAAA;AAGO,IAAM,SAAA,GAAY,OACvB,IAAA,EACA,KAAA,KACkB;AAClB,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,EAAA,EAAI;AACvC,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,KAAK,CAA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,MAAM,MAAA,GAAS,IAAI,WAAA,CAAY,cAAA,CAAe,OAAO,CAAC,CAAA;AACtD,IAAA,IAAI;AACF,MAAA,MAAM,GAAA,GAAM,MAAM,MAAA,CAAO,IAAA,CAAK,QAAA;AAAA,QAC5B,SAAS,OAAA,IAAW,gBAAA;AAAA,QACpB,EAAE,iBAAiB,IAAA;AAAK,OAC1B;AACA,MAAA,MAAM,OAAA,GAAU,MAAM,MAAA,CAAO,SAAA,CAAU,MAAA;AAAA,QACrC,GAAA;AAAA,QACA,OAAA,CAAQ,MAAA,EAAQ,OAAA,EAAS,KAAK,CAAA;AAAA,QAC9B;AAAA,UACE,GAAG,OAAA,EAAS,MAAA;AAAA,UACZ,SAAA,EAAW,SAAS,SAAA,IAAa,kBAAA;AAAA,UACjC,GAAA,EAAK,EAAE,GAAG,aAAA,CAAc,KAAK,GAAG,OAAA,EAAS,QAAQ,GAAA;AAAI;AACvD,OACF;AACA,MAAA,MAAM,iBAAiB,OAAO,CAAA;AAC9B,MAAA,OAAO,UAAA;AAAA,QACL,MAAA;AAAA,QACA,OAAA;AAAA,QACA,SAAS,kBAAA,IAAsB;AAAA,OACjC;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,MAAA,CAAO,KAAA,EAAM;AACb,MAAA,MAAM,KAAA;AAAA,IACR;AAAA,EACF;AACF,CAAC","file":"modal.js","sourcesContent":["/**\n * Waiting on a command in a Modal sandbox: stdin, streamed or buffered\n * output, and the exit code. Used by `modal()` only.\n */\n\nimport type { ExecResult } from \"../SandboxProvider.js\";\nimport { BoundedTail } from \"../boundedTail.js\";\nimport type { ContainerProcess } from \"modal\";\n\n/** Read a text stream to its end, handing each line to `onLine`. */\nconst forEachLine = async (\n stream: ReadableStream<string>,\n onLine: (line: string) => void,\n): Promise<void> => {\n let partial = \"\";\n for await (const chunk of stream) {\n const lines = (partial + chunk).split(\"\\n\");\n partial = lines.pop() ?? \"\";\n for (const line of lines) {\n onLine(line);\n }\n }\n // A last line with no trailing newline is still a line.\n if (partial !== \"\") {\n onLine(partial);\n }\n};\n\n/** Read a text stream to its end, keeping a bounded tail of it. */\nconst drainInto = async (\n stream: ReadableStream<string>,\n tail: BoundedTail,\n): Promise<void> => {\n for await (const chunk of stream) {\n tail.push(chunk);\n }\n};\n\n/** Pipe `stdin` (if any) to the process, then close it so it reads EOF. */\nexport const feedStdin = async (\n proc: ContainerProcess<string>,\n stdin: string | undefined,\n): Promise<void> => {\n if (stdin !== undefined && stdin !== \"\") {\n await proc.stdin.writeText(stdin);\n }\n await proc.stdin.close();\n};\n\n/** Wait for a process, streaming its stdout lines to `onLine`. */\nexport const collectStreamed = async (\n proc: ContainerProcess<string>,\n onLine: (line: string) => void,\n maxOutputTailChars: number,\n): Promise<ExecResult> => {\n const stdoutTail = new BoundedTail(maxOutputTailChars, \"\\n\");\n const stderrTail = new BoundedTail(maxOutputTailChars, \"\");\n await Promise.all([\n forEachLine(proc.stdout, (line) => {\n stdoutTail.push(line);\n onLine(line);\n }),\n drainInto(proc.stderr, stderrTail),\n ]);\n const exitCode = await proc.wait();\n return {\n stdout: stdoutTail.toString(),\n stderr: stderrTail.toString(),\n exitCode,\n };\n};\n\n/** Wait for a process and return its whole output. */\nexport const collectBuffered = async (\n proc: ContainerProcess<string>,\n): Promise<ExecResult> => {\n const [stdout, stderr] = await Promise.all([\n proc.stdout.readText(),\n proc.stderr.readText(),\n ]);\n const exitCode = await proc.wait();\n return { stdout, stderr, exitCode };\n};\n","/**\n * Modal isolated sandbox provider — wraps the `modal` SDK into a SandboxProvider.\n *\n * Usage:\n * import { modal } from \"@ai-hero/sandcastle/sandboxes/modal\";\n * await run({ agent: claudeCode(\"claude-opus-4-8\"), sandbox: modal() });\n */\n\nimport { readdir, stat } from \"node:fs/promises\";\nimport { join, posix, relative, sep } from \"node:path\";\nimport { createIsolatedSandboxProvider } from \"../SandboxProvider.js\";\nimport type {\n ExecResult,\n IsolatedSandboxHandle,\n IsolatedSandboxProvider,\n} from \"../SandboxProvider.js\";\nimport { MAX_TAIL_CHARS } from \"../boundedTail.js\";\nimport { collectBuffered, collectStreamed, feedStdin } from \"./modalExec.js\";\nimport type {\n Image,\n ModalClient,\n ModalClientParams,\n Sandbox,\n SandboxCreateParams,\n} from \"modal\";\n\n/** Worktree path inside the Modal sandbox. Its parent, `/`, is root's. */\nconst MODAL_REPO_PATH = \"/workspace\";\n\n/** The Modal App sandboxes are created in, unless `appName` says otherwise. */\nconst DEFAULT_APP_NAME = \"sandcastle\";\n\n/** The sandbox's lifetime unless `timeoutMs` says otherwise: one hour. */\nconst DEFAULT_TIMEOUT_MS = 60 * 60 * 1000;\n\n/** The registry image the default image is built on: Node LTS, with git. */\nconst DEFAULT_BASE_IMAGE = \"node:24-bookworm\";\n\n/** Installs Claude Code into the default image. */\nconst DEFAULT_IMAGE_COMMANDS = [\n \"RUN npm install -g @anthropic-ai/claude-code && npm cache clean --force\",\n];\n\n/** Options for the Modal sandbox provider. */\nexport interface ModalOptions {\n /**\n * Modal token id. Falls back to the `MODAL_TOKEN_ID` environment variable,\n * then to `~/.modal.toml` (written by `modal token new`).\n */\n readonly tokenId?: string;\n\n /**\n * Modal token secret. Falls back to the `MODAL_TOKEN_SECRET` environment\n * variable, then to `~/.modal.toml`.\n */\n readonly tokenSecret?: string;\n\n /**\n * Modal environment to create sandboxes in. Falls back to\n * `MODAL_ENVIRONMENT`, then to the profile's default.\n */\n readonly environment?: string;\n\n /**\n * Name of the Modal App the sandboxes belong to (default: `\"sandcastle\"`).\n * It is created if it does not exist; no deploy step is needed.\n */\n readonly appName?: string;\n\n /**\n * The sandbox image: a registry tag such as `\"node:24-bookworm\"`, or a\n * Modal `Image` you built yourself (e.g. with `dockerfileCommands`).\n *\n * Omit it for Sandcastle's default: `node:24-bookworm` (Node LTS, git, tar)\n * with Claude Code installed. Any other image must have `sh`, `git` and\n * your agent's CLI, or install the CLI in an `onSandboxReady` hook.\n *\n * Modal runs every command as root, whatever the image's `USER`.\n */\n readonly image?: string | Image;\n\n /**\n * Maximum lifetime of the sandbox in milliseconds (default: one hour,\n * Modal's own default is 5 minutes). Modal can't extend it after create,\n * so set it above your longest run. Modal allows up to 24 hours.\n */\n readonly timeoutMs?: number;\n\n /**\n * Other `sandboxes.create()` options, passed through to Modal (`cpu`,\n * `memoryMiB`, `regions`, `blockNetwork`, …). Its `env` wins over the\n * env Sandcastle resolves.\n */\n readonly create?: Omit<SandboxCreateParams, \"timeoutMs\">;\n\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 /**\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\n/** The `ModalClient` params: only the connection options that are set. */\nconst toClientParams = (options: ModalOptions | undefined): ModalClientParams =>\n Object.fromEntries(\n Object.entries({\n tokenId: options?.tokenId,\n tokenSecret: options?.tokenSecret,\n environment: options?.environment,\n }).filter(([, value]) => value !== undefined && value !== \"\"),\n );\n\n/** The image to create the sandbox from. */\nconst toImage = (\n client: ModalClient,\n image: string | Image | undefined,\n): Image => {\n if (typeof image === \"string\" && image !== \"\") {\n return client.images.fromRegistry(image);\n }\n if (image !== undefined && typeof image !== \"string\") {\n return image;\n }\n return client.images\n .fromRegistry(DEFAULT_BASE_IMAGE)\n .dockerfileCommands(DEFAULT_IMAGE_COMMANDS);\n};\n\n/** Every file under a host directory, recursively. */\nconst listFiles = async (dir: string): Promise<string[]> => {\n const entries = await readdir(dir, { withFileTypes: true, recursive: true });\n return entries\n .filter((entry) => !entry.isDirectory())\n .map((entry) => join(entry.parentPath, entry.name));\n};\n\n/** Copy a host file or directory into the sandbox. */\nconst copyIn = async (\n sandbox: Sandbox,\n hostPath: string,\n sandboxPath: string,\n): Promise<void> => {\n const info = await stat(hostPath);\n if (!info.isDirectory()) {\n await sandbox.filesystem.copyFromLocal(hostPath, sandboxPath);\n return;\n }\n await sandbox.filesystem.makeDirectory(sandboxPath);\n const files = await listFiles(hostPath);\n // One file at a time: each copy is its own exec in the sandbox.\n await files.reduce(async (previous, file) => {\n await previous;\n const rel = relative(hostPath, file).split(sep).join(\"/\");\n await sandbox.filesystem.copyFromLocal(file, posix.join(sandboxPath, rel));\n }, Promise.resolve());\n};\n\n/**\n * Create the worktree folder in a sandbox `create()` has just made. If that\n * fails, terminate the sandbox before rethrowing: no handle exists yet, so\n * neither Sandcastle's teardown nor `close()` can reach it, and it would run\n * until its timeout.\n */\nconst setUpOrTerminate = async (sandbox: Sandbox): Promise<void> => {\n try {\n await sandbox.filesystem.makeDirectory(MODAL_REPO_PATH);\n } catch (error) {\n await sandbox.terminate().catch(() => undefined);\n throw new Error(\n `modal(): could not create ${MODAL_REPO_PATH}: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n};\n\n/** The Sandcastle handle over a Modal sandbox whose worktree folder exists. */\nconst makeHandle = (\n client: ModalClient,\n sandbox: Sandbox,\n maxOutputTailChars: number,\n): IsolatedSandboxHandle => ({\n worktreePath: MODAL_REPO_PATH,\n sandboxId: sandbox.sandboxId,\n\n // Commands already run as root, so `sudo` needs nothing more.\n exec: async (command, opts): Promise<ExecResult> => {\n const proc = await sandbox.exec([\"sh\", \"-c\", command], {\n workdir: opts?.cwd ?? MODAL_REPO_PATH,\n });\n await feedStdin(proc, opts?.stdin);\n return opts?.onLine\n ? collectStreamed(proc, opts.onLine, maxOutputTailChars)\n : collectBuffered(proc);\n },\n\n copyIn: async (hostPath, sandboxPath) =>\n copyIn(sandbox, hostPath, sandboxPath),\n\n copyFileOut: async (sandboxPath, hostPath) =>\n sandbox.filesystem.copyToLocal(sandboxPath, hostPath),\n\n close: async (): Promise<void> => {\n try {\n await sandbox.terminate();\n } finally {\n client.close();\n }\n },\n});\n\n/**\n * Create a Modal isolated sandbox provider.\n *\n * Each `create()` starts a new Modal sandbox via the `modal` SDK, and\n * `close()` terminates it. Requires `modal` to be installed as a peer\n * dependency.\n */\nexport const modal = (options?: ModalOptions): IsolatedSandboxProvider =>\n createIsolatedSandboxProvider({\n name: \"modal\",\n // Modal runs every command as root, where Claude Code refuses\n // --dangerously-skip-permissions unless it knows it is in a sandbox.\n env: { IS_SANDBOX: \"1\", ...options?.env },\n create: async (createOptions): Promise<IsolatedSandboxHandle> => {\n // Dynamic import so the peer dependency is only loaded at runtime\n const { ModalClient } = await import(\"modal\");\n const client = new ModalClient(toClientParams(options));\n try {\n const app = await client.apps.fromName(\n options?.appName ?? DEFAULT_APP_NAME,\n { createIfMissing: true },\n );\n const sandbox = await client.sandboxes.create(\n app,\n toImage(client, options?.image),\n {\n ...options?.create,\n timeoutMs: options?.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n env: { ...createOptions.env, ...options?.create?.env },\n },\n );\n await setUpOrTerminate(sandbox);\n return makeHandle(\n client,\n sandbox,\n options?.maxOutputTailChars ?? MAX_TAIL_CHARS,\n );\n } catch (error) {\n client.close();\n throw error;\n }\n },\n });\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SandboxProvider } from '../SandboxProvider-
|
|
1
|
+
import { S as SandboxProvider } from '../SandboxProvider-CwRLxIXZ.js';
|
|
2
2
|
import { M as MountConfig } from '../MountConfig-CmXclHA5.js';
|
|
3
3
|
import { S as SelinuxLabel, L as LinuxCapability } from '../LinuxCapability-B_PQfsY_.js';
|
|
4
4
|
export { d as defaultImageName } from '../LinuxCapability-B_PQfsY_.js';
|
|
@@ -82,12 +82,13 @@ interface PodmanOptions {
|
|
|
82
82
|
* Names are written without the `CAP_` prefix, as `podman run` accepts them,
|
|
83
83
|
* and a misspelt name is a type error:
|
|
84
84
|
*
|
|
85
|
-
* - `["
|
|
86
|
-
* - `["
|
|
85
|
+
* - `["CHOWN"]` → `--cap-drop CHOWN` (no changing file ownership)
|
|
86
|
+
* - `["CHOWN", "SETUID"]` → `--cap-drop CHOWN --cap-drop SETUID`
|
|
87
87
|
* - `["ALL"]` → `--cap-drop ALL` (drop every capability)
|
|
88
88
|
*
|
|
89
89
|
* When omitted, no `--cap-drop` flags are added and the container keeps
|
|
90
|
-
* Podman's default capability set.
|
|
90
|
+
* Podman's default capability set. Note that Podman's defaults already
|
|
91
|
+
* exclude `NET_RAW` and `MKNOD`, so dropping those has no effect.
|
|
91
92
|
*/
|
|
92
93
|
readonly capDrop?: readonly LinuxCapability[];
|
|
93
94
|
/**
|
|
@@ -124,6 +125,28 @@ interface PodmanOptions {
|
|
|
124
125
|
* When omitted, no `--cpus` flag is added and the container is unconstrained.
|
|
125
126
|
*/
|
|
126
127
|
readonly cpus?: number;
|
|
128
|
+
/**
|
|
129
|
+
* Limit the memory available to the container, via `--memory`.
|
|
130
|
+
*
|
|
131
|
+
* Accepts Podman memory strings:
|
|
132
|
+
*
|
|
133
|
+
* - `"2g"` → `--memory 2g --memory-swap 2g`
|
|
134
|
+
* - `"512m"` → `--memory 512m --memory-swap 512m`
|
|
135
|
+
*
|
|
136
|
+
* `--memory-swap` is set to the same value, making this a hard cap with no
|
|
137
|
+
* swap headroom. When omitted, no memory flags are added and the container
|
|
138
|
+
* is unconstrained.
|
|
139
|
+
*/
|
|
140
|
+
readonly memory?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Limit the number of processes in the container, via `--pids-limit`.
|
|
143
|
+
*
|
|
144
|
+
* - `256` → `--pids-limit 256`
|
|
145
|
+
*
|
|
146
|
+
* Useful against fork bombs in untrusted workloads. When omitted, no
|
|
147
|
+
* `--pids-limit` flag is added.
|
|
148
|
+
*/
|
|
149
|
+
readonly pidsLimit?: number;
|
|
127
150
|
}
|
|
128
151
|
/**
|
|
129
152
|
* Create a Podman sandbox provider.
|
package/dist/sandboxes/podman.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
2
|
+
import { shellArgsReportingExit, collectEngineExec } from '../chunk-4GZMUHVO.js';
|
|
3
|
+
import { resolveUserMounts, processFileMountParents, formatVolumeMount, defaultImageName } from '../chunk-7PHPLDVS.js';
|
|
4
|
+
export { defaultImageName } from '../chunk-7PHPLDVS.js';
|
|
5
|
+
import { registerShutdown } from '../chunk-EXYXBRCX.js';
|
|
6
|
+
import '../chunk-YDQW5IOY.js';
|
|
7
|
+
import '../chunk-JEQ4IVQM.js';
|
|
8
|
+
import { createBindMountSandboxProvider } from '../chunk-4BB7DNPW.js';
|
|
9
|
+
import { MAX_TAIL_CHARS } from '../chunk-6NQPCXSG.js';
|
|
6
10
|
import { execFile, execFileSync, spawn } from 'child_process';
|
|
7
11
|
import { randomUUID } from 'crypto';
|
|
8
|
-
import { createInterface } from 'readline';
|
|
9
12
|
|
|
10
13
|
createRequire(import.meta.url);
|
|
11
14
|
var podman = (options) => {
|
|
@@ -63,6 +66,8 @@ var podman = (options) => {
|
|
|
63
66
|
d
|
|
64
67
|
]);
|
|
65
68
|
const cpusArgs = options?.cpus === void 0 ? [] : ["--cpus", String(options.cpus)];
|
|
69
|
+
const memoryArgs = options?.memory === void 0 ? [] : ["--memory", options.memory, "--memory-swap", options.memory];
|
|
70
|
+
const pidsLimitArgs = options?.pidsLimit === void 0 ? [] : ["--pids-limit", String(options.pidsLimit)];
|
|
66
71
|
await new Promise((resolve, reject) => {
|
|
67
72
|
execFile(
|
|
68
73
|
"podman",
|
|
@@ -78,6 +83,8 @@ var podman = (options) => {
|
|
|
78
83
|
...capDropArgs,
|
|
79
84
|
...deviceArgs,
|
|
80
85
|
...cpusArgs,
|
|
86
|
+
...memoryArgs,
|
|
87
|
+
...pidsLimitArgs,
|
|
81
88
|
"-w",
|
|
82
89
|
worktreePath,
|
|
83
90
|
...envArgs,
|
|
@@ -150,7 +157,7 @@ var podman = (options) => {
|
|
|
150
157
|
if (opts?.cwd !== void 0 && opts.cwd !== "") {
|
|
151
158
|
args.push("-w", opts.cwd);
|
|
152
159
|
}
|
|
153
|
-
args.push(containerName,
|
|
160
|
+
args.push(containerName, ...shellArgsReportingExit(command));
|
|
154
161
|
return new Promise((resolve, reject) => {
|
|
155
162
|
const stdin = opts?.stdin;
|
|
156
163
|
const proc = stdin === void 0 ? spawn("podman", args, { stdio: ["ignore", "pipe", "pipe"] }) : spawn("podman", args, { stdio: ["pipe", "pipe", "pipe"] });
|
|
@@ -161,42 +168,11 @@ var podman = (options) => {
|
|
|
161
168
|
proc.on("error", (error) => {
|
|
162
169
|
reject(new Error(`podman exec failed: ${error.message}`));
|
|
163
170
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
rl.on("line", (line) => {
|
|
170
|
-
stdoutTail.push(line);
|
|
171
|
-
onLine(line);
|
|
172
|
-
});
|
|
173
|
-
proc.stderr.on("data", (chunk) => {
|
|
174
|
-
stderrTail.push(chunk.toString());
|
|
175
|
-
});
|
|
176
|
-
proc.on("close", (code) => {
|
|
177
|
-
resolve({
|
|
178
|
-
stdout: stdoutTail.toString(),
|
|
179
|
-
stderr: stderrTail.toString(),
|
|
180
|
-
exitCode: code ?? 0
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
} else {
|
|
184
|
-
const stdoutChunks = [];
|
|
185
|
-
const stderrChunks = [];
|
|
186
|
-
proc.stdout.on("data", (chunk) => {
|
|
187
|
-
stdoutChunks.push(chunk.toString());
|
|
188
|
-
});
|
|
189
|
-
proc.stderr.on("data", (chunk) => {
|
|
190
|
-
stderrChunks.push(chunk.toString());
|
|
191
|
-
});
|
|
192
|
-
proc.on("close", (code) => {
|
|
193
|
-
resolve({
|
|
194
|
-
stdout: stdoutChunks.join(""),
|
|
195
|
-
stderr: stderrChunks.join(""),
|
|
196
|
-
exitCode: code ?? 0
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
}
|
|
171
|
+
collectEngineExec(
|
|
172
|
+
proc,
|
|
173
|
+
{ onLine: opts?.onLine, maxOutputTailChars },
|
|
174
|
+
resolve
|
|
175
|
+
);
|
|
200
176
|
});
|
|
201
177
|
},
|
|
202
178
|
interactiveExec: async (args, opts) => new Promise((resolve, reject) => {
|
|
@@ -217,7 +193,7 @@ var podman = (options) => {
|
|
|
217
193
|
reject(new Error(`podman exec failed: ${error.message}`));
|
|
218
194
|
});
|
|
219
195
|
proc.on("close", (code) => {
|
|
220
|
-
resolve({ exitCode: code ??
|
|
196
|
+
resolve({ exitCode: code ?? 1 });
|
|
221
197
|
});
|
|
222
198
|
}),
|
|
223
199
|
copyFileIn: async (hostPath, sandboxPath) => new Promise((resolve, reject) => {
|
|
@@ -1 +1 @@
|
|
|
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,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,cAA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AA","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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/sandboxes/podman.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAuLO,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,aA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A,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 { createBindMountSandboxProvider } from \"../SandboxProvider.js\";\nimport {\n collectEngineExec,\n shellArgsReportingExit,\n} from \"./engineExitStatus.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 { 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 * - `[\"CHOWN\"]` → `--cap-drop CHOWN` (no changing file ownership)\n * - `[\"CHOWN\", \"SETUID\"]` → `--cap-drop CHOWN --cap-drop SETUID`\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. Note that Podman's defaults already\n * exclude `NET_RAW` and `MKNOD`, so dropping those has no effect.\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 * Limit the memory available to the container, via `--memory`.\n *\n * Accepts Podman memory strings:\n *\n * - `\"2g\"` → `--memory 2g --memory-swap 2g`\n * - `\"512m\"` → `--memory 512m --memory-swap 512m`\n *\n * `--memory-swap` is set to the same value, making this a hard cap with no\n * swap headroom. When omitted, no memory flags are added and the container\n * is unconstrained.\n */\n readonly memory?: string;\n /**\n * Limit the number of processes in the container, via `--pids-limit`.\n *\n * - `256` → `--pids-limit 256`\n *\n * Useful against fork bombs in untrusted workloads. When omitted, no\n * `--pids-limit` flag is added.\n */\n readonly pidsLimit?: 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 const memoryArgs =\n options?.memory === undefined\n ? []\n : [\"--memory\", options.memory, \"--memory-swap\", options.memory];\n const pidsLimitArgs =\n options?.pidsLimit === undefined\n ? []\n : [\"--pids-limit\", String(options.pidsLimit)];\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 ...memoryArgs,\n ...pidsLimitArgs,\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, ...shellArgsReportingExit(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 collectEngineExec(\n proc,\n { onLine: opts?.onLine, maxOutputTailChars },\n resolve,\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 ?? 1 });\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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BindMountSandboxProvider } from '../SandboxProvider-
|
|
1
|
+
import { B as BindMountSandboxProvider } from '../SandboxProvider-CwRLxIXZ.js';
|
|
2
2
|
import { M as MountConfig } from '../MountConfig-CmXclHA5.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -46,7 +46,7 @@ interface SeatbeltOptions {
|
|
|
46
46
|
* aside. It can't signal host processes, but Seatbelt can't fully hide them.
|
|
47
47
|
* The private home is exposed to Sandcastle as `/home/agent`: copies to and
|
|
48
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
|
|
49
|
+
* on close and on shutdown (SIGINT, SIGTERM, exit), and every process an `exec` started is killed when it exits, on
|
|
50
50
|
* close, on shutdown and when this Node process is hard-killed (a detached
|
|
51
51
|
* host watchdog per `exec` does that). The toolchain comes from the host
|
|
52
52
|
* `PATH`: each `PATH` dir (never the home dir or an ancestor of it) and the
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { NodeFileSystem_exports } from '../chunk-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
2
|
+
import { resolveIdentityMounts, registerNativeSandboxShutdown, copyCreatingParents, collectOutput, hostPathToolchainFromEnv } from '../chunk-BXLS4HRY.js';
|
|
3
|
+
import { markNativeSandboxProvider } from '../chunk-L3BU47F6.js';
|
|
4
|
+
import { assertSeatbeltUsable, SANDBOX_EXEC } from '../chunk-VUOXFCWO.js';
|
|
5
|
+
import { NodeFileSystem_exports } from '../chunk-7JUTKCHL.js';
|
|
6
|
+
import '../chunk-7PHPLDVS.js';
|
|
7
|
+
import '../chunk-EXYXBRCX.js';
|
|
8
|
+
import { FileSystem_exports, SeatbeltError } from '../chunk-YDQW5IOY.js';
|
|
9
|
+
import { Effect_exports, Option_exports } from '../chunk-JEQ4IVQM.js';
|
|
10
|
+
import { createBindMountSandboxProvider } from '../chunk-4BB7DNPW.js';
|
|
8
11
|
import { MAX_TAIL_CHARS } from '../chunk-6NQPCXSG.js';
|
|
9
12
|
import { spawn } from 'child_process';
|
|
10
13
|
import { once } from 'events';
|
|
@@ -369,7 +372,7 @@ var createHandle = async (options, config) => {
|
|
|
369
372
|
killGroup(proc);
|
|
370
373
|
}
|
|
371
374
|
};
|
|
372
|
-
const unregisterShutdown =
|
|
375
|
+
const unregisterShutdown = registerNativeSandboxShutdown(killAll, dirs);
|
|
373
376
|
let closed = false;
|
|
374
377
|
const hostPathOf = (p) => toHostPath(p, dirs, options.mounts);
|
|
375
378
|
return {
|