@clearideas/agent-runtime-sandbox 0.5.0 → 0.6.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 +20 -2
- package/assets/agent-fs.py +555 -0
- package/dist/bubblewrap.d.ts +59 -0
- package/dist/bubblewrap.js +408 -0
- package/dist/contracts.d.ts +21 -0
- package/dist/contracts.js +3 -0
- package/dist/docker.d.ts +3 -1
- package/dist/docker.js +31 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/policy.d.ts +114 -0
- package/dist/policy.js +649 -0
- package/dist/run-sandbox.d.ts +69 -0
- package/dist/run-sandbox.js +852 -0
- package/dist/testing/host-process-provider.d.ts +28 -0
- package/dist/testing/host-process-provider.js +153 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +1 -0
- package/package.json +8 -3
|
@@ -0,0 +1,852 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { isSafeWorkspacePath } from "@clearideas/agent-runtime-core";
|
|
6
|
+
import { assertSandboxPath, assertSandboxResourceLimits, } from "./contracts.js";
|
|
7
|
+
import { DEFAULT_HELPER_COMMAND, SANDBOX_HELPER_PATH, SANDBOX_MOUNT_DIRECTORY, SANDBOX_OUTPUT_DIRECTORY, SANDBOX_WORKSPACES_FILE, SandboxPolicyError, admitCommand, describeWorkspaceTools, resolveRunSandboxPolicy, } from "./policy.js";
|
|
8
|
+
const HELPER_PROTOCOL_VERSION = 1;
|
|
9
|
+
const STAGING_BATCH_BYTES = 4 * 1024 * 1024;
|
|
10
|
+
const MAXIMUM_HELPER_OUTPUT_BYTES = 1_048_576;
|
|
11
|
+
const CLOSE_SYNC_TIMEOUT_MS = 30_000;
|
|
12
|
+
const OUTPUT_PLACEHOLDER = ".agent-runtime-output";
|
|
13
|
+
const defaultProfiles = [
|
|
14
|
+
{
|
|
15
|
+
language: "python",
|
|
16
|
+
image: "python:3.12-slim",
|
|
17
|
+
extension: "py",
|
|
18
|
+
command: "python3",
|
|
19
|
+
args: (sourcePath) => [sourcePath],
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
export const bundledHelperPath = () => fileURLToPath(new URL("../assets/agent-fs.py", import.meta.url));
|
|
23
|
+
const sha256 = (data) => createHash("sha256").update(data).digest("hex");
|
|
24
|
+
const appendBounded = (chunks, state, chunk, maximum) => {
|
|
25
|
+
const bytes = Buffer.byteLength(chunk);
|
|
26
|
+
if (state.truncated)
|
|
27
|
+
return;
|
|
28
|
+
if (state.bytes + bytes > maximum) {
|
|
29
|
+
const remaining = Math.max(0, maximum - state.bytes);
|
|
30
|
+
chunks.push(Buffer.from(chunk).subarray(0, remaining).toString("utf8"));
|
|
31
|
+
state.bytes = maximum;
|
|
32
|
+
state.truncated = true;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
chunks.push(chunk);
|
|
36
|
+
state.bytes += bytes;
|
|
37
|
+
};
|
|
38
|
+
const isJsonObject = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
39
|
+
class RunSandboxExecutionError extends Error {
|
|
40
|
+
code;
|
|
41
|
+
constructor(code, message) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.name = "RunSandboxExecutionError";
|
|
44
|
+
this.code = code;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Opens one provider-backed sandbox per run attempt, stages bound
|
|
49
|
+
* workspaces, executes every workspace command under the host policy, syncs
|
|
50
|
+
* read-write mounts back to their stores after each command, and reports
|
|
51
|
+
* everything through run events and command records.
|
|
52
|
+
*/
|
|
53
|
+
export class ProviderRunSandbox {
|
|
54
|
+
#options;
|
|
55
|
+
#policy;
|
|
56
|
+
#helperCommand;
|
|
57
|
+
#helperSource;
|
|
58
|
+
#profiles;
|
|
59
|
+
#now;
|
|
60
|
+
constructor(options) {
|
|
61
|
+
if (!options.image.trim())
|
|
62
|
+
throw new Error("Run sandbox requires an image.");
|
|
63
|
+
this.#options = options;
|
|
64
|
+
this.#policy = resolveRunSandboxPolicy({
|
|
65
|
+
...(options.commands ? { commands: options.commands } : {}),
|
|
66
|
+
...(options.shell ? { shell: options.shell } : {}),
|
|
67
|
+
...(options.limits ? { limits: options.limits } : {}),
|
|
68
|
+
});
|
|
69
|
+
this.#helperCommand = options.helper?.command ?? DEFAULT_HELPER_COMMAND;
|
|
70
|
+
if (this.#helperCommand.length === 0)
|
|
71
|
+
throw new Error("Run sandbox helper command cannot be empty.");
|
|
72
|
+
this.#helperSource = options.helper?.source ?? bundledHelperPath();
|
|
73
|
+
this.#profiles = new Map((options.profiles ?? defaultProfiles).map((profile) => [
|
|
74
|
+
profile.language,
|
|
75
|
+
profile,
|
|
76
|
+
]));
|
|
77
|
+
this.#now = options.now ?? (() => new Date());
|
|
78
|
+
}
|
|
79
|
+
get policy() {
|
|
80
|
+
return this.#policy;
|
|
81
|
+
}
|
|
82
|
+
async tools(workspace) {
|
|
83
|
+
return describeWorkspaceTools(workspace, this.#policy);
|
|
84
|
+
}
|
|
85
|
+
async validate(request) {
|
|
86
|
+
await readFile(this.#helperSource).catch((error) => {
|
|
87
|
+
throw new Error(`Run sandbox helper is not readable at ${this.#helperSource}: ${error instanceof Error ? error.message : String(error)}`);
|
|
88
|
+
});
|
|
89
|
+
const spec = this.#spec(request.runId, []);
|
|
90
|
+
assertSandboxResourceLimits(spec.limits);
|
|
91
|
+
await this.#options.provider.validate?.(spec, request.signal ? { signal: request.signal } : undefined);
|
|
92
|
+
let total = 0;
|
|
93
|
+
for (const workspace of request.workspaces) {
|
|
94
|
+
if (this.#canAttach(workspace))
|
|
95
|
+
continue;
|
|
96
|
+
const entries = await workspace.store.entries(request.signal ? { signal: request.signal } : undefined);
|
|
97
|
+
const bytes = entries.reduce((sum, entry) => sum + entry.size, 0);
|
|
98
|
+
this.#assertStagingLimits(workspace, entries.length, bytes);
|
|
99
|
+
total += bytes;
|
|
100
|
+
}
|
|
101
|
+
if (total > this.#policy.limits.maxTotalStagedBytes) {
|
|
102
|
+
throw new Error(`Bound workspaces total ${total} bytes, exceeding the ${this.#policy.limits.maxTotalStagedBytes}-byte sandbox staging limit.`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async open(request) {
|
|
106
|
+
const mounts = [];
|
|
107
|
+
const attachments = [];
|
|
108
|
+
const aliases = new Set();
|
|
109
|
+
for (const workspace of request.workspaces) {
|
|
110
|
+
if (aliases.has(workspace.alias))
|
|
111
|
+
throw new Error(`Duplicate workspace alias: ${workspace.alias}`);
|
|
112
|
+
aliases.add(workspace.alias);
|
|
113
|
+
const directory = assertSandboxPath(`${SANDBOX_MOUNT_DIRECTORY}/${workspace.alias}`);
|
|
114
|
+
const attached = this.#canAttach(workspace);
|
|
115
|
+
if (attached) {
|
|
116
|
+
attachments.push({
|
|
117
|
+
source: workspace.store.attachable.root,
|
|
118
|
+
target: directory,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
mounts.push({
|
|
122
|
+
workspace,
|
|
123
|
+
directory,
|
|
124
|
+
attached,
|
|
125
|
+
fileCount: 0,
|
|
126
|
+
bytes: 0,
|
|
127
|
+
baseline: new Map(),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const spec = this.#spec(request.runId, attachments);
|
|
131
|
+
const handle = await this.#options.provider.create(spec, request.signal ? { signal: request.signal } : undefined);
|
|
132
|
+
const session = new ProviderRunSandboxSession({
|
|
133
|
+
handle,
|
|
134
|
+
provider: this.#options.provider,
|
|
135
|
+
policy: this.#policy,
|
|
136
|
+
helperCommand: this.#helperCommand,
|
|
137
|
+
profiles: this.#profiles,
|
|
138
|
+
allowedEnvironment: new Set(this.#options.allowedEnvironment ?? []),
|
|
139
|
+
hooks: this.#options,
|
|
140
|
+
request,
|
|
141
|
+
mounts,
|
|
142
|
+
image: spec.image,
|
|
143
|
+
now: this.#now,
|
|
144
|
+
});
|
|
145
|
+
try {
|
|
146
|
+
await session.stage(await readFile(this.#helperSource));
|
|
147
|
+
await this.#options.authorizeSandbox?.({
|
|
148
|
+
runId: request.runId,
|
|
149
|
+
attempt: request.attempt,
|
|
150
|
+
image: spec.image,
|
|
151
|
+
mounts: mounts.map((mount) => ({
|
|
152
|
+
alias: mount.workspace.alias,
|
|
153
|
+
mode: mount.workspace.mode,
|
|
154
|
+
...(mount.attached ? {} : { fileCount: mount.fileCount }),
|
|
155
|
+
attached: mount.attached,
|
|
156
|
+
})),
|
|
157
|
+
});
|
|
158
|
+
await request.emit("sandbox.opened", {
|
|
159
|
+
sandboxId: handle.id,
|
|
160
|
+
image: spec.image,
|
|
161
|
+
provider: this.#options.provider.name,
|
|
162
|
+
mounts: mounts.map((mount) => ({
|
|
163
|
+
alias: mount.workspace.alias,
|
|
164
|
+
mode: mount.workspace.mode,
|
|
165
|
+
...(mount.attached
|
|
166
|
+
? {}
|
|
167
|
+
: { fileCount: mount.fileCount, bytes: mount.bytes }),
|
|
168
|
+
attached: mount.attached,
|
|
169
|
+
})),
|
|
170
|
+
helper: { command: [...this.#helperCommand] },
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
await this.#options.provider.terminate(handle).catch(() => undefined);
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
return session;
|
|
178
|
+
}
|
|
179
|
+
#canAttach(workspace) {
|
|
180
|
+
return ((this.#options.attach ?? "auto") === "auto" &&
|
|
181
|
+
workspace.mode === "read" &&
|
|
182
|
+
workspace.store.attachable != null &&
|
|
183
|
+
this.#options.provider.capabilities?.readOnlyAttachments === true);
|
|
184
|
+
}
|
|
185
|
+
#assertStagingLimits(workspace, fileCount, bytes) {
|
|
186
|
+
const limits = workspace.store.limits ?? {};
|
|
187
|
+
if (limits.maxFiles != null && fileCount > limits.maxFiles) {
|
|
188
|
+
throw new Error(`Workspace ${workspace.alias} has ${fileCount} files, exceeding its ${limits.maxFiles}-file limit.`);
|
|
189
|
+
}
|
|
190
|
+
if (limits.maxTotalBytes != null && bytes > limits.maxTotalBytes) {
|
|
191
|
+
throw new Error(`Workspace ${workspace.alias} has ${bytes} bytes, exceeding its ${limits.maxTotalBytes}-byte limit.`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
#spec(runId, attachments) {
|
|
195
|
+
const limits = this.#policy.limits;
|
|
196
|
+
return {
|
|
197
|
+
image: this.#options.image,
|
|
198
|
+
workingDirectory: "/workspace",
|
|
199
|
+
network: "none",
|
|
200
|
+
limits: {
|
|
201
|
+
timeoutMs: limits.maxTotalSandboxSeconds * 1_000 + 60_000,
|
|
202
|
+
memoryMb: limits.memoryMb,
|
|
203
|
+
cpuCount: limits.cpuCount,
|
|
204
|
+
processLimit: limits.processLimit,
|
|
205
|
+
workspaceTmpfsMb: limits.workspaceTmpfsMb,
|
|
206
|
+
maximumOutputBytes: limits.maxOutputBytes,
|
|
207
|
+
maximumOutputFiles: limits.maxOutputFiles,
|
|
208
|
+
},
|
|
209
|
+
...(attachments.length > 0 ? { attachments } : {}),
|
|
210
|
+
metadata: {
|
|
211
|
+
"agent-runtime.run": runId,
|
|
212
|
+
"agent-runtime.kind": "run-sandbox",
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
class ProviderRunSandboxSession {
|
|
218
|
+
id;
|
|
219
|
+
#input;
|
|
220
|
+
#mounts;
|
|
221
|
+
#commandsUsed;
|
|
222
|
+
#sandboxSecondsUsed;
|
|
223
|
+
#sequence = 0;
|
|
224
|
+
#queue = Promise.resolve();
|
|
225
|
+
#closed = false;
|
|
226
|
+
constructor(input) {
|
|
227
|
+
this.id = input.handle.id;
|
|
228
|
+
this.#input = input;
|
|
229
|
+
this.#mounts = new Map(input.mounts.map((mount) => [mount.workspace.alias, mount]));
|
|
230
|
+
this.#commandsUsed = input.request.budget?.commandsUsed ?? 0;
|
|
231
|
+
this.#sandboxSecondsUsed = input.request.budget?.sandboxSecondsUsed ?? 0;
|
|
232
|
+
}
|
|
233
|
+
budget() {
|
|
234
|
+
return {
|
|
235
|
+
commandsUsed: this.#commandsUsed,
|
|
236
|
+
sandboxSecondsUsed: this.#sandboxSecondsUsed,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/** Stage the helper, every non-attached mount, and the mount index. */
|
|
240
|
+
async stage(helperSource) {
|
|
241
|
+
const { provider, handle, request } = this.#input;
|
|
242
|
+
const signal = request.signal;
|
|
243
|
+
await provider.putFiles(handle, [{ path: SANDBOX_HELPER_PATH, content: helperSource, mode: 0o500 }], signal ? { signal } : undefined);
|
|
244
|
+
let stagedBytes = 0;
|
|
245
|
+
for (const mount of this.#mounts.values()) {
|
|
246
|
+
if (mount.attached)
|
|
247
|
+
continue;
|
|
248
|
+
const { workspace } = mount;
|
|
249
|
+
const entries = await workspace.store.entries(signal ? { signal } : undefined);
|
|
250
|
+
const limits = workspace.store.limits ?? {};
|
|
251
|
+
const totalBytes = entries.reduce((sum, entry) => sum + entry.size, 0);
|
|
252
|
+
if (limits.maxFiles != null && entries.length > limits.maxFiles) {
|
|
253
|
+
throw new Error(`Workspace ${workspace.alias} has ${entries.length} files, exceeding its ${limits.maxFiles}-file limit.`);
|
|
254
|
+
}
|
|
255
|
+
if (limits.maxTotalBytes != null && totalBytes > limits.maxTotalBytes) {
|
|
256
|
+
throw new Error(`Workspace ${workspace.alias} has ${totalBytes} bytes, exceeding its ${limits.maxTotalBytes}-byte limit.`);
|
|
257
|
+
}
|
|
258
|
+
const mode = workspace.mode === "read_write" ? 0o600 : 0o400;
|
|
259
|
+
let batch = [];
|
|
260
|
+
let batchBytes = 0;
|
|
261
|
+
const flush = async () => {
|
|
262
|
+
if (batch.length === 0)
|
|
263
|
+
return;
|
|
264
|
+
await provider.putFiles(handle, batch, signal ? { signal } : undefined);
|
|
265
|
+
batch = [];
|
|
266
|
+
batchBytes = 0;
|
|
267
|
+
};
|
|
268
|
+
for (const entry of entries) {
|
|
269
|
+
if (!isSafeWorkspacePath(entry.path))
|
|
270
|
+
continue;
|
|
271
|
+
const data = await workspace.store.read(entry.path, signal ? { signal } : undefined);
|
|
272
|
+
stagedBytes += data.byteLength;
|
|
273
|
+
if (stagedBytes > this.#input.policy.limits.maxTotalStagedBytes) {
|
|
274
|
+
throw new Error(`Bound workspaces exceed the ${this.#input.policy.limits.maxTotalStagedBytes}-byte sandbox staging limit.`);
|
|
275
|
+
}
|
|
276
|
+
batch.push({
|
|
277
|
+
path: assertSandboxPath(`${mount.directory}/${entry.path}`),
|
|
278
|
+
content: data,
|
|
279
|
+
mode,
|
|
280
|
+
});
|
|
281
|
+
batchBytes += data.byteLength;
|
|
282
|
+
mount.fileCount += 1;
|
|
283
|
+
mount.bytes += data.byteLength;
|
|
284
|
+
if (workspace.mode === "read_write") {
|
|
285
|
+
mount.baseline.set(entry.path, {
|
|
286
|
+
size: data.byteLength,
|
|
287
|
+
sha256: sha256(data),
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
if (batchBytes >= STAGING_BATCH_BYTES)
|
|
291
|
+
await flush();
|
|
292
|
+
}
|
|
293
|
+
await flush();
|
|
294
|
+
if (entries.length === 0) {
|
|
295
|
+
// Guarantee the mount directory exists even for empty workspaces.
|
|
296
|
+
await provider.putFiles(handle, [
|
|
297
|
+
{
|
|
298
|
+
path: `${mount.directory}/.agent-runtime-mount`,
|
|
299
|
+
content: "",
|
|
300
|
+
mode: 0o400,
|
|
301
|
+
},
|
|
302
|
+
], signal ? { signal } : undefined);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const index = {
|
|
306
|
+
version: 1,
|
|
307
|
+
mounts: Object.fromEntries([...this.#mounts.values()].map((mount) => [
|
|
308
|
+
mount.workspace.alias,
|
|
309
|
+
{
|
|
310
|
+
path: mount.directory,
|
|
311
|
+
mode: mount.workspace.mode,
|
|
312
|
+
...(mount.attached ? {} : { fileCount: mount.fileCount }),
|
|
313
|
+
attached: mount.attached,
|
|
314
|
+
},
|
|
315
|
+
])),
|
|
316
|
+
output: SANDBOX_OUTPUT_DIRECTORY,
|
|
317
|
+
};
|
|
318
|
+
await provider.putFiles(handle, [
|
|
319
|
+
{
|
|
320
|
+
path: SANDBOX_WORKSPACES_FILE,
|
|
321
|
+
content: JSON.stringify(index),
|
|
322
|
+
mode: 0o400,
|
|
323
|
+
},
|
|
324
|
+
], signal ? { signal } : undefined);
|
|
325
|
+
}
|
|
326
|
+
execute(request) {
|
|
327
|
+
const run = this.#queue.then(() => this.#execute(request));
|
|
328
|
+
this.#queue = run.then(() => undefined, () => undefined);
|
|
329
|
+
return run;
|
|
330
|
+
}
|
|
331
|
+
async close(reason) {
|
|
332
|
+
if (this.#closed)
|
|
333
|
+
return;
|
|
334
|
+
this.#closed = true;
|
|
335
|
+
await this.#queue;
|
|
336
|
+
const { provider, handle, request } = this.#input;
|
|
337
|
+
let filesChanged = 0;
|
|
338
|
+
let ignored = 0;
|
|
339
|
+
let syncError;
|
|
340
|
+
try {
|
|
341
|
+
const controller = new AbortController();
|
|
342
|
+
const timer = setTimeout(() => controller.abort(new Error("Final workspace sync timed out.")), CLOSE_SYNC_TIMEOUT_MS);
|
|
343
|
+
timer.unref?.();
|
|
344
|
+
try {
|
|
345
|
+
for (const mount of this.#mounts.values()) {
|
|
346
|
+
if (mount.workspace.mode !== "read_write")
|
|
347
|
+
continue;
|
|
348
|
+
const changes = await this.#syncBack(mount, controller.signal);
|
|
349
|
+
filesChanged += changes.filesChanged.length;
|
|
350
|
+
ignored += changes.ignoredPaths.length;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
finally {
|
|
354
|
+
clearTimeout(timer);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
syncError = error;
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
await provider.terminate(handle);
|
|
362
|
+
await request.emit("sandbox.closed", {
|
|
363
|
+
sandboxId: handle.id,
|
|
364
|
+
reason,
|
|
365
|
+
commandsUsed: this.#commandsUsed,
|
|
366
|
+
sandboxSecondsUsed: this.#sandboxSecondsUsed,
|
|
367
|
+
finalSync: { filesChanged, ignored },
|
|
368
|
+
...(syncError
|
|
369
|
+
? {
|
|
370
|
+
syncError: syncError instanceof Error
|
|
371
|
+
? syncError.message
|
|
372
|
+
: String(syncError),
|
|
373
|
+
}
|
|
374
|
+
: {}),
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
if (syncError)
|
|
378
|
+
throw syncError;
|
|
379
|
+
}
|
|
380
|
+
async #execute(request) {
|
|
381
|
+
if (this.#closed)
|
|
382
|
+
throw new RunSandboxExecutionError("sandbox_unavailable", "The run sandbox is closed.");
|
|
383
|
+
const { policy, provider, handle, hooks, now } = this.#input;
|
|
384
|
+
const runRequest = this.#input.request;
|
|
385
|
+
const mount = request.alias ? this.#mounts.get(request.alias) : undefined;
|
|
386
|
+
if (request.kind !== "code" && !mount) {
|
|
387
|
+
throw new SandboxPolicyError("tool_not_allowed", `Workspace "${request.alias ?? ""}" is not bound to this run.`);
|
|
388
|
+
}
|
|
389
|
+
const commandId = `cmd-${runRequest.attempt}-${this.#sequence + 1}`;
|
|
390
|
+
const admitted = admitCommand(request, {
|
|
391
|
+
policy,
|
|
392
|
+
...(mount ? { workspace: mount.workspace } : {}),
|
|
393
|
+
commandId,
|
|
394
|
+
helperCommand: this.#helperCommand(),
|
|
395
|
+
codeProfile: (language) => {
|
|
396
|
+
const profile = this.#input.profiles.get(language);
|
|
397
|
+
return profile
|
|
398
|
+
? {
|
|
399
|
+
extension: profile.extension,
|
|
400
|
+
argv: (sourcePath) => [
|
|
401
|
+
profile.command,
|
|
402
|
+
...profile.args(sourcePath),
|
|
403
|
+
],
|
|
404
|
+
}
|
|
405
|
+
: undefined;
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
if (this.#commandsUsed >= policy.limits.maxCommandsPerRun) {
|
|
409
|
+
throw new RunSandboxExecutionError("sandbox_budget_exhausted", `The run has used its ${policy.limits.maxCommandsPerRun}-command sandbox budget.`);
|
|
410
|
+
}
|
|
411
|
+
if (this.#sandboxSecondsUsed >= policy.limits.maxTotalSandboxSeconds) {
|
|
412
|
+
throw new RunSandboxExecutionError("sandbox_budget_exhausted", `The run has used its ${policy.limits.maxTotalSandboxSeconds}-second sandbox budget.`);
|
|
413
|
+
}
|
|
414
|
+
this.#sequence += 1;
|
|
415
|
+
const partialRecord = {
|
|
416
|
+
kind: admitted.kind,
|
|
417
|
+
name: admitted.name,
|
|
418
|
+
...(admitted.policyEntry ? { policyEntry: admitted.policyEntry } : {}),
|
|
419
|
+
argv: [...admitted.argv],
|
|
420
|
+
cwd: admitted.cwd,
|
|
421
|
+
...(mount
|
|
422
|
+
? {
|
|
423
|
+
alias: mount.workspace.alias,
|
|
424
|
+
workspace: mount.workspace.binding.ref,
|
|
425
|
+
}
|
|
426
|
+
: {}),
|
|
427
|
+
};
|
|
428
|
+
try {
|
|
429
|
+
await hooks.authorizeCommand?.({
|
|
430
|
+
record: partialRecord,
|
|
431
|
+
...(request.toolCallId
|
|
432
|
+
? {
|
|
433
|
+
toolCall: {
|
|
434
|
+
id: request.toolCallId,
|
|
435
|
+
name: request.name,
|
|
436
|
+
input: request.arguments,
|
|
437
|
+
},
|
|
438
|
+
}
|
|
439
|
+
: {}),
|
|
440
|
+
}, {
|
|
441
|
+
runId: runRequest.runId,
|
|
442
|
+
stepId: request.stepId,
|
|
443
|
+
attempt: runRequest.attempt,
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
catch (error) {
|
|
447
|
+
throw new RunSandboxExecutionError("tool_not_authorized", error instanceof Error ? error.message : String(error));
|
|
448
|
+
}
|
|
449
|
+
await runRequest.emit("sandbox.command.started", {
|
|
450
|
+
commandId,
|
|
451
|
+
...(request.toolCallId ? { toolCallId: request.toolCallId } : {}),
|
|
452
|
+
kind: admitted.kind,
|
|
453
|
+
name: admitted.name,
|
|
454
|
+
...(admitted.policyEntry ? { policyEntry: admitted.policyEntry } : {}),
|
|
455
|
+
...(mount
|
|
456
|
+
? {
|
|
457
|
+
alias: mount.workspace.alias,
|
|
458
|
+
workspace: mount.workspace.binding.ref,
|
|
459
|
+
}
|
|
460
|
+
: {}),
|
|
461
|
+
argv: [...admitted.argv],
|
|
462
|
+
cwd: admitted.cwd,
|
|
463
|
+
timeoutMs: admitted.timeoutMs,
|
|
464
|
+
}, request.stepId);
|
|
465
|
+
const startedAt = now();
|
|
466
|
+
this.#commandsUsed += 1;
|
|
467
|
+
const signal = request.signal ?? runRequest.signal;
|
|
468
|
+
// Guarantee the per-command output directory exists for every provider.
|
|
469
|
+
await provider.putFiles(handle, [
|
|
470
|
+
...admitted.stagedFiles,
|
|
471
|
+
{
|
|
472
|
+
path: `${admitted.outputDirectory}/${OUTPUT_PLACEHOLDER}`,
|
|
473
|
+
content: "",
|
|
474
|
+
mode: 0o400,
|
|
475
|
+
},
|
|
476
|
+
], signal ? { signal } : undefined);
|
|
477
|
+
const environment = this.#environment(admitted, request);
|
|
478
|
+
const command = {
|
|
479
|
+
command: admitted.argv[0],
|
|
480
|
+
args: admitted.argv.slice(1),
|
|
481
|
+
cwd: admitted.cwd,
|
|
482
|
+
environment,
|
|
483
|
+
timeoutMs: admitted.timeoutMs,
|
|
484
|
+
};
|
|
485
|
+
const stdoutChunks = [];
|
|
486
|
+
const stderrChunks = [];
|
|
487
|
+
const stdoutState = { bytes: 0, truncated: false };
|
|
488
|
+
const stderrState = { bytes: 0, truncated: false };
|
|
489
|
+
let exitCode = -1;
|
|
490
|
+
let timedOut = false;
|
|
491
|
+
let exitSignal;
|
|
492
|
+
try {
|
|
493
|
+
for await (const event of provider.execute(handle, command, signal ? { signal } : undefined)) {
|
|
494
|
+
if (event.type === "stdout") {
|
|
495
|
+
appendBounded(stdoutChunks, stdoutState, event.data, policy.limits.maxStdoutBytes);
|
|
496
|
+
}
|
|
497
|
+
else if (event.type === "stderr") {
|
|
498
|
+
appendBounded(stderrChunks, stderrState, event.data, policy.limits.maxStderrBytes);
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
exitCode = event.exitCode;
|
|
502
|
+
exitSignal = event.signal;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
catch (error) {
|
|
507
|
+
if (signal?.aborted)
|
|
508
|
+
throw error;
|
|
509
|
+
exitCode = -1;
|
|
510
|
+
appendBounded(stderrChunks, stderrState, error instanceof Error ? error.message : String(error), policy.limits.maxStderrBytes);
|
|
511
|
+
}
|
|
512
|
+
const completedAt = now();
|
|
513
|
+
const durationMs = Math.max(0, completedAt.getTime() - startedAt.getTime());
|
|
514
|
+
this.#sandboxSecondsUsed += durationMs / 1_000;
|
|
515
|
+
if (durationMs >= admitted.timeoutMs &&
|
|
516
|
+
(exitCode !== 0 || exitSignal === "SIGKILL" || exitSignal === "SIGTERM")) {
|
|
517
|
+
timedOut = true;
|
|
518
|
+
}
|
|
519
|
+
const stdout = stdoutChunks.join("");
|
|
520
|
+
const stderr = stderrChunks.join("");
|
|
521
|
+
const artifacts = await this.#collectArtifacts(admitted.outputDirectory, signal);
|
|
522
|
+
const filesChanged = [];
|
|
523
|
+
const ignoredPaths = [];
|
|
524
|
+
for (const candidate of this.#mounts.values()) {
|
|
525
|
+
if (candidate.workspace.mode !== "read_write")
|
|
526
|
+
continue;
|
|
527
|
+
const changes = await this.#syncBack(candidate, signal);
|
|
528
|
+
filesChanged.push(...changes.filesChanged);
|
|
529
|
+
ignoredPaths.push(...changes.ignoredPaths);
|
|
530
|
+
}
|
|
531
|
+
const record = {
|
|
532
|
+
id: commandId,
|
|
533
|
+
runId: runRequest.runId,
|
|
534
|
+
attempt: runRequest.attempt,
|
|
535
|
+
stepId: request.stepId,
|
|
536
|
+
...(request.toolCallId ? { toolCallId: request.toolCallId } : {}),
|
|
537
|
+
...partialRecord,
|
|
538
|
+
startedAt: startedAt.toISOString(),
|
|
539
|
+
completedAt: completedAt.toISOString(),
|
|
540
|
+
durationMs,
|
|
541
|
+
exitCode,
|
|
542
|
+
timedOut,
|
|
543
|
+
stdoutBytes: stdoutState.bytes,
|
|
544
|
+
stderrBytes: stderrState.bytes,
|
|
545
|
+
stdoutTruncated: stdoutState.truncated,
|
|
546
|
+
stderrTruncated: stderrState.truncated,
|
|
547
|
+
filesChanged,
|
|
548
|
+
...(artifacts.length > 0
|
|
549
|
+
? { artifacts: artifacts.map((artifact) => artifact.id) }
|
|
550
|
+
: {}),
|
|
551
|
+
ignoredPaths,
|
|
552
|
+
budget: {
|
|
553
|
+
commandsUsed: this.#commandsUsed,
|
|
554
|
+
commandsLimit: policy.limits.maxCommandsPerRun,
|
|
555
|
+
sandboxSecondsUsed: this.#sandboxSecondsUsed,
|
|
556
|
+
sandboxSecondsLimit: policy.limits.maxTotalSandboxSeconds,
|
|
557
|
+
},
|
|
558
|
+
};
|
|
559
|
+
await runRequest.emit("sandbox.command.completed", JSON.parse(JSON.stringify(record)), request.stepId);
|
|
560
|
+
if (timedOut) {
|
|
561
|
+
throw new RunSandboxExecutionError("sandbox_command_timeout", `Sandbox command ${admitted.name} timed out after ${admitted.timeoutMs}ms.`);
|
|
562
|
+
}
|
|
563
|
+
let output;
|
|
564
|
+
if (admitted.expectsJson) {
|
|
565
|
+
output = this.#parseHelperOutput(stdout, exitCode, stderr, artifacts);
|
|
566
|
+
}
|
|
567
|
+
else if (admitted.kind === "code") {
|
|
568
|
+
output = stdout.length > 0 ? stdout : undefined;
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
output = {
|
|
572
|
+
exitCode,
|
|
573
|
+
stdout,
|
|
574
|
+
stderr,
|
|
575
|
+
truncated: stdoutState.truncated || stderrState.truncated,
|
|
576
|
+
...(artifacts.length > 0
|
|
577
|
+
? { artifacts: artifacts.map((artifact) => artifact.id) }
|
|
578
|
+
: {}),
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
record,
|
|
583
|
+
...(output !== undefined ? { output } : {}),
|
|
584
|
+
stdout,
|
|
585
|
+
stderr,
|
|
586
|
+
...(artifacts.length > 0 ? { artifacts } : {}),
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
#helperCommand() {
|
|
590
|
+
return this.#input.helperCommand;
|
|
591
|
+
}
|
|
592
|
+
#environment(admitted, request) {
|
|
593
|
+
const environment = {
|
|
594
|
+
AGENT_WORKSPACES_FILE: SANDBOX_WORKSPACES_FILE,
|
|
595
|
+
AGENT_OUTPUT_DIRECTORY: admitted.outputDirectory,
|
|
596
|
+
AGENT_COMMAND_ID: admitted.outputDirectory.split("/").at(-1),
|
|
597
|
+
};
|
|
598
|
+
if (admitted.kind === "code") {
|
|
599
|
+
environment.AGENT_VARIABLES_FILE = `${admitted.cwd}/variables.json`;
|
|
600
|
+
const requested = request.arguments.environment;
|
|
601
|
+
if (isJsonObject(requested)) {
|
|
602
|
+
for (const [name, value] of Object.entries(requested)) {
|
|
603
|
+
if (this.#input.allowedEnvironment.has(name) &&
|
|
604
|
+
typeof value === "string") {
|
|
605
|
+
environment[name] = value;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
return environment;
|
|
611
|
+
}
|
|
612
|
+
async #collectArtifacts(directory, signal) {
|
|
613
|
+
const { provider, handle, policy } = this.#input;
|
|
614
|
+
const artifacts = this.#input.request.artifacts;
|
|
615
|
+
const files = (await provider
|
|
616
|
+
.listFiles(handle, directory, signal ? { signal } : undefined)
|
|
617
|
+
.catch(() => [])).filter((file) => !file.path.endsWith(`/${OUTPUT_PLACEHOLDER}`));
|
|
618
|
+
if (files.length === 0 || !artifacts)
|
|
619
|
+
return [];
|
|
620
|
+
if (files.length > policy.limits.maxOutputFiles) {
|
|
621
|
+
throw new RunSandboxExecutionError("workspace_limit_exceeded", `Command produced ${files.length} output files, exceeding ${policy.limits.maxOutputFiles}.`);
|
|
622
|
+
}
|
|
623
|
+
const refs = [];
|
|
624
|
+
let total = 0;
|
|
625
|
+
for (const file of files) {
|
|
626
|
+
const outputPath = assertSandboxPath(file.path);
|
|
627
|
+
if (!outputPath.startsWith(`${directory}/`))
|
|
628
|
+
continue;
|
|
629
|
+
if (outputPath.endsWith(`/${OUTPUT_PLACEHOLDER}`))
|
|
630
|
+
continue;
|
|
631
|
+
const data = await provider.readFile(handle, outputPath, signal ? { signal } : undefined);
|
|
632
|
+
total += data.byteLength;
|
|
633
|
+
if (total > policy.limits.maxOutputBytes) {
|
|
634
|
+
throw new RunSandboxExecutionError("workspace_limit_exceeded", `Command output exceeded ${policy.limits.maxOutputBytes} bytes.`);
|
|
635
|
+
}
|
|
636
|
+
const relative = outputPath.slice(directory.length + 1);
|
|
637
|
+
refs.push(await artifacts.put({
|
|
638
|
+
name: relative,
|
|
639
|
+
mediaType: mediaTypeFor(relative),
|
|
640
|
+
data,
|
|
641
|
+
metadata: {
|
|
642
|
+
sandboxProvider: provider.name,
|
|
643
|
+
commandId: directory.split("/").at(-1),
|
|
644
|
+
sha256: sha256(data),
|
|
645
|
+
},
|
|
646
|
+
}));
|
|
647
|
+
}
|
|
648
|
+
return refs;
|
|
649
|
+
}
|
|
650
|
+
#parseHelperOutput(stdout, exitCode, stderr, artifacts) {
|
|
651
|
+
if (Buffer.byteLength(stdout) > MAXIMUM_HELPER_OUTPUT_BYTES) {
|
|
652
|
+
throw new RunSandboxExecutionError("workspace_limit_exceeded", "Helper output exceeded the 1 MiB limit.");
|
|
653
|
+
}
|
|
654
|
+
let parsed;
|
|
655
|
+
try {
|
|
656
|
+
parsed = JSON.parse(stdout.trim() || "null");
|
|
657
|
+
}
|
|
658
|
+
catch {
|
|
659
|
+
throw new RunSandboxExecutionError("sandbox_command_failed", `Workspace helper returned invalid output (exit ${exitCode}): ${stderr.slice(0, 512)}`);
|
|
660
|
+
}
|
|
661
|
+
if (!isJsonObject(parsed) ||
|
|
662
|
+
parsed.protocolVersion !== HELPER_PROTOCOL_VERSION) {
|
|
663
|
+
throw new RunSandboxExecutionError("sandbox_command_failed", `Workspace helper protocol mismatch (exit ${exitCode}).`);
|
|
664
|
+
}
|
|
665
|
+
const { protocolVersion: _version, ...document } = parsed;
|
|
666
|
+
if (isJsonObject(document.error)) {
|
|
667
|
+
const code = String(document.error.code ?? "");
|
|
668
|
+
const message = String(document.error.message ?? "Workspace helper error.");
|
|
669
|
+
const mapped = code === "path_invalid"
|
|
670
|
+
? "workspace_path_invalid"
|
|
671
|
+
: code === "limit_exceeded"
|
|
672
|
+
? "workspace_limit_exceeded"
|
|
673
|
+
: code === "read_only"
|
|
674
|
+
? "tool_not_allowed"
|
|
675
|
+
: "sandbox_command_failed";
|
|
676
|
+
throw new RunSandboxExecutionError(mapped, message);
|
|
677
|
+
}
|
|
678
|
+
if (exitCode !== 0) {
|
|
679
|
+
throw new RunSandboxExecutionError("sandbox_command_failed", `Workspace helper exited with ${exitCode}: ${stderr.slice(0, 512)}`);
|
|
680
|
+
}
|
|
681
|
+
if (document.encoding === "binary") {
|
|
682
|
+
const { artifactFile: _file, ...rest } = document;
|
|
683
|
+
const artifact = artifacts.find((candidate) => candidate.name === _file);
|
|
684
|
+
return {
|
|
685
|
+
...rest,
|
|
686
|
+
...(artifact
|
|
687
|
+
? { artifactId: artifact.id }
|
|
688
|
+
: { note: "binary content requires an artifact store" }),
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
return document;
|
|
692
|
+
}
|
|
693
|
+
async #syncBack(mount, signal) {
|
|
694
|
+
const { provider, handle } = this.#input;
|
|
695
|
+
const { workspace } = mount;
|
|
696
|
+
const alias = workspace.alias;
|
|
697
|
+
const filesChanged = [];
|
|
698
|
+
const ignoredPaths = [];
|
|
699
|
+
const maxFileBytes = workspace.store.limits?.maxFileBytes ?? 1_048_576;
|
|
700
|
+
const snapshot = await this.#snapshot(mount, signal);
|
|
701
|
+
for (const item of snapshot.ignored) {
|
|
702
|
+
ignoredPaths.push({ alias, path: item.path, reason: item.reason });
|
|
703
|
+
}
|
|
704
|
+
const seen = new Set();
|
|
705
|
+
for (const file of snapshot.files) {
|
|
706
|
+
seen.add(file.path);
|
|
707
|
+
const previous = mount.baseline.get(file.path);
|
|
708
|
+
if (file.sha256 == null || file.size > maxFileBytes) {
|
|
709
|
+
if (!previous || previous.sha256 !== undefined) {
|
|
710
|
+
ignoredPaths.push({ alias, path: file.path, reason: "size" });
|
|
711
|
+
}
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
if (previous && previous.sha256 === file.sha256)
|
|
715
|
+
continue;
|
|
716
|
+
const data = await provider.readFile(handle, assertSandboxPath(`${mount.directory}/${file.path}`), signal ? { signal } : undefined);
|
|
717
|
+
if (data.byteLength > maxFileBytes) {
|
|
718
|
+
ignoredPaths.push({ alias, path: file.path, reason: "size" });
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
try {
|
|
722
|
+
await workspace.store.write(file.path, data, signal ? { signal } : undefined);
|
|
723
|
+
mount.baseline.set(file.path, {
|
|
724
|
+
size: data.byteLength,
|
|
725
|
+
sha256: sha256(data),
|
|
726
|
+
});
|
|
727
|
+
filesChanged.push({
|
|
728
|
+
alias,
|
|
729
|
+
path: file.path,
|
|
730
|
+
action: previous ? "modified" : "created",
|
|
731
|
+
size: data.byteLength,
|
|
732
|
+
sha256: file.sha256,
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
catch (error) {
|
|
736
|
+
ignoredPaths.push({
|
|
737
|
+
alias,
|
|
738
|
+
path: file.path,
|
|
739
|
+
reason: `store: ${error instanceof Error ? error.message : String(error)}`,
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
for (const previousPath of [...mount.baseline.keys()]) {
|
|
744
|
+
if (seen.has(previousPath))
|
|
745
|
+
continue;
|
|
746
|
+
try {
|
|
747
|
+
await workspace.store.delete(previousPath, signal ? { signal } : undefined);
|
|
748
|
+
mount.baseline.delete(previousPath);
|
|
749
|
+
filesChanged.push({ alias, path: previousPath, action: "deleted" });
|
|
750
|
+
}
|
|
751
|
+
catch (error) {
|
|
752
|
+
ignoredPaths.push({
|
|
753
|
+
alias,
|
|
754
|
+
path: previousPath,
|
|
755
|
+
reason: `store: ${error instanceof Error ? error.message : String(error)}`,
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return { filesChanged, ignoredPaths };
|
|
760
|
+
}
|
|
761
|
+
async #snapshot(mount, signal) {
|
|
762
|
+
const { provider, handle, policy } = this.#input;
|
|
763
|
+
const limits = mount.workspace.store.limits ?? {};
|
|
764
|
+
const argv = [
|
|
765
|
+
...this.#helperCommand(),
|
|
766
|
+
"snapshot",
|
|
767
|
+
"--mount",
|
|
768
|
+
mount.directory,
|
|
769
|
+
"--max-files",
|
|
770
|
+
String(limits.maxFiles ?? 5_000),
|
|
771
|
+
"--max-bytes",
|
|
772
|
+
String(limits.maxFileBytes ?? 1_048_576),
|
|
773
|
+
];
|
|
774
|
+
const chunks = [];
|
|
775
|
+
const state = { bytes: 0, truncated: false };
|
|
776
|
+
let exitCode = -1;
|
|
777
|
+
for await (const event of provider.execute(handle, {
|
|
778
|
+
command: argv[0],
|
|
779
|
+
args: argv.slice(1),
|
|
780
|
+
cwd: "/workspace",
|
|
781
|
+
environment: {},
|
|
782
|
+
timeoutMs: policy.limits.maxCommandTimeoutMs,
|
|
783
|
+
}, signal ? { signal } : undefined)) {
|
|
784
|
+
if (event.type === "stdout") {
|
|
785
|
+
appendBounded(chunks, state, event.data, 8 * MAXIMUM_HELPER_OUTPUT_BYTES);
|
|
786
|
+
}
|
|
787
|
+
else if (event.type === "exit") {
|
|
788
|
+
exitCode = event.exitCode;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
let parsed;
|
|
792
|
+
try {
|
|
793
|
+
parsed = JSON.parse(chunks.join("").trim() || "null");
|
|
794
|
+
}
|
|
795
|
+
catch {
|
|
796
|
+
parsed = undefined;
|
|
797
|
+
}
|
|
798
|
+
if (exitCode !== 0 ||
|
|
799
|
+
!isJsonObject(parsed) ||
|
|
800
|
+
!Array.isArray(parsed.files)) {
|
|
801
|
+
throw new Error(`Workspace snapshot of ${mount.workspace.alias} failed (exit ${exitCode}).`);
|
|
802
|
+
}
|
|
803
|
+
const files = parsed.files.flatMap((item) => {
|
|
804
|
+
if (!isJsonObject(item) ||
|
|
805
|
+
typeof item.path !== "string" ||
|
|
806
|
+
!isSafeWorkspacePath(item.path))
|
|
807
|
+
return [];
|
|
808
|
+
return [
|
|
809
|
+
{
|
|
810
|
+
path: item.path,
|
|
811
|
+
size: typeof item.size === "number" ? item.size : 0,
|
|
812
|
+
...(typeof item.sha256 === "string" &&
|
|
813
|
+
/^[a-f0-9]{64}$/u.test(item.sha256)
|
|
814
|
+
? { sha256: item.sha256 }
|
|
815
|
+
: {}),
|
|
816
|
+
},
|
|
817
|
+
];
|
|
818
|
+
});
|
|
819
|
+
const ignored = Array.isArray(parsed.ignored)
|
|
820
|
+
? parsed.ignored.flatMap((item) => isJsonObject(item) && typeof item.path === "string"
|
|
821
|
+
? [
|
|
822
|
+
{
|
|
823
|
+
path: String(item.path).slice(0, 1024),
|
|
824
|
+
reason: String(item.reason ?? "path"),
|
|
825
|
+
},
|
|
826
|
+
]
|
|
827
|
+
: [])
|
|
828
|
+
: [];
|
|
829
|
+
return { files, ignored };
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
const mediaTypeFor = (filename) => {
|
|
833
|
+
const extension = path.posix.extname(filename).toLowerCase();
|
|
834
|
+
return ({
|
|
835
|
+
".txt": "text/plain",
|
|
836
|
+
".md": "text/markdown",
|
|
837
|
+
".json": "application/json",
|
|
838
|
+
".csv": "text/csv",
|
|
839
|
+
".png": "image/png",
|
|
840
|
+
".jpg": "image/jpeg",
|
|
841
|
+
".jpeg": "image/jpeg",
|
|
842
|
+
".webp": "image/webp",
|
|
843
|
+
".gif": "image/gif",
|
|
844
|
+
".svg": "image/svg+xml",
|
|
845
|
+
".pdf": "application/pdf",
|
|
846
|
+
".html": "text/html",
|
|
847
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
848
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
849
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
850
|
+
}[extension] ?? "application/octet-stream");
|
|
851
|
+
};
|
|
852
|
+
export { RunSandboxExecutionError };
|