@opencoredev/sandbox-sdk 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +24 -8
  3. package/dist/{agentos-BOFA_q-a.mjs → agentos-CbrZW7R0.mjs} +5 -4
  4. package/dist/{agentos-BOFA_q-a.mjs.map → agentos-CbrZW7R0.mjs.map} +1 -1
  5. package/dist/ai/harness.d.mts +2 -2
  6. package/dist/ai/harness.mjs +2 -2
  7. package/dist/ai/index.d.mts +1 -1
  8. package/dist/ai/index.mjs +2 -2
  9. package/dist/{ai-DhfwIZdL.mjs → ai-DeFa8yPk.mjs} +2 -2
  10. package/dist/{ai-DhfwIZdL.mjs.map → ai-DeFa8yPk.mjs.map} +1 -1
  11. package/dist/{capabilities-CMnszzpt.d.mts → capabilities-BWvOVFbH.d.mts} +5 -3
  12. package/dist/{capabilities-CEowrzRM.mjs → capabilities-CaSNd6J1.mjs} +29 -3
  13. package/dist/{capabilities-CEowrzRM.mjs.map → capabilities-CaSNd6J1.mjs.map} +1 -1
  14. package/dist/{capabilities-COKpwoFH.mjs → capabilities-xs9kaHrK.mjs} +2 -2
  15. package/dist/{capabilities-COKpwoFH.mjs.map → capabilities-xs9kaHrK.mjs.map} +1 -1
  16. package/dist/{errors-Ch9PHKTd.mjs → errors-BuF9bYOQ.mjs} +10 -3
  17. package/dist/errors-BuF9bYOQ.mjs.map +1 -0
  18. package/dist/eve/index.d.mts +2 -2
  19. package/dist/eve/index.mjs +2 -2
  20. package/dist/{index-B1YT6OQ8.d.mts → index-CkTwqD0X.d.mts} +2 -2
  21. package/dist/{index-BMFkO6Fv.d.mts → index-Dh9xob2s.d.mts} +2 -2
  22. package/dist/index.d.mts +4 -4
  23. package/dist/index.mjs +6 -4
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/{provider-utils-DilOYLBO.mjs → managed-provider-BsZGVQ4I.mjs} +4 -57
  26. package/dist/managed-provider-BsZGVQ4I.mjs.map +1 -0
  27. package/dist/mastra/index.d.mts +2 -2
  28. package/dist/mastra/index.mjs +1 -1
  29. package/dist/metadata.d.mts +1 -1
  30. package/dist/metadata.mjs +37 -5
  31. package/dist/metadata.mjs.map +1 -1
  32. package/dist/{provider-_caCV8kk.d.mts → provider-DOBErkBO.d.mts} +2 -2
  33. package/dist/provider-utils-CfB9nvJx.mjs +57 -0
  34. package/dist/provider-utils-CfB9nvJx.mjs.map +1 -0
  35. package/dist/providers/agentos/index.d.mts +6 -6
  36. package/dist/providers/agentos/index.mjs +7 -6
  37. package/dist/providers/box/index.d.mts +34 -0
  38. package/dist/providers/box/index.mjs +348 -0
  39. package/dist/providers/box/index.mjs.map +1 -0
  40. package/dist/providers/daytona/index.d.mts +5 -5
  41. package/dist/providers/daytona/index.mjs +6 -5
  42. package/dist/providers/daytona/index.mjs.map +1 -1
  43. package/dist/providers/e2b/index.d.mts +5 -5
  44. package/dist/providers/e2b/index.mjs +6 -5
  45. package/dist/providers/e2b/index.mjs.map +1 -1
  46. package/dist/providers/local/index.d.mts +6 -6
  47. package/dist/providers/local/index.mjs +7 -6
  48. package/dist/providers/local/index.mjs.map +1 -1
  49. package/dist/providers/railway/index.d.mts +29 -0
  50. package/dist/providers/railway/index.mjs +211 -0
  51. package/dist/providers/railway/index.mjs.map +1 -0
  52. package/dist/providers/upstash/index.d.mts +5 -5
  53. package/dist/providers/upstash/index.mjs +6 -5
  54. package/dist/providers/upstash/index.mjs.map +1 -1
  55. package/dist/providers/vercel/index.d.mts +6 -5
  56. package/dist/providers/vercel/index.mjs +6 -5
  57. package/dist/providers/vercel/index.mjs.map +1 -1
  58. package/dist/{sandbox-BUYT-1C9.d.mts → sandbox-DdEqoXJF.d.mts} +12 -3
  59. package/dist/{sandbox-BwyHcB_C.mjs → sandbox-DgtY5hvt.mjs} +13 -3
  60. package/dist/sandbox-DgtY5hvt.mjs.map +1 -0
  61. package/dist/testing/index.d.mts +3 -3
  62. package/dist/testing/index.mjs +3 -3
  63. package/dist/{types-BTagTtsp.d.mts → types-Bv6I2U1c.d.mts} +5 -2
  64. package/package.json +23 -3
  65. package/dist/errors-Ch9PHKTd.mjs.map +0 -1
  66. package/dist/provider-utils-DilOYLBO.mjs.map +0 -1
  67. package/dist/sandbox-BwyHcB_C.mjs.map +0 -1
@@ -0,0 +1,29 @@
1
+ import "../../types-Bv6I2U1c.mjs";
2
+ import { o as SandboxProvider } from "../../provider-DOBErkBO.mjs";
3
+ import "../../index-Dh9xob2s.mjs";
4
+ import "../../sandbox-DdEqoXJF.mjs";
5
+ import { o as railwayCapabilities } from "../../capabilities-BWvOVFbH.mjs";
6
+ import { Sandbox as RailwaySandbox, SandboxTemplate } from "railway";
7
+
8
+ //#region src/providers/railway/index.d.ts
9
+ interface RailwayBaseOptions {
10
+ /** Railway API token. Defaults to RAILWAY_API_TOKEN. */
11
+ token?: string;
12
+ /** Railway environment id. Defaults to RAILWAY_ENVIRONMENT_ID. */
13
+ environmentId?: string;
14
+ /** Minutes before Railway destroys an idle sandbox. */
15
+ idleTimeoutMinutes?: number;
16
+ /** Whether the sandbox can access the environment's private network. */
17
+ networkIsolation?: "ISOLATED" | "PRIVATE";
18
+ }
19
+ type RailwayOptions = RailwayBaseOptions & ({
20
+ checkpoint?: string;
21
+ template?: never;
22
+ } | {
23
+ checkpoint?: never;
24
+ template?: SandboxTemplate;
25
+ });
26
+ declare function railway(options?: RailwayOptions): SandboxProvider<RailwaySandbox>;
27
+ //#endregion
28
+ export { RailwayOptions, type RailwaySandbox, type SandboxTemplate as RailwaySandboxTemplate, railway, railwayCapabilities };
29
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1,211 @@
1
+ import { t as SandboxError } from "../../errors-BuF9bYOQ.mjs";
2
+ import "../../capabilities-xs9kaHrK.mjs";
3
+ import { o as railwayCapabilities } from "../../capabilities-CaSNd6J1.mjs";
4
+ import { i as unsupported, t as commandString } from "../../provider-utils-CfB9nvJx.mjs";
5
+ import { Sandbox } from "railway";
6
+
7
+ //#region src/providers/railway/index.ts
8
+ function railway(options = {}) {
9
+ const credentials = {
10
+ token: options.token,
11
+ environmentId: options.environmentId
12
+ };
13
+ return {
14
+ id: "railway",
15
+ capabilities: railwayCapabilities,
16
+ async create(createOptions) {
17
+ assertNotAborted(createOptions.signal);
18
+ const createConfig = {
19
+ ...credentials,
20
+ idleTimeoutMinutes: options.idleTimeoutMinutes,
21
+ networkIsolation: options.networkIsolation,
22
+ env: { ...createOptions.env }
23
+ };
24
+ const raw = await awaitCreation(options.checkpoint ? Sandbox.create(options.checkpoint, createConfig) : options.template ? Sandbox.create(options.template, createConfig) : Sandbox.create(createConfig), createOptions.signal, createOptions.timeout);
25
+ try {
26
+ await raw.files.mkdir(createOptions.cwd);
27
+ } catch (error) {
28
+ await raw.destroy().catch(() => void 0);
29
+ throw error;
30
+ }
31
+ return {
32
+ id: raw.id,
33
+ raw,
34
+ capabilities: railwayCapabilities,
35
+ files: {
36
+ async write(path, value) {
37
+ await raw.files.write(path, value);
38
+ },
39
+ read: (path) => raw.files.read(path, { format: "bytes" }),
40
+ async list(path) {
41
+ return (await raw.files.list(path)).map((entry) => ({
42
+ name: entry.name,
43
+ path: `${path.replace(/\/$/, "")}/${entry.name}`,
44
+ type: entry.isDir ? "directory" : "file",
45
+ size: entry.isDir ? void 0 : entry.size
46
+ }));
47
+ },
48
+ mkdir: (path) => raw.files.mkdir(path),
49
+ async remove(path) {
50
+ const result = await raw.exec(commandString({
51
+ command: "rm",
52
+ args: [
53
+ "-rf",
54
+ "--",
55
+ path
56
+ ]
57
+ }));
58
+ if (result.exitCode !== 0) throw new Error(`files.remove failed: ${result.stderr || result.stdout}`);
59
+ },
60
+ exists: (path) => raw.files.exists(path)
61
+ },
62
+ async run(command, runOptions) {
63
+ assertNotAborted(runOptions.signal);
64
+ const started = performance.now();
65
+ const handle = raw.exec(commandString(command), {
66
+ cwd: runOptions.cwd,
67
+ env: { ...runOptions.env },
68
+ timeoutSec: timeoutSeconds(runOptions.timeout)
69
+ });
70
+ const removeAbort = bindAbort(handle, runOptions.signal);
71
+ try {
72
+ const result = await handle;
73
+ if (result.timedOut) throw new SandboxError({
74
+ code: "timeout",
75
+ provider: "railway",
76
+ operation: "process.run",
77
+ message: `Command timed out after ${runOptions.timeout}ms`
78
+ });
79
+ return {
80
+ stdout: result.stdout,
81
+ stderr: result.stderr,
82
+ exitCode: result.exitCode ?? -1,
83
+ success: result.exitCode === 0,
84
+ signal: result.exitCode === null ? "unknown" : void 0,
85
+ durationMs: Math.round(performance.now() - started)
86
+ };
87
+ } finally {
88
+ removeAbort();
89
+ }
90
+ },
91
+ async start(command, runOptions) {
92
+ assertNotAborted(runOptions.signal);
93
+ const events = [];
94
+ const waiters = /* @__PURE__ */ new Set();
95
+ let state = "running";
96
+ const wake = () => {
97
+ for (const waiter of waiters) waiter();
98
+ waiters.clear();
99
+ };
100
+ const push = (stream, data) => {
101
+ events.push({
102
+ stream,
103
+ data,
104
+ timestamp: /* @__PURE__ */ new Date()
105
+ });
106
+ wake();
107
+ };
108
+ const handle = raw.exec(commandString(command), {
109
+ cwd: runOptions.cwd,
110
+ env: { ...runOptions.env },
111
+ timeoutSec: timeoutSeconds(runOptions.timeout),
112
+ onStdout: (chunk) => push("stdout", chunk),
113
+ onStderr: (chunk) => push("stderr", chunk)
114
+ });
115
+ const removeAbort = bindAbort(handle, runOptions.signal);
116
+ const completed = handle.then((result) => ({ exitCode: result.exitCode ?? -1 })).finally(() => {
117
+ if (state === "running") state = "exited";
118
+ removeAbort();
119
+ wake();
120
+ });
121
+ return {
122
+ id: await handle.sessionName,
123
+ async status() {
124
+ return state;
125
+ },
126
+ async *output() {
127
+ let index = 0;
128
+ while (state === "running" || index < events.length) {
129
+ while (index < events.length) yield events[index++];
130
+ if (state !== "running") break;
131
+ await new Promise((resolve) => waiters.add(resolve));
132
+ }
133
+ },
134
+ async write() {
135
+ unsupported("railway", "process.stdin");
136
+ },
137
+ wait: () => completed,
138
+ async kill(signal = "SIGTERM") {
139
+ const nativeSignal = signal.replace(/^SIG/, "");
140
+ await handle.kill(nativeSignal);
141
+ state = "killed";
142
+ wake();
143
+ }
144
+ };
145
+ },
146
+ async expose() {
147
+ unsupported("railway", "ports.expose");
148
+ },
149
+ snapshots: {
150
+ async create(snapshotOptions) {
151
+ const checkpoint = await raw.checkpoint(snapshotOptions?.name ?? `sandbox-sdk-${Date.now()}`);
152
+ return {
153
+ id: checkpoint.id,
154
+ name: checkpoint.key,
155
+ mode: "filesystem",
156
+ createdAt: new Date(checkpoint.createdAt)
157
+ };
158
+ },
159
+ async delete(snapshot) {
160
+ await Sandbox.deleteCheckpoint(typeof snapshot === "string" ? snapshot : snapshot.id, credentials);
161
+ },
162
+ async restore() {
163
+ unsupported("railway", "snapshot.restore");
164
+ }
165
+ },
166
+ async stop() {
167
+ await raw.destroy();
168
+ }
169
+ };
170
+ }
171
+ };
172
+ }
173
+ function timeoutSeconds(timeout) {
174
+ return timeout === void 0 ? void 0 : Math.max(1, Math.ceil(timeout / 1e3));
175
+ }
176
+ function bindAbort(handle, signal) {
177
+ if (!signal) return () => void 0;
178
+ const abort = () => void handle.kill("TERM").catch(() => void 0);
179
+ signal.addEventListener("abort", abort, { once: true });
180
+ return () => signal.removeEventListener("abort", abort);
181
+ }
182
+ async function awaitCreation(promise, signal, timeoutMs) {
183
+ if (!signal && timeoutMs === void 0) return promise;
184
+ return new Promise((resolve, reject) => {
185
+ let settled = false;
186
+ const finish = (callback) => {
187
+ if (settled) return;
188
+ settled = true;
189
+ signal?.removeEventListener("abort", onAbort);
190
+ if (timer) clearTimeout(timer);
191
+ callback();
192
+ };
193
+ const onAbort = () => finish(() => reject(signal?.reason ?? new DOMException("Aborted", "AbortError")));
194
+ const timer = timeoutMs ? setTimeout(() => finish(() => reject(/* @__PURE__ */ new Error(`Sandbox creation timed out after ${timeoutMs}ms`))), timeoutMs) : void 0;
195
+ signal?.addEventListener("abort", onAbort, { once: true });
196
+ promise.then((sandbox) => {
197
+ if (settled) {
198
+ sandbox.destroy().catch(() => void 0);
199
+ return;
200
+ }
201
+ finish(() => resolve(sandbox));
202
+ }, (error) => finish(() => reject(error)));
203
+ });
204
+ }
205
+ function assertNotAborted(signal) {
206
+ if (signal?.aborted) throw signal.reason ?? new DOMException("Aborted", "AbortError");
207
+ }
208
+
209
+ //#endregion
210
+ export { railway, railwayCapabilities };
211
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["RailwaySandbox","events: ProcessOutputEvent[]","state: \"running\" | \"exited\" | \"killed\""],"sources":["../../../src/providers/railway/index.ts"],"sourcesContent":["import {\n Sandbox as RailwaySandbox,\n type ExecHandle,\n type ExecSignal,\n type SandboxTemplate,\n} from \"railway\";\nimport { SandboxError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type { ProcessOutputEvent, SandboxProcess, SandboxSnapshot } from \"../../core/types\";\nimport { commandString, unsupported } from \"../../internal/provider-utils\";\nimport { railwayCapabilities } from \"../capabilities\";\n\ninterface RailwayBaseOptions {\n /** Railway API token. Defaults to RAILWAY_API_TOKEN. */\n token?: string;\n /** Railway environment id. Defaults to RAILWAY_ENVIRONMENT_ID. */\n environmentId?: string;\n /** Minutes before Railway destroys an idle sandbox. */\n idleTimeoutMinutes?: number;\n /** Whether the sandbox can access the environment's private network. */\n networkIsolation?: \"ISOLATED\" | \"PRIVATE\";\n}\n\nexport type RailwayOptions = RailwayBaseOptions &\n ({ checkpoint?: string; template?: never } | { checkpoint?: never; template?: SandboxTemplate });\n\nexport { railwayCapabilities } from \"../capabilities\";\n\nexport function railway(options: RailwayOptions = {}): SandboxProvider<RailwaySandbox> {\n const credentials = {\n token: options.token,\n environmentId: options.environmentId,\n };\n\n return {\n id: \"railway\",\n capabilities: railwayCapabilities,\n async create(createOptions) {\n assertNotAborted(createOptions.signal);\n const createConfig = {\n ...credentials,\n idleTimeoutMinutes: options.idleTimeoutMinutes,\n networkIsolation: options.networkIsolation,\n env: { ...createOptions.env },\n };\n const pending = options.checkpoint\n ? RailwaySandbox.create(options.checkpoint, createConfig)\n : options.template\n ? RailwaySandbox.create(options.template, createConfig)\n : RailwaySandbox.create(createConfig);\n const raw = await awaitCreation(pending, createOptions.signal, createOptions.timeout);\n try {\n await raw.files.mkdir(createOptions.cwd);\n } catch (error) {\n await raw.destroy().catch(() => undefined);\n throw error;\n }\n\n return {\n id: raw.id,\n raw,\n capabilities: railwayCapabilities,\n files: {\n async write(path, value) {\n await raw.files.write(path, value);\n },\n read: (path) => raw.files.read(path, { format: \"bytes\" }),\n async list(path) {\n return (await raw.files.list(path)).map((entry) => ({\n name: entry.name,\n path: `${path.replace(/\\/$/, \"\")}/${entry.name}`,\n type: entry.isDir ? (\"directory\" as const) : (\"file\" as const),\n size: entry.isDir ? undefined : entry.size,\n }));\n },\n mkdir: (path) => raw.files.mkdir(path),\n async remove(path) {\n const result = await raw.exec(\n commandString({ command: \"rm\", args: [\"-rf\", \"--\", path] }),\n );\n if (result.exitCode !== 0) {\n throw new Error(`files.remove failed: ${result.stderr || result.stdout}`);\n }\n },\n exists: (path) => raw.files.exists(path),\n },\n async run(command, runOptions) {\n assertNotAborted(runOptions.signal);\n const started = performance.now();\n const handle = raw.exec(commandString(command), {\n cwd: runOptions.cwd,\n env: { ...runOptions.env },\n timeoutSec: timeoutSeconds(runOptions.timeout),\n });\n const removeAbort = bindAbort(handle, runOptions.signal);\n try {\n const result = await handle;\n if (result.timedOut) {\n throw new SandboxError({\n code: \"timeout\",\n provider: \"railway\",\n operation: \"process.run\",\n message: `Command timed out after ${runOptions.timeout}ms`,\n });\n }\n return {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode ?? -1,\n success: result.exitCode === 0,\n signal: result.exitCode === null ? \"unknown\" : undefined,\n durationMs: Math.round(performance.now() - started),\n };\n } finally {\n removeAbort();\n }\n },\n async start(command, runOptions) {\n assertNotAborted(runOptions.signal);\n const events: ProcessOutputEvent[] = [];\n const waiters = new Set<() => void>();\n let state: \"running\" | \"exited\" | \"killed\" = \"running\";\n const wake = () => {\n for (const waiter of waiters) waiter();\n waiters.clear();\n };\n const push = (stream: \"stdout\" | \"stderr\", data: string) => {\n events.push({ stream, data, timestamp: new Date() });\n wake();\n };\n const handle = raw.exec(commandString(command), {\n cwd: runOptions.cwd,\n env: { ...runOptions.env },\n timeoutSec: timeoutSeconds(runOptions.timeout),\n onStdout: (chunk) => push(\"stdout\", chunk),\n onStderr: (chunk) => push(\"stderr\", chunk),\n });\n const removeAbort = bindAbort(handle, runOptions.signal);\n const completed = handle\n .then((result) => ({ exitCode: result.exitCode ?? -1 }))\n .finally(() => {\n if (state === \"running\") state = \"exited\";\n removeAbort();\n wake();\n });\n const id = await handle.sessionName;\n\n return {\n id,\n async status() {\n return state;\n },\n async *output() {\n let index = 0;\n while (state === \"running\" || index < events.length) {\n while (index < events.length) yield events[index++]!;\n if (state !== \"running\") break;\n await new Promise<void>((resolve) => waiters.add(resolve));\n }\n },\n async write() {\n unsupported(\"railway\", \"process.stdin\");\n },\n wait: () => completed,\n async kill(signal = \"SIGTERM\") {\n const nativeSignal = signal.replace(/^SIG/, \"\") as ExecSignal;\n await handle.kill(nativeSignal);\n state = \"killed\";\n wake();\n },\n } satisfies SandboxProcess;\n },\n async expose() {\n unsupported(\"railway\", \"ports.expose\");\n },\n snapshots: {\n async create(snapshotOptions) {\n const checkpoint = await raw.checkpoint(\n snapshotOptions?.name ?? `sandbox-sdk-${Date.now()}`,\n );\n return {\n id: checkpoint.id,\n name: checkpoint.key,\n mode: \"filesystem\",\n createdAt: new Date(checkpoint.createdAt),\n } satisfies SandboxSnapshot;\n },\n async delete(snapshot) {\n await RailwaySandbox.deleteCheckpoint(\n typeof snapshot === \"string\" ? snapshot : snapshot.id,\n credentials,\n );\n },\n async restore() {\n unsupported(\"railway\", \"snapshot.restore\");\n },\n },\n async stop() {\n await raw.destroy();\n },\n };\n },\n };\n}\n\nfunction timeoutSeconds(timeout?: number): number | undefined {\n return timeout === undefined ? undefined : Math.max(1, Math.ceil(timeout / 1_000));\n}\n\nfunction bindAbort(handle: ExecHandle, signal?: AbortSignal): () => void {\n if (!signal) return () => undefined;\n const abort = () => void handle.kill(\"TERM\").catch(() => undefined);\n signal.addEventListener(\"abort\", abort, { once: true });\n return () => signal.removeEventListener(\"abort\", abort);\n}\n\nasync function awaitCreation(\n promise: Promise<RailwaySandbox>,\n signal?: AbortSignal,\n timeoutMs?: number,\n): Promise<RailwaySandbox> {\n if (!signal && timeoutMs === undefined) return promise;\n return new Promise<RailwaySandbox>((resolve, reject) => {\n let settled = false;\n const finish = (callback: () => void) => {\n if (settled) return;\n settled = true;\n signal?.removeEventListener(\"abort\", onAbort);\n if (timer) clearTimeout(timer);\n callback();\n };\n const onAbort = () =>\n finish(() => reject(signal?.reason ?? new DOMException(\"Aborted\", \"AbortError\")));\n const timer = timeoutMs\n ? setTimeout(\n () => finish(() => reject(new Error(`Sandbox creation timed out after ${timeoutMs}ms`))),\n timeoutMs,\n )\n : undefined;\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n promise.then(\n (sandbox) => {\n if (settled) {\n void sandbox.destroy().catch(() => undefined);\n return;\n }\n finish(() => resolve(sandbox));\n },\n (error) => finish(() => reject(error)),\n );\n });\n}\n\nfunction assertNotAborted(signal?: AbortSignal): void {\n if (signal?.aborted) throw signal.reason ?? new DOMException(\"Aborted\", \"AbortError\");\n}\n\nexport type { RailwaySandbox, SandboxTemplate as RailwaySandboxTemplate };\n"],"mappings":";;;;;;;AA4BA,SAAgB,QAAQ,UAA0B,EAAE,EAAmC;CACrF,MAAM,cAAc;EAClB,OAAO,QAAQ;EACf,eAAe,QAAQ;EACxB;AAED,QAAO;EACL,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;AAC1B,oBAAiB,cAAc,OAAO;GACtC,MAAM,eAAe;IACnB,GAAG;IACH,oBAAoB,QAAQ;IAC5B,kBA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O,EAAE,MAAM,MAAM,CAAC;AACvD,cAAa,OAAO,oBAAoB,SAAS,MAAM;;AAGzD,eAAe,cACb,SACA,QACA,WACyB;AACzB,KAAI,CAAC,UAAU,cAAc,OAAW,QAAO;AAC/C,QAAO,IAAI,SAAyB,SAAS,WAAW;EACtD,IAAI,UAAU;EACd,MAAM,UAAU,aAAyB;AACvC,OAAI,QAAS;AACb,aAAU;AACV,WAAQ,oBAAoB,SAAS,QAAQ;AAC7C,OAAI,MAAO,cAAa,MAAM;AAC9B,aAAU;;EAEZ,MAAM,gBACJ,aAAa,OAAO,QAAQ,UAAU,IAAI,aAAa,WAAW,aAAa,CAAC,CAAC;EACnF,MAAM,QAAQ,YACV,iBACQ,aAAa,uBAAO,IAAI,MAAM,oCAAoC,UAAU,IAAI,CAAC,CAAC,EACxF,UACD,GACD;AACJ,UAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1D,UAAQ,MACL,YAAY;AACX,OAAI,SAAS;AACX,IAAK,QAAQ,SAAS,CAAC,YAAY,OAAU;AAC7C;;AAEF,gBAAa,QAAQ,QAAQ,CAAC;MAE/B,UAAU,aAAa,OAAO,MAAM,CAAC,CACvC;GACD;;AAGJ,SAAS,iBAAiB,QAA4B;AACpD,KAAI,QAAQ,QAAS,OAAM,OAAO,UAAU,IAAI,aAAa,WAAW,aAAa"}
@@ -1,8 +1,8 @@
1
- import "../../types-BTagTtsp.mjs";
2
- import { o as SandboxProvider } from "../../provider-_caCV8kk.mjs";
3
- import "../../index-BMFkO6Fv.mjs";
4
- import "../../sandbox-BUYT-1C9.mjs";
5
- import { a as upstashCapabilities } from "../../capabilities-CMnszzpt.mjs";
1
+ import "../../types-Bv6I2U1c.mjs";
2
+ import { o as SandboxProvider } from "../../provider-DOBErkBO.mjs";
3
+ import "../../index-Dh9xob2s.mjs";
4
+ import "../../sandbox-DdEqoXJF.mjs";
5
+ import { s as upstashCapabilities } from "../../capabilities-BWvOVFbH.mjs";
6
6
  import { Box, BoxConfig } from "@upstash/box";
7
7
 
8
8
  //#region src/providers/upstash/index.d.ts
@@ -1,8 +1,9 @@
1
- import { t as SandboxError } from "../../errors-Ch9PHKTd.mjs";
2
- import "../../capabilities-COKpwoFH.mjs";
3
- import "../../sandbox-BwyHcB_C.mjs";
4
- import { a as upstashCapabilities } from "../../capabilities-CEowrzRM.mjs";
5
- import { i as unsupported, n as portResult, o as withManagedSessions, r as toUint8Array, t as commandString } from "../../provider-utils-DilOYLBO.mjs";
1
+ import { t as SandboxError } from "../../errors-BuF9bYOQ.mjs";
2
+ import "../../capabilities-xs9kaHrK.mjs";
3
+ import "../../sandbox-DgtY5hvt.mjs";
4
+ import { s as upstashCapabilities } from "../../capabilities-CaSNd6J1.mjs";
5
+ import { t as withManagedSessions } from "../../managed-provider-BsZGVQ4I.mjs";
6
+ import { i as unsupported, n as portResult, r as toUint8Array, t as commandString } from "../../provider-utils-CfB9nvJx.mjs";
6
7
  import { Box } from "@upstash/box";
7
8
 
8
9
  //#region src/providers/upstash/index.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["events: ProcessOutputEvent[]","status: \"running\" | \"exited\""],"sources":["../../../src/providers/upstash/index.ts"],"sourcesContent":["import { Box, type BoxConfig, type ExecStreamChunk } from \"@upstash/box\";\nimport { SandboxError } from \"../../core/errors\";\nimport type { SandboxNetworkPolicy, SandboxProvider } from \"../../core/provider\";\nimport type {\n CommandInput,\n ProcessOutputEvent,\n RunOptions,\n SandboxProcess,\n SandboxSnapshot,\n} from \"../../core/types\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\nimport {\n commandString,\n portResult,\n toUint8Array,\n unsupported,\n} from \"../../internal/provider-utils\";\nimport { upstashCapabilities } from \"../capabilities\";\n\nexport type UpstashOptions = Omit<BoxConfig, \"env\"> & {\n /** Expose ports publicly. Set to false to return bearer-token URLs. */\n public?: boolean;\n};\n\nexport { upstashCapabilities } from \"../capabilities\";\n\nexport function upstash(options: UpstashOptions = {}): SandboxProvider<Box> {\n const { public: publicPorts = true, ...boxOptions } = options;\n\n return withManagedSessions(\n {\n id: \"upstash\",\n capabilities: upstashCapabilities,\n async create(createOptions) {\n assertNotAborted(createOptions.signal);\n const raw = await Box.create({\n ...boxOptions,\n env: { ...createOptions.env },\n timeout: boxOptions.timeout ?? createOptions.timeout,\n });\n const remoteCwd = raw.cwd;\n const toRemotePath = (path: string) =>\n replacePathPrefix(path, createOptions.cwd, remoteCwd);\n const toVirtualPath = (path: string) =>\n replacePathPrefix(path, remoteCwd, createOptions.cwd);\n\n return {\n id: raw.id,\n raw,\n capabilities: upstashCapabilities,\n files: {\n async write(path, value) {\n const content = Buffer.from(await toUint8Array(value)).toString(\"base64\");\n await raw.files.write({\n path: toRemotePath(path),\n content,\n encoding: \"base64\",\n });\n },\n async read(path) {\n const content = await raw.files.read(toRemotePath(path), {\n encoding: \"base64\",\n });\n return new Uint8Array(Buffer.from(content, \"base64\"));\n },\n async list(path) {\n return (await raw.files.list(toRemotePath(path))).map((entry) => ({\n name: entry.name,\n path: toVirtualPath(entry.path),\n type: entry.is_dir ? (\"directory\" as const) : (\"file\" as const),\n size: entry.size,\n }));\n },\n async mkdir(path) {\n const result = await raw.exec.command(`mkdir -p ${shellQuote(toRemotePath(path))}`);\n assertCommandSucceeded(result.exitCode, result.result, \"files.mkdir\");\n },\n async remove(path) {\n const result = await raw.exec.command(`rm -rf -- ${shellQuote(toRemotePath(path))}`);\n assertCommandSucceeded(result.exitCode, result.result, \"files.remove\");\n },\n async exists(path) {\n const result = await raw.exec.command(`test -e ${shellQuote(toRemotePath(path))}`);\n return result.exitCode === 0;\n },\n },\n async run(command, runOptions) {\n assertNotAborted(runOptions.signal);\n const started = performance.now();\n const run = await raw.exec.command(\n scopedCommand(command, runOptions, createOptions.cwd, remoteCwd),\n );\n if (runOptions.timeout !== undefined && run.exitCode === 124) {\n throw new SandboxError({\n code: \"timeout\",\n provider: \"upstash\",\n operation: \"process.run\",\n message: `Command timed out after ${runOptions.timeout}ms`,\n });\n }\n return {\n stdout: run.result,\n stderr: \"\",\n exitCode: run.exitCode ?? 1,\n success: run.exitCode === 0,\n durationMs: Math.round(performance.now() - started),\n };\n },\n async start(command, runOptions) {\n assertNotAborted(runOptions.signal);\n const handle = await raw.exec.stream(\n scopedCommand(command, runOptions, createOptions.cwd, remoteCwd),\n );\n const events: ProcessOutputEvent[] = [];\n const waiters = new Set<() => void>();\n let status: \"running\" | \"exited\" = \"running\";\n let exitCode = 1;\n const wake = () => {\n for (const waiter of waiters) waiter();\n waiters.clear();\n };\n const streamCompleted = consumeStream(handle, (chunk) => {\n if (chunk.type === \"output\") {\n events.push({\n stream: \"stdout\",\n data: chunk.data,\n timestamp: new Date(),\n });\n wake();\n } else {\n exitCode = chunk.exitCode;\n }\n })\n .then(() => {\n if (status === \"running\") status = \"exited\";\n return { exitCode };\n })\n .catch((error: unknown) => {\n status = \"exited\";\n throw error;\n })\n .finally(() => {\n wake();\n });\n\n return {\n id: handle.id,\n async status() {\n return status;\n },\n async *output() {\n let index = 0;\n while (status === \"running\" || index < events.length) {\n while (index < events.length) yield events[index++]!;\n if (status !== \"running\") break;\n await new Promise<void>((resolve) => waiters.add(resolve));\n }\n },\n async write() {\n unsupported(\"upstash\", \"process.stdin\");\n },\n wait: () => streamCompleted,\n async kill() {\n unsupported(\"upstash\", \"process.cancel\");\n },\n } satisfies SandboxProcess;\n },\n async expose(port) {\n const preview = await raw.getPublicURL(\n port,\n publicPorts ? undefined : { bearerToken: true },\n );\n const token = preview.token;\n return portResult(\n port,\n preview.url,\n !token,\n Boolean(token),\n token\n ? (path = \"/\", init = {}) =>\n fetch(new URL(path, preview.url), {\n ...init,\n headers: {\n ...Object.fromEntries(new Headers(init.headers)),\n authorization: `Bearer ${token}`,\n },\n })\n : undefined,\n );\n },\n snapshots: {\n async create(snapshotOptions) {\n const snapshot = await raw.snapshot({\n name: snapshotOptions?.name ?? `sandbox-sdk-${Date.now()}`,\n });\n return {\n id: snapshot.id,\n name: snapshot.name,\n mode: \"filesystem\",\n createdAt: timestamp(snapshot.created_at),\n } satisfies SandboxSnapshot;\n },\n async delete(snapshot) {\n await raw.deleteSnapshot(typeof snapshot === \"string\" ? snapshot : snapshot.id);\n },\n async restore() {\n unsupported(\"upstash\", \"snapshot.restore\");\n },\n },\n async stop() {\n await raw.delete();\n },\n };\n },\n },\n [],\n {\n stop: (sandbox) => sandbox.raw.pause(),\n resume: (sandbox) => sandbox.raw.resume(),\n destroy: (sandbox) => sandbox.raw.delete(),\n setNetworkPolicy: (sandbox, policy) => sandbox.raw.updateNetworkPolicy(networkPolicy(policy)),\n },\n );\n}\n\nasync function consumeStream(\n stream: AsyncIterable<ExecStreamChunk>,\n onChunk: (chunk: ExecStreamChunk) => void,\n): Promise<void> {\n for await (const chunk of stream) onChunk(chunk);\n}\n\nfunction scopedCommand(\n input: CommandInput,\n options: RunOptions,\n virtualCwd: string,\n remoteCwd: string,\n): string {\n const environment = Object.entries(options.env ?? {}).map(([key, value]) =>\n shellQuote(`${key}=${value}`),\n );\n const command = commandString(input);\n const shell = `sh -c ${shellQuote(command)}`;\n const timed = options.timeout\n ? `timeout ${Math.max(1, Math.ceil(options.timeout / 1_000))}s ${shell}`\n : shell;\n const cwd = replacePathPrefix(options.cwd ?? virtualCwd, virtualCwd, remoteCwd);\n return `cd ${shellQuote(cwd)} && ${\n environment.length ? `env ${environment.join(\" \")} ` : \"\"\n }${timed} 2>&1`;\n}\n\nfunction replacePathPrefix(path: string, from: string, to: string): string {\n if (path === from) return to;\n if (path.startsWith(`${from}/`)) return `${to}${path.slice(from.length)}`;\n return path;\n}\n\nfunction shellQuote(value: string): string {\n return `'${value.replaceAll(\"'\", `'\"'\"'`)}'`;\n}\n\nfunction assertNotAborted(signal?: AbortSignal): void {\n if (signal?.aborted) throw signal.reason ?? new DOMException(\"Aborted\", \"AbortError\");\n}\n\nfunction assertCommandSucceeded(exitCode: number | null, output: string, operation: string): void {\n if (exitCode === 0) return;\n throw new Error(`${operation} failed${output ? `: ${output}` : \"\"}`);\n}\n\nfunction timestamp(value: number): Date {\n return new Date(value < 1_000_000_000_000 ? value * 1_000 : value);\n}\n\nfunction networkPolicy(policy: SandboxNetworkPolicy): import(\"@upstash/box\").NetworkPolicy {\n if (policy.mode === \"allow-all\" || policy.mode === \"deny-all\") return { mode: policy.mode };\n if (policy.mode === \"native\") return policy.value as import(\"@upstash/box\").NetworkPolicy;\n return {\n mode: \"custom\",\n allowedDomains: [...(policy.allowedHosts ?? [])],\n allowedCidrs: [...(policy.allowedCIDRs ?? [])],\n deniedCidrs: [...(policy.deniedCIDRs ?? [])],\n };\n}\n\nexport type UpstashBox = Box;\n"],"mappings":";;;;;;;;AA0BA,SAAgB,QAAQ,UAA0B,EAAE,EAAwB;CAC1E,MAAM,EAAE,QAAQ,cAAc,MAAM,GAAG,eAAe;AAEtD,QAAO,oBACL;EACE,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;AAC1B,oBAAiB,cAAc,OAAO;GACtC,MAAM,MAAM,MAAM,IAAI,OAAO;IAC3B,GAAG;IACH,KAAK,EAAE,GAAG,cAAc,KAAK;IAC7B,SAAS,WAAW,WAAW,cAAc;IAC9C,CAAC;GACF,MAAM,YAAY,IAAI;GACtB,MAAM,gBAAgB,SACpB,kBAAkB,MAAM,cAAc,KAAK,UAAU;GACvD,MAAM,iBAAiB,SACrB,kBAAkB,MAAM,WAAW,cAAc,IAAI;AAEvD,UAAO;IACL,IAAI,IAAI;IACR;IACA,cAAc;IACd,OAAO;KACL,MAAM,MAAM,MAAM,OAAO;MACvB,MAAM,UAAU,OAAO,KAAK,MAAM,aAAa,MAAM,CAAC,CAAC,SAAS,SAAS;AACzE,YAAM,IAAI,MAAM,MAAM;OACpB,MAAM,aAAa,KAAK;OACxB;OACA,UAAU;OACX,CAAC;;KAEJ,MAAM,KAAK,MAAM;MACf,MAAM,UAAU,MAAM,IAAI,MAAM,KAAK,aAAa,KAAK,EAAE,EACvD,UAAU,UACX,CAA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OAAO,YAAY,KAAK,IAAI,CAAC,KAAK,KACtD,MAAM;;AAGX,SAAS,kBAAkB,MAAc,MAAc,IAAoB;AACzE,KAAI,SAAS,KAAM,QAAO;AAC1B,KAAI,KAAK,WAAW,GAAG,KAAK,GAAG,CAAE,QAAO,GAAG,KAAK,KAAK,MAAM,KAAK,OAAO;AACvE,QAAO;;AAGT,SAAS,WAAW,OAAuB;AACzC,QAAO,IAAI,MAAM,WAAW,KAAK,QAAQ,CAAC;;AAG5C,SAAS,iBAAiB,QAA4B;AACpD,KAAI,QAAQ,QAAS,OAAM,OAAO,UAAU,IAAI,aAAa,WAAW,aAAa;;AAGvF,SAAS,uBAAuB,UAAyB,QAAgB,WAAyB;AAChG,KAAI,aAAa,EAAG;AACpB,OAAM,IAAI,MAAM,GAAG,UAAU,SAAS,SAAS,KAAK,WAAW,KAAK;;AAGtE,SAAS,UAAU,OAAqB;AACtC,QAAO,IAAI,KAAK,QAAQ,eAAoB,QAAQ,MAAQ,MAAM;;AAGpE,SAAS,cAAc,QAAoE;AACzF,KAAI,OAAO,SAAS,eAAe,OAAO,SAAS,WAAY,QAAO,EAAE,MAAM,OAAO,MAAM;AAC3F,KAAI,OAAO,SAAS,SAAU,QAAO,OAAO;AAC5C,QAAO;EACL,MAAM;EACN,gBAAgB,CAAC,GAAI,OAAO,gBAAgB,EAAE,CAAE;EAChD,cAAc,CAAC,GAAI,OAAO,gBAAgB,EAAE,CAAE;EAC9C,aAAa,CAAC,GAAI,OAAO,eAAe,EAAE,CAAE;EAC7C"}
1
+ {"version":3,"file":"index.mjs","names":["events: ProcessOutputEvent[]","status: \"running\" | \"exited\""],"sources":["../../../src/providers/upstash/index.ts"],"sourcesContent":["import { Box, type BoxConfig, type ExecStreamChunk } from \"@upstash/box\";\nimport { SandboxError } from \"../../core/errors\";\nimport type { SandboxNetworkPolicy, SandboxProvider } from \"../../core/provider\";\nimport type {\n CommandInput,\n ProcessOutputEvent,\n RunOptions,\n SandboxProcess,\n SandboxSnapshot,\n} from \"../../core/types\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\nimport {\n commandString,\n portResult,\n toUint8Array,\n unsupported,\n} from \"../../internal/provider-utils\";\nimport { upstashCapabilities } from \"../capabilities\";\n\nexport type UpstashOptions = Omit<BoxConfig, \"env\"> & {\n /** Expose ports publicly. Set to false to return bearer-token URLs. */\n public?: boolean;\n};\n\nexport { upstashCapabilities } from \"../capabilities\";\n\nexport function upstash(options: UpstashOptions = {}): SandboxProvider<Box> {\n const { public: publicPorts = true, ...boxOptions } = options;\n\n return withManagedSessions(\n {\n id: \"upstash\",\n capabilities: upstashCapabilities,\n async create(createOptions) {\n assertNotAborted(createOptions.signal);\n const raw = await Box.create({\n ...boxOptions,\n env: { ...createOptions.env },\n timeout: boxOptions.timeout ?? createOptions.timeout,\n });\n const remoteCwd = raw.cwd;\n const toRemotePath = (path: string) =>\n replacePathPrefix(path, createOptions.cwd, remoteCwd);\n const toVirtualPath = (path: string) =>\n replacePathPrefix(path, remoteCwd, createOptions.cwd);\n\n return {\n id: raw.id,\n raw,\n capabilities: upstashCapabilities,\n files: {\n async write(path, value) {\n const content = Buffer.from(await toUint8Array(value)).toString(\"base64\");\n await raw.files.write({\n path: toRemotePath(path),\n content,\n encoding: \"base64\",\n });\n },\n async read(path) {\n const content = await raw.files.read(toRemotePath(path), {\n encoding: \"base64\",\n });\n return new Uint8Array(Buffer.from(content, \"base64\"));\n },\n async list(path) {\n return (await raw.files.list(toRemotePath(path))).map((entry) => ({\n name: entry.name,\n path: toVirtualPath(entry.path),\n type: entry.is_dir ? (\"directory\" as const) : (\"file\" as const),\n size: entry.size,\n }));\n },\n async mkdir(path) {\n const result = await raw.exec.command(`mkdir -p ${shellQuote(toRemotePath(path))}`);\n assertCommandSucceeded(result.exitCode, result.result, \"files.mkdir\");\n },\n async remove(path) {\n const result = await raw.exec.command(`rm -rf -- ${shellQuote(toRemotePath(path))}`);\n assertCommandSucceeded(result.exitCode, result.result, \"files.remove\");\n },\n async exists(path) {\n const result = await raw.exec.command(`test -e ${shellQuote(toRemotePath(path))}`);\n return result.exitCode === 0;\n },\n },\n async run(command, runOptions) {\n assertNotAborted(runOptions.signal);\n const started = performance.now();\n const run = await raw.exec.command(\n scopedCommand(command, runOptions, createOptions.cwd, remoteCwd),\n );\n if (runOptions.timeout !== undefined && run.exitCode === 124) {\n throw new SandboxError({\n code: \"timeout\",\n provider: \"upstash\",\n operation: \"process.run\",\n message: `Command timed out after ${runOptions.timeout}ms`,\n });\n }\n return {\n stdout: run.result,\n stderr: \"\",\n exitCode: run.exitCode ?? 1,\n success: run.exitCode === 0,\n durationMs: Math.round(performance.now() - started),\n };\n },\n async start(command, runOptions) {\n assertNotAborted(runOptions.signal);\n const handle = await raw.exec.stream(\n scopedCommand(command, runOptions, createOptions.cwd, remoteCwd),\n );\n const events: ProcessOutputEvent[] = [];\n const waiters = new Set<() => void>();\n let status: \"running\" | \"exited\" = \"running\";\n let exitCode = 1;\n const wake = () => {\n for (const waiter of waiters) waiter();\n waiters.clear();\n };\n const streamCompleted = consumeStream(handle, (chunk) => {\n if (chunk.type === \"output\") {\n events.push({\n stream: \"stdout\",\n data: chunk.data,\n timestamp: new Date(),\n });\n wake();\n } else {\n exitCode = chunk.exitCode;\n }\n })\n .then(() => {\n if (status === \"running\") status = \"exited\";\n return { exitCode };\n })\n .catch((error: unknown) => {\n status = \"exited\";\n throw error;\n })\n .finally(() => {\n wake();\n });\n\n return {\n id: handle.id,\n async status() {\n return status;\n },\n async *output() {\n let index = 0;\n while (status === \"running\" || index < events.length) {\n while (index < events.length) yield events[index++]!;\n if (status !== \"running\") break;\n await new Promise<void>((resolve) => waiters.add(resolve));\n }\n },\n async write() {\n unsupported(\"upstash\", \"process.stdin\");\n },\n wait: () => streamCompleted,\n async kill() {\n unsupported(\"upstash\", \"process.cancel\");\n },\n } satisfies SandboxProcess;\n },\n async expose(port) {\n const preview = await raw.getPublicURL(\n port,\n publicPorts ? undefined : { bearerToken: true },\n );\n const token = preview.token;\n return portResult(\n port,\n preview.url,\n !token,\n Boolean(token),\n token\n ? (path = \"/\", init = {}) =>\n fetch(new URL(path, preview.url), {\n ...init,\n headers: {\n ...Object.fromEntries(new Headers(init.headers)),\n authorization: `Bearer ${token}`,\n },\n })\n : undefined,\n );\n },\n snapshots: {\n async create(snapshotOptions) {\n const snapshot = await raw.snapshot({\n name: snapshotOptions?.name ?? `sandbox-sdk-${Date.now()}`,\n });\n return {\n id: snapshot.id,\n name: snapshot.name,\n mode: \"filesystem\",\n createdAt: timestamp(snapshot.created_at),\n } satisfies SandboxSnapshot;\n },\n async delete(snapshot) {\n await raw.deleteSnapshot(typeof snapshot === \"string\" ? snapshot : snapshot.id);\n },\n async restore() {\n unsupported(\"upstash\", \"snapshot.restore\");\n },\n },\n async stop() {\n await raw.delete();\n },\n };\n },\n },\n [],\n {\n stop: (sandbox) => sandbox.raw.pause(),\n resume: (sandbox) => sandbox.raw.resume(),\n destroy: (sandbox) => sandbox.raw.delete(),\n setNetworkPolicy: (sandbox, policy) => sandbox.raw.updateNetworkPolicy(networkPolicy(policy)),\n },\n );\n}\n\nasync function consumeStream(\n stream: AsyncIterable<ExecStreamChunk>,\n onChunk: (chunk: ExecStreamChunk) => void,\n): Promise<void> {\n for await (const chunk of stream) onChunk(chunk);\n}\n\nfunction scopedCommand(\n input: CommandInput,\n options: RunOptions,\n virtualCwd: string,\n remoteCwd: string,\n): string {\n const environment = Object.entries(options.env ?? {}).map(([key, value]) =>\n shellQuote(`${key}=${value}`),\n );\n const command = commandString(input);\n const shell = `sh -c ${shellQuote(command)}`;\n const timed = options.timeout\n ? `timeout ${Math.max(1, Math.ceil(options.timeout / 1_000))}s ${shell}`\n : shell;\n const cwd = replacePathPrefix(options.cwd ?? virtualCwd, virtualCwd, remoteCwd);\n return `cd ${shellQuote(cwd)} && ${\n environment.length ? `env ${environment.join(\" \")} ` : \"\"\n }${timed} 2>&1`;\n}\n\nfunction replacePathPrefix(path: string, from: string, to: string): string {\n if (path === from) return to;\n if (path.startsWith(`${from}/`)) return `${to}${path.slice(from.length)}`;\n return path;\n}\n\nfunction shellQuote(value: string): string {\n return `'${value.replaceAll(\"'\", `'\"'\"'`)}'`;\n}\n\nfunction assertNotAborted(signal?: AbortSignal): void {\n if (signal?.aborted) throw signal.reason ?? new DOMException(\"Aborted\", \"AbortError\");\n}\n\nfunction assertCommandSucceeded(exitCode: number | null, output: string, operation: string): void {\n if (exitCode === 0) return;\n throw new Error(`${operation} failed${output ? `: ${output}` : \"\"}`);\n}\n\nfunction timestamp(value: number): Date {\n return new Date(value < 1_000_000_000_000 ? value * 1_000 : value);\n}\n\nfunction networkPolicy(policy: SandboxNetworkPolicy): import(\"@upstash/box\").NetworkPolicy {\n if (policy.mode === \"allow-all\" || policy.mode === \"deny-all\") return { mode: policy.mode };\n if (policy.mode === \"native\") return policy.value as import(\"@upstash/box\").NetworkPolicy;\n return {\n mode: \"custom\",\n allowedDomains: [...(policy.allowedHosts ?? [])],\n allowedCidrs: [...(policy.allowedCIDRs ?? [])],\n deniedCidrs: [...(policy.deniedCIDRs ?? [])],\n };\n}\n\nexport type UpstashBox = Box;\n"],"mappings":";;;;;;;;;AA0BA,SAAgB,QAAQ,UAA0B,EAAE,EAAwB;CAC1E,MAAM,EAAE,QAAQ,cAAc,MAAM,GAAG,eAAe;AAEtD,QAAO,oBACL;EACE,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;AAC1B,oBAAiB,cAAc,OAAO;GACtC,MAAM,MAAM,MAAM,IAAI,OAAO;IAC3B,GAAG;IACH,KAAK,EAAE,GAAG,cAAc,KAAK;IAC7B,SAAS,WAAW,WAAW,cAAc;IAC9C,CAAC;GACF,MAAM,YAAY,IAAI;GACtB,MAAM,gBAAgB,SACpB,kBAAkB,MAAM,cAAc,KAAK,UAAU;GACvD,MAAM,iBAAiB,SACrB,kBAAkB,MAAM,WAAW,cAAc,IAAI;AAEvD,UAAO;IACL,IAAI,IAAI;IACR;IACA,cAAc;IACd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CAAE;EAC7C"}
@@ -1,8 +1,8 @@
1
- import "../../types-BTagTtsp.mjs";
2
- import { o as SandboxProvider } from "../../provider-_caCV8kk.mjs";
3
- import "../../index-BMFkO6Fv.mjs";
4
- import "../../sandbox-BUYT-1C9.mjs";
5
- import { o as vercelCapabilities } from "../../capabilities-CMnszzpt.mjs";
1
+ import "../../types-Bv6I2U1c.mjs";
2
+ import { o as SandboxProvider } from "../../provider-DOBErkBO.mjs";
3
+ import "../../index-Dh9xob2s.mjs";
4
+ import "../../sandbox-DdEqoXJF.mjs";
5
+ import { c as vercelCapabilities } from "../../capabilities-BWvOVFbH.mjs";
6
6
  import { Sandbox as VercelSandbox } from "@vercel/sandbox";
7
7
 
8
8
  //#region src/providers/vercel/index.d.ts
@@ -10,6 +10,7 @@ interface VercelBaseOptions {
10
10
  runtime?: "node24" | "node22" | "node26" | "python3.13" | (string & {});
11
11
  name?: string;
12
12
  ports?: number[];
13
+ /** Whether the sandbox persists across sessions. Defaults to true. */
13
14
  persistent?: boolean;
14
15
  }
15
16
  type VercelOptions = VercelBaseOptions & ({
@@ -1,8 +1,9 @@
1
- import { r as normalizeError, t as SandboxError } from "../../errors-Ch9PHKTd.mjs";
2
- import "../../capabilities-COKpwoFH.mjs";
3
- import "../../sandbox-BwyHcB_C.mjs";
4
- import { o as vercelCapabilities } from "../../capabilities-CEowrzRM.mjs";
5
- import { i as unsupported, n as portResult, o as withManagedSessions, r as toUint8Array } from "../../provider-utils-DilOYLBO.mjs";
1
+ import { r as normalizeError, t as SandboxError } from "../../errors-BuF9bYOQ.mjs";
2
+ import "../../capabilities-xs9kaHrK.mjs";
3
+ import "../../sandbox-DgtY5hvt.mjs";
4
+ import { c as vercelCapabilities } from "../../capabilities-CaSNd6J1.mjs";
5
+ import { t as withManagedSessions } from "../../managed-provider-BsZGVQ4I.mjs";
6
+ import { i as unsupported, n as portResult, r as toUint8Array } from "../../provider-utils-CfB9nvJx.mjs";
6
7
  import { Sandbox, Snapshot } from "@vercel/sandbox";
7
8
 
8
9
  //#region src/providers/vercel/index.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["VercelSandbox","events: ProcessOutputEvent[]","VercelSnapshot"],"sources":["../../../src/providers/vercel/index.ts"],"sourcesContent":["import { Sandbox as VercelSandbox, Snapshot as VercelSnapshot } from \"@vercel/sandbox\";\nimport { normalizeError, SandboxError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type {\n CommandInput,\n ProcessOutputEvent,\n SandboxProcess,\n SandboxSnapshot,\n} from \"../../core/types\";\nimport { portResult, toUint8Array, unsupported } from \"../../internal/provider-utils\";\nimport { vercelCapabilities } from \"../capabilities\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\n\ninterface VercelBaseOptions {\n runtime?: \"node24\" | \"node22\" | \"node26\" | \"python3.13\" | (string & {});\n name?: string;\n ports?: number[];\n persistent?: boolean;\n}\n\nexport type VercelOptions = VercelBaseOptions &\n (\n | { token: string; teamId: string; projectId: string }\n | { token?: never; teamId?: never; projectId?: never }\n );\n\nexport { vercelCapabilities } from \"../capabilities\";\n\nexport function vercel(options: VercelOptions = {}): SandboxProvider<VercelSandbox> {\n return withManagedSessions(\n {\n id: \"vercel\",\n capabilities: vercelCapabilities,\n async create(createOptions) {\n const credentials =\n options.token && options.teamId && options.projectId\n ? {\n token: options.token,\n teamId: options.teamId,\n projectId: options.projectId,\n }\n : {};\n const exposed = new Set(options.ports ?? []);\n const raw = await VercelSandbox.create({\n ...credentials,\n runtime: options.runtime ?? \"node24\",\n name: options.name,\n ports: [...exposed],\n persistent: options.persistent,\n timeout: createOptions.timeout,\n env: { ...createOptions.env },\n signal: createOptions.signal,\n });\n const snapshots = new Map<string, VercelSnapshot>();\n await raw.fs.mkdir(createOptions.cwd, { recursive: true });\n return {\n id: raw.name,\n raw,\n capabilities: vercelCapabilities,\n files: {\n async write(path, value) {\n await raw.fs.writeFile(path, await toUint8Array(value));\n },\n async read(path) {\n return new Uint8Array(await raw.fs.readFile(path));\n },\n async list(path) {\n const entries = await raw.fs.readdir(path, {\n withFileTypes: true,\n });\n return Promise.all(\n entries.map(async (entry) => {\n const entryPath = `${path.replace(/\\/$/, \"\")}/${entry.name}`;\n const info = await raw.fs.lstat(entryPath);\n return {\n name: entry.name,\n path: entryPath,\n type: entry.isFile()\n ? (\"file\" as const)\n : entry.isDirectory()\n ? (\"directory\" as const)\n : entry.isSymbolicLink()\n ? (\"symlink\" as const)\n : (\"unknown\" as const),\n size: entry.isFile() ? info.size : undefined,\n };\n }),\n );\n },\n async mkdir(path) {\n await raw.fs.mkdir(path, { recursive: true });\n },\n async remove(path) {\n await raw.fs.rm(path, { recursive: true, force: true });\n },\n exists: (path) => raw.fs.exists(path),\n },\n async run(command, runOptions) {\n try {\n const result = await runCommand(raw, command, runOptions, false);\n const [stdout, stderr] = await Promise.all([\n result.stdout({ signal: runOptions.signal }),\n result.stderr({ signal: runOptions.signal }),\n ]);\n if (\n runOptions.timeout !== undefined &&\n result.exitCode === 137 &&\n result.durationMs !== undefined &&\n result.durationMs >= runOptions.timeout\n ) {\n throw new SandboxError({\n code: \"timeout\",\n provider: \"vercel\",\n operation: \"process.run\",\n message: `Command timed out after ${runOptions.timeout}ms`,\n });\n }\n return {\n stdout,\n stderr,\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: result.durationMs,\n };\n } catch (error) {\n throw normalizeError(\"vercel\", \"process.run\", error);\n }\n },\n async start(command, runOptions) {\n const handle = await runCommand(raw, command, runOptions, true);\n const events: ProcessOutputEvent[] = [];\n let running = true;\n const stream = handle.logs({ signal: runOptions.signal });\n const completed = handle.wait().then((result) => ({ exitCode: result.exitCode }));\n const process: SandboxProcess = {\n id: handle.cmdId,\n async status() {\n return running ? \"running\" : \"exited\";\n },\n async *output() {\n try {\n for await (const event of stream) {\n const normalized = {\n stream: event.stream,\n data: event.data,\n timestamp: new Date(),\n } satisfies ProcessOutputEvent;\n events.push(normalized);\n yield normalized;\n }\n } finally {\n running = false;\n }\n },\n async write() {\n unsupported(\"vercel\", \"process.stdin\");\n },\n wait: () => completed,\n async kill(signal = \"SIGTERM\") {\n await handle.kill(signal as Parameters<typeof handle.kill>[0]);\n running = false;\n },\n };\n return process;\n },\n async expose(port) {\n if (!exposed.has(port)) {\n exposed.add(port);\n await raw.update({ ports: [...exposed] });\n }\n const url = raw.domain(port);\n return portResult(port, url, true, false);\n },\n snapshots: {\n async create() {\n const snapshot = await raw.snapshot();\n snapshots.set(snapshot.snapshotId, snapshot);\n return {\n id: snapshot.snapshotId,\n mode: \"filesystem\",\n createdAt: snapshot.createdAt,\n } satisfies SandboxSnapshot;\n },\n async delete(snapshot) {\n const id = typeof snapshot === \"string\" ? snapshot : snapshot.id;\n const native =\n snapshots.get(id) ?? (await VercelSnapshot.get({ snapshotId: id, ...credentials }));\n await native.delete();\n snapshots.delete(id);\n },\n async restore() {\n unsupported(\"vercel\", \"snapshot.restore\");\n },\n },\n async stop() {\n if (raw.status !== \"stopped\") await raw.stop();\n },\n };\n },\n },\n options.ports,\n {\n stop: async (sandbox) => {\n await sandbox.raw.stop();\n },\n destroy: (sandbox) => sandbox.raw.delete(),\n setPorts: (sandbox, ports, signal) => sandbox.raw.update({ ports: [...ports] }, { signal }),\n setNetworkPolicy: (sandbox, policy) =>\n sandbox.raw.update({\n networkPolicy:\n policy.mode === \"allow-all\" || policy.mode === \"deny-all\"\n ? policy.mode\n : policy.mode === \"native\"\n ? (policy.value as import(\"@vercel/sandbox\").NetworkPolicy)\n : { allow: [...(policy.allowedHosts ?? [])] },\n }),\n },\n );\n}\n\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: false,\n): Promise<import(\"@vercel/sandbox\").CommandFinished>;\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: true,\n): Promise<import(\"@vercel/sandbox\").Command>;\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: boolean,\n) {\n const command = typeof input === \"string\" ? { command: \"/bin/sh\", args: [\"-lc\", input] } : input;\n return raw.runCommand({\n cmd: command.command,\n args: [...(command.args ?? [])],\n cwd: options.cwd,\n env: { ...options.env },\n signal: options.signal,\n timeoutMs: options.timeout,\n detached,\n });\n}\n\nexport type { VercelSandbox };\n"],"mappings":";;;;;;;;AA4BA,SAAgB,OAAO,UAAyB,EAAE,EAAkC;AAClF,QAAO,oBACL;EACE,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;GAC1B,MAAM,cACJ,QAAQ,SAAS,QAAQ,UAAU,QAAQ,YACvC;IACE,OAAO,QAAQ;IACf,QAAQ,QAAQ;IAChB,WAAW,QAAQ;IACpB,GACD,EAAE;GACR,MAAM,UAAU,IAAI,IAAI,QAAQ,SAAS,EAAE,CAAC;GAC5C,MAAM,MAAM,MAAMA,QAAc,OAAO;IACrC,GAAG;IACH,SAAS,QAAQ,WAAW;IAC5B,MAAM,QAAQ;IACd,OAAO,CAAC,GAAG,QAAQ;IACnB,YAAY,QAAQ;IACpB,SAAS,cAAc;IACvB,KAAK,EAAE,GAAG,cAAc,KAAK;IAC7B,QAAQ,cAAc;IACvB,CAAC;GACF,MAAM,4BAAY,IAAI,KAA6B;AACnD,SAAM,IAAI,GAAG,MAAM,cAAc,KAAK,EAAE,WAAW,MAAM,CAAC;AAC1D,UAAO;IACL,IAAI,IAAI;IACR;IACA,cAAc;IACd,OAAO;KACL,MAAM,MAAM,MAAM,OAAO;AACvB,YAAM,IAAI,GAAG,UAAU,MAAM,MAAM,aAAa,MAAM,CAAC;;KAEzD,MAAM,KAAK,MAAM;AACf,aAAO,IAAI,WAAW,MAAM,IAAI,GAAG,SAAS,KAAK,CAAC;;KAEpD,MAAM,KAAK,MAAM;MACf,MAAM,UAAU,MAAM,IAAI,GAAG,QAAQ,MAAM,EACzC,eAAe,MAChB,CAAC;AACF,aAAO,QAAQ,IACb,QAAQ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U,mBAAmB;;KAE5C;IACD,MAAM,OAAO;AACX,SAAI,IAAI,WAAW,UAAW,OAAM,IAAI,MAAM;;IAEjD;;EAEJ,EACD,QAAQ,OACR;EACE,MAAM,OAAO,YAAY;AACvB,SAAM,QAAQ,IAAI,MAAM;;EAE1B,UAAU,YAAY,QAAQ,IAAI,QAAQ;EAC1C,WAAW,SAAS,OAAO,WAAW,QAAQ,IAAI,OAAO,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,EAAE,EAAE,QAAQ,CAAC;EAC3F,mBAAmB,SAAS,WAC1B,QAAQ,IAAI,OAAO,EACjB,eACE,OAAO,SAAS,eAAe,OAAO,SAAS,aAC3C,OAAO,OACP,OAAO,SAAS,WACb,OAAO,QACR,EAAE,OAAO,CAAC,GAAI,OAAO,gBAAgB,EAAE,CAAE,EAAE,EACpD,CAAC;EACL,CACF;;AAeH,eAAe,WACb,KACA,OACA,SACA,UACA;CACA,MAAM,UAAU,OAAO,UAAU,WAAW;EAAE,SAAS;EAAW,MAAM,CAAC,OAAO,MAAM;EAAE,GAAG;AAC3F,QAAO,IAAI,WAAW;EACpB,KAAK,QAAQ;EACb,MAAM,CAAC,GAAI,QAAQ,QAAQ,EAAE,CAAE;EAC/B,KAAK,QAAQ;EACb,KAAK,EAAE,GAAG,QAAQ,KAAK;EACvB,QAAQ,QAAQ;EAChB,WAAW,QAAQ;EACnB;EACD,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":["VercelSandbox","events: ProcessOutputEvent[]","VercelSnapshot"],"sources":["../../../src/providers/vercel/index.ts"],"sourcesContent":["import { Sandbox as VercelSandbox, Snapshot as VercelSnapshot } from \"@vercel/sandbox\";\nimport { normalizeError, SandboxError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type {\n CommandInput,\n ProcessOutputEvent,\n SandboxProcess,\n SandboxSnapshot,\n} from \"../../core/types\";\nimport { portResult, toUint8Array, unsupported } from \"../../internal/provider-utils\";\nimport { vercelCapabilities } from \"../capabilities\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\n\ninterface VercelBaseOptions {\n runtime?: \"node24\" | \"node22\" | \"node26\" | \"python3.13\" | (string & {});\n name?: string;\n ports?: number[];\n /** Whether the sandbox persists across sessions. Defaults to true. */\n persistent?: boolean;\n}\n\nexport type VercelOptions = VercelBaseOptions &\n (\n | { token: string; teamId: string; projectId: string }\n | { token?: never; teamId?: never; projectId?: never }\n );\n\nexport { vercelCapabilities } from \"../capabilities\";\n\nexport function vercel(options: VercelOptions = {}): SandboxProvider<VercelSandbox> {\n return withManagedSessions(\n {\n id: \"vercel\",\n capabilities: vercelCapabilities,\n async create(createOptions) {\n const credentials =\n options.token && options.teamId && options.projectId\n ? {\n token: options.token,\n teamId: options.teamId,\n projectId: options.projectId,\n }\n : {};\n const exposed = new Set(options.ports ?? []);\n const raw = await VercelSandbox.create({\n ...credentials,\n runtime: options.runtime ?? \"node24\",\n name: options.name,\n ports: [...exposed],\n persistent: options.persistent,\n timeout: createOptions.timeout,\n env: { ...createOptions.env },\n signal: createOptions.signal,\n });\n const snapshots = new Map<string, VercelSnapshot>();\n await raw.fs.mkdir(createOptions.cwd, { recursive: true });\n return {\n id: raw.name,\n raw,\n capabilities: vercelCapabilities,\n files: {\n async write(path, value) {\n await raw.fs.writeFile(path, await toUint8Array(value));\n },\n async read(path) {\n return new Uint8Array(await raw.fs.readFile(path));\n },\n async list(path) {\n const entries = await raw.fs.readdir(path, {\n withFileTypes: true,\n });\n return Promise.all(\n entries.map(async (entry) => {\n const entryPath = `${path.replace(/\\/$/, \"\")}/${entry.name}`;\n const info = await raw.fs.lstat(entryPath);\n return {\n name: entry.name,\n path: entryPath,\n type: entry.isFile()\n ? (\"file\" as const)\n : entry.isDirectory()\n ? (\"directory\" as const)\n : entry.isSymbolicLink()\n ? (\"symlink\" as const)\n : (\"unknown\" as const),\n size: entry.isFile() ? info.size : undefined,\n };\n }),\n );\n },\n async mkdir(path) {\n await raw.fs.mkdir(path, { recursive: true });\n },\n async remove(path) {\n await raw.fs.rm(path, { recursive: true, force: true });\n },\n exists: (path) => raw.fs.exists(path),\n },\n async run(command, runOptions) {\n try {\n const result = await runCommand(raw, command, runOptions, false);\n const [stdout, stderr] = await Promise.all([\n result.stdout({ signal: runOptions.signal }),\n result.stderr({ signal: runOptions.signal }),\n ]);\n if (\n runOptions.timeout !== undefined &&\n result.exitCode === 137 &&\n result.durationMs !== undefined &&\n result.durationMs >= runOptions.timeout\n ) {\n throw new SandboxError({\n code: \"timeout\",\n provider: \"vercel\",\n operation: \"process.run\",\n message: `Command timed out after ${runOptions.timeout}ms`,\n });\n }\n return {\n stdout,\n stderr,\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: result.durationMs,\n };\n } catch (error) {\n throw normalizeError(\"vercel\", \"process.run\", error);\n }\n },\n async start(command, runOptions) {\n const handle = await runCommand(raw, command, runOptions, true);\n const events: ProcessOutputEvent[] = [];\n let running = true;\n const stream = handle.logs({ signal: runOptions.signal });\n const completed = handle.wait().then((result) => ({ exitCode: result.exitCode }));\n const process: SandboxProcess = {\n id: handle.cmdId,\n async status() {\n return running ? \"running\" : \"exited\";\n },\n async *output() {\n try {\n for await (const event of stream) {\n const normalized = {\n stream: event.stream,\n data: event.data,\n timestamp: new Date(),\n } satisfies ProcessOutputEvent;\n events.push(normalized);\n yield normalized;\n }\n } finally {\n running = false;\n }\n },\n async write() {\n unsupported(\"vercel\", \"process.stdin\");\n },\n wait: () => completed,\n async kill(signal = \"SIGTERM\") {\n await handle.kill(signal as Parameters<typeof handle.kill>[0]);\n running = false;\n },\n };\n return process;\n },\n async expose(port) {\n if (!exposed.has(port)) {\n exposed.add(port);\n await raw.update({ ports: [...exposed] });\n }\n const url = raw.domain(port);\n return portResult(port, url, true, false);\n },\n snapshots: {\n async create() {\n const snapshot = await raw.snapshot();\n snapshots.set(snapshot.snapshotId, snapshot);\n return {\n id: snapshot.snapshotId,\n mode: \"filesystem\",\n createdAt: snapshot.createdAt,\n } satisfies SandboxSnapshot;\n },\n async delete(snapshot) {\n const id = typeof snapshot === \"string\" ? snapshot : snapshot.id;\n const native =\n snapshots.get(id) ?? (await VercelSnapshot.get({ snapshotId: id, ...credentials }));\n await native.delete();\n snapshots.delete(id);\n },\n async restore() {\n unsupported(\"vercel\", \"snapshot.restore\");\n },\n },\n async stop() {\n if (raw.status !== \"stopped\") await raw.stop();\n },\n };\n },\n },\n options.ports,\n {\n stop: async (sandbox) => {\n await sandbox.raw.stop();\n },\n destroy: (sandbox) => sandbox.raw.delete(),\n setPorts: (sandbox, ports, signal) => sandbox.raw.update({ ports: [...ports] }, { signal }),\n setNetworkPolicy: (sandbox, policy) =>\n sandbox.raw.update({\n networkPolicy:\n policy.mode === \"allow-all\" || policy.mode === \"deny-all\"\n ? policy.mode\n : policy.mode === \"native\"\n ? (policy.value as import(\"@vercel/sandbox\").NetworkPolicy)\n : { allow: [...(policy.allowedHosts ?? [])] },\n }),\n },\n );\n}\n\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: false,\n): Promise<import(\"@vercel/sandbox\").CommandFinished>;\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: true,\n): Promise<import(\"@vercel/sandbox\").Command>;\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: boolean,\n) {\n const command = typeof input === \"string\" ? { command: \"/bin/sh\", args: [\"-lc\", input] } : input;\n return raw.runCommand({\n cmd: command.command,\n args: [...(command.args ?? [])],\n cwd: options.cwd,\n env: { ...options.env },\n signal: options.signal,\n timeoutMs: options.timeout,\n detached,\n });\n}\n\nexport type { VercelSandbox };\n"],"mappings":";;;;;;;;;AA6BA,SAAgB,OAAO,UAAyB,EAAE,EAAkC;AAClF,QAAO,oBACL;EACE,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;GAC1B,MAAM,cACJ,Q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E,OAAO,SAAS,eAAe,OAAO,SAAS,aAC3C,OAAO,OACP,OAAO,SAAS,WACb,OAAO,QACR,EAAE,OAAO,CAAC,GAAI,OAAO,gBAAgB,EAAE,CAAE,EAAE,EACpD,CAAC;EACL,CACF;;AAeH,eAAe,WACb,KACA,OACA,SACA,UACA;CACA,MAAM,UAAU,OAAO,UAAU,WAAW;EAAE,SAAS;EAAW,MAAM,CAAC,OAAO,MAAM;EAAE,GAAG;AAC3F,QAAO,IAAI,WAAW;EACpB,KAAK,QAAQ;EACb,MAAM,CAAC,GAAI,QAAQ,QAAQ,EAAE,CAAE;EAC/B,KAAK,QAAQ;EACb,KAAK,EAAE,GAAG,QAAQ,KAAK;EACvB,QAAQ,QAAQ;EAChB,WAAW,QAAQ;EACnB;EACD,CAAC"}
@@ -1,5 +1,5 @@
1
- import { f as Sandbox } from "./types-BTagTtsp.mjs";
2
- import { o as SandboxProvider } from "./provider-_caCV8kk.mjs";
1
+ import { f as Sandbox } from "./types-Bv6I2U1c.mjs";
2
+ import { o as SandboxProvider } from "./provider-DOBErkBO.mjs";
3
3
 
4
4
  //#region src/core/sandbox.d.ts
5
5
  interface CreateSandboxOptions<TProvider extends SandboxProvider<unknown>> {
@@ -10,8 +10,17 @@ interface CreateSandboxOptions<TProvider extends SandboxProvider<unknown>> {
10
10
  signal?: AbortSignal;
11
11
  }
12
12
  type RawOf<TProvider> = TProvider extends SandboxProvider<infer TRaw> ? TRaw : never;
13
+ /**
14
+ * Creates a normalized sandbox. Prefer `await using` so cleanup runs when the scope exits.
15
+ */
13
16
  declare function createSandbox<TProvider extends SandboxProvider<unknown>>(options: CreateSandboxOptions<TProvider>): Promise<Sandbox<RawOf<TProvider>>>;
17
+ /**
18
+ * Runs a callback with a sandbox and stops it afterward.
19
+ *
20
+ * Prefer `await using` with `createSandbox()` in new code. This helper remains useful for
21
+ * callback-style code and runtimes that do not parse explicit resource management syntax.
22
+ */
14
23
  declare function withSandbox<TProvider extends SandboxProvider<unknown>, TResult>(options: CreateSandboxOptions<TProvider>, callback: (sandbox: Sandbox<RawOf<TProvider>>) => TResult | Promise<TResult>): Promise<TResult>;
15
24
  //#endregion
16
25
  export { createSandbox as n, withSandbox as r, CreateSandboxOptions as t };
17
- //# sourceMappingURL=sandbox-BUYT-1C9.d.mts.map
26
+ //# sourceMappingURL=sandbox-DdEqoXJF.d.mts.map
@@ -1,4 +1,4 @@
1
- import { r as normalizeError, t as SandboxError } from "./errors-Ch9PHKTd.mjs";
1
+ import { r as normalizeError, t as SandboxError } from "./errors-BuF9bYOQ.mjs";
2
2
 
3
3
  //#region src/core/sandbox.ts
4
4
  function validateCwd(cwd) {
@@ -20,6 +20,9 @@ function validatePath(cwd, value) {
20
20
  if (value.startsWith("/")) return value.replace(/\/{2,}/g, "/");
21
21
  return `${cwd}/${value}`.replace(/\/{2,}/g, "/");
22
22
  }
23
+ /**
24
+ * Creates a normalized sandbox. Prefer `await using` so cleanup runs when the scope exits.
25
+ */
23
26
  async function createSandbox(options) {
24
27
  const cwd = validateCwd(options.cwd ?? "/workspace");
25
28
  const env = options.env ?? {};
@@ -69,7 +72,8 @@ async function createSandbox(options) {
69
72
  restore: (snapshot) => call("snapshot.restore", () => runtime.snapshots.restore(snapshot))
70
73
  },
71
74
  run: (command, runOptions = {}) => call("process.run", () => runtime.run(command, normalizeRunOptions(cwd, runOptions))),
72
- stop
75
+ stop,
76
+ [Symbol.asyncDispose]: stop
73
77
  };
74
78
  }
75
79
  function normalizeRunOptions(cwd, options) {
@@ -78,6 +82,12 @@ function normalizeRunOptions(cwd, options) {
78
82
  cwd: options.cwd ? validatePath(cwd, options.cwd) : cwd
79
83
  };
80
84
  }
85
+ /**
86
+ * Runs a callback with a sandbox and stops it afterward.
87
+ *
88
+ * Prefer `await using` with `createSandbox()` in new code. This helper remains useful for
89
+ * callback-style code and runtimes that do not parse explicit resource management syntax.
90
+ */
81
91
  async function withSandbox(options, callback) {
82
92
  const sandbox = await createSandbox(options);
83
93
  try {
@@ -99,4 +109,4 @@ async function withSandbox(options, callback) {
99
109
 
100
110
  //#endregion
101
111
  export { withSandbox as n, createSandbox as t };
102
- //# sourceMappingURL=sandbox-BwyHcB_C.mjs.map
112
+ //# sourceMappingURL=sandbox-DgtY5hvt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-DgtY5hvt.mjs","names":["stopPromise: Promise<void> | undefined"],"sources":["../src/core/sandbox.ts"],"sourcesContent":["import { normalizeError, SandboxError } from \"./errors\";\nimport type { SandboxProvider } from \"./provider\";\nimport type { FileValue, RunOptions, Sandbox } from \"./types\";\n\nexport interface CreateSandboxOptions<TProvider extends SandboxProvider<unknown>> {\n provider: TProvider;\n cwd?: string;\n env?: Readonly<Record<string, string>>;\n timeout?: number;\n signal?: AbortSignal;\n}\n\ntype RawOf<TProvider> = TProvider extends SandboxProvider<infer TRaw> ? TRaw : never;\n\nfunction validateCwd(cwd: string): string {\n if (!cwd.startsWith(\"/\") || cwd.includes(\"\\0\")) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"core\",\n operation: \"create\",\n message: \"cwd must be an absolute path\",\n });\n }\n return cwd.replace(/\\/$/, \"\") || \"/\";\n}\n\nfunction validatePath(cwd: string, value: string): string {\n if (!value || value.includes(\"\\0\") || value.split(\"/\").includes(\"..\")) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"core\",\n operation: \"path\",\n message: `Invalid sandbox path: ${value}`,\n });\n }\n if (value.startsWith(\"/\")) return value.replace(/\\/{2,}/g, \"/\");\n return `${cwd}/${value}`.replace(/\\/{2,}/g, \"/\");\n}\n\n/**\n * Creates a normalized sandbox. Prefer `await using` so cleanup runs when the scope exits.\n */\nexport async function createSandbox<TProvider extends SandboxProvider<unknown>>(\n options: CreateSandboxOptions<TProvider>,\n): Promise<Sandbox<RawOf<TProvider>>> {\n const cwd = validateCwd(options.cwd ?? \"/workspace\");\n const env = options.env ?? {};\n let runtime;\n try {\n runtime = await options.provider.create({\n cwd,\n env,\n timeout: options.timeout,\n signal: options.signal,\n });\n } catch (error) {\n throw normalizeError(options.provider.id, \"sandbox.create\", error);\n }\n let stopPromise: Promise<void> | undefined;\n const stop = async () => {\n stopPromise ??= call(\"sandbox.stop\", () => runtime.stop());\n return stopPromise;\n };\n const call = async <T>(operation: string, fn: () => Promise<T>): Promise<T> => {\n try {\n return await fn();\n } catch (error) {\n throw normalizeError(options.provider.id, operation, error);\n }\n };\n return {\n id: runtime.id,\n provider: options.provider.id,\n cwd,\n capabilities: runtime.capabilities,\n raw: runtime.raw as RawOf<TProvider>,\n files: {\n write: async (path: string, value: FileValue) =>\n call(\"files.write\", () => runtime.files.write(validatePath(cwd, path), value)),\n read: async (path: string) =>\n call(\"files.read\", () => runtime.files.read(validatePath(cwd, path))),\n text: async (path: string) =>\n new TextDecoder().decode(\n await call(\"files.read\", () => runtime.files.read(validatePath(cwd, path))),\n ),\n list: async (path = \".\") =>\n call(\"files.list\", () => runtime.files.list(path === \".\" ? cwd : validatePath(cwd, path))),\n mkdir: async (path: string) =>\n call(\"files.mkdir\", () => runtime.files.mkdir(validatePath(cwd, path))),\n remove: async (path: string) =>\n call(\"files.remove\", () => runtime.files.remove(validatePath(cwd, path))),\n exists: async (path: string) =>\n call(\"files.exists\", () => runtime.files.exists(validatePath(cwd, path))),\n },\n processes: {\n start: (command, runOptions = {}) =>\n call(\"process.start\", () => runtime.start(command, normalizeRunOptions(cwd, runOptions))),\n },\n ports: { expose: (port) => call(\"ports.expose\", () => runtime.expose(port)) },\n snapshots: {\n create: (snapshotOptions) =>\n call(\"snapshot.create\", () => runtime.snapshots.create(snapshotOptions)),\n delete: (snapshot) => call(\"snapshot.delete\", () => runtime.snapshots.delete(snapshot)),\n restore: (snapshot) => call(\"snapshot.restore\", () => runtime.snapshots.restore(snapshot)),\n },\n run: (command, runOptions = {}) =>\n call(\"process.run\", () => runtime.run(command, normalizeRunOptions(cwd, runOptions))),\n stop,\n [Symbol.asyncDispose]: stop,\n };\n}\n\nfunction normalizeRunOptions(cwd: string, options: RunOptions): RunOptions {\n return { ...options, cwd: options.cwd ? validatePath(cwd, options.cwd) : cwd };\n}\n\n/**\n * Runs a callback with a sandbox and stops it afterward.\n *\n * Prefer `await using` with `createSandbox()` in new code. This helper remains useful for\n * callback-style code and runtimes that do not parse explicit resource management syntax.\n */\nexport async function withSandbox<TProvider extends SandboxProvider<unknown>, TResult>(\n options: CreateSandboxOptions<TProvider>,\n callback: (sandbox: Sandbox<RawOf<TProvider>>) => TResult | Promise<TResult>,\n): Promise<TResult> {\n const sandbox = await createSandbox(options);\n try {\n const result = await callback(sandbox);\n await sandbox.stop();\n return result;\n } catch (error) {\n try {\n await sandbox.stop();\n } catch (cleanupError) {\n if (error instanceof Error) {\n Object.defineProperty(error, \"cleanupError\", { value: cleanupError, enumerable: false });\n }\n }\n throw error;\n }\n}\n"],"mappings":";;;AAcA,SAAS,YAAY,KAAqB;AACxC,KAAI,CAAC,IAAI,WAAW,IAAI,IAAI,IAAI,SAAS,KAAK,CAC5C,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU;EACV,WAAW;EACX,SAAS;EACV,CAAC;AAEJ,QAAO,IAAI,QAAQ,OAAO,GAAG,IAAI;;AAGnC,SAAS,aAAa,KAAa,OAAuB;AACxD,KAAI,CAAC,SAAS,MAAM,SAAS,KAAK,IAAI,MAAM,MAAM,IAAI,CAAC,SAAS,KAAK,CACnE,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU;EACV,WAAW;EACX,SAAS,yBAAyB;EACnC,CAAC;AAEJ,KAAI,MAAM,WAAW,IAAI,CAAE,QAAO,MAAM,QAAQ,WAAW,IAAI;AAC/D,QAAO,GAAG,IAAI,GAAG,QAAQ,QAAQ,WAAW,IAAI;;;;;AAMlD,eAAsB,cACpB,SACoC;CACpC,MAAM,MAAM,YAAY,QAAQ,OAAO,aAAa;CACpD,MAAM,MAAM,QAAQ,OAAO,EAAE;CAC7B,IAAI;AACJ,KAAI;AACF,YAAU,MAAM,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,KAAK,uBAAuB,QAAQ,MAAM,SAAS,oBAAoB,KAAK,WAAW,CAAC,CAAC,EAC5F;EACD,OAAO,EAAE,SAAS,SAAS,KAAK,sBAAsB,QAAQ,OAAO,KAAK,CAAC,EAAE;EAC7E,WAAW;GACT,SAAS,oBACP,KAAK,yBAAyB,QAAQ,UAAU,OAAO,gBAAgB,CAAC;GAC1E,SAAS,aAAa,KAAK,yBAAyB,QAAQ,UAAU,OAAO,SAAS,CAAC;GACvF,UAAU,aAAa,KAAK,0BAA0B,QAAQ,UAAU,QAAQ,SAAS,CAAC;GAC3F;EACD,MAAM,SAAS,aAAa,EAAE,KAC5B,KAAK,qBAAqB,QAAQ,IAAI,SAAS,oBAAoB,KAAK,WAAW,CAAC,CAAC;EACvF;GACC,OAAO,eAAe;EACxB;;AAGH,SAAS,oBAAoB,KAAa,SAAiC;AACzE,QAAO;EAAE,GAAG;EAAS,KAAK,QAAQ,MAAM,aAAa,KAAK,QAAQ,IAAI,GAAG;EAAK;;;;;;;;AAShF,eAAsB,YACpB,SACA,UACkB;CAClB,MAAM,UAAU,MAAM,cAAc,QAAQ;AAC5C,KAAI;EACF,MAAM,SAAS,MAAM,SAAS,QAAQ;AACtC,QAAM,QAAQ,MAAM;AACpB,SAAO;UACA,OAAO;AACd,MAAI;AACF,SAAM,QAAQ,MAAM;WACb,cAAc;AACrB,OAAI,iBAAiB,MACnB,QAAO,eAAe,OAAO,gBAAgB;IAAE,OAAO;IAAc,YAAY;IAAO,CAAC;;AAG5F,QAAM"}
@@ -1,6 +1,6 @@
1
- import "../types-BTagTtsp.mjs";
2
- import { o as SandboxProvider } from "../provider-_caCV8kk.mjs";
3
- import { t as CreateSandboxOptions } from "../sandbox-BUYT-1C9.mjs";
1
+ import "../types-Bv6I2U1c.mjs";
2
+ import { o as SandboxProvider } from "../provider-DOBErkBO.mjs";
3
+ import { t as CreateSandboxOptions } from "../sandbox-DdEqoXJF.mjs";
4
4
 
5
5
  //#region src/testing/conformance.d.ts
6
6
  declare const conformanceCases: readonly ["create and stop", "idempotent stop", "text files", "binary files", "directories", "relative paths", "invalid paths", "successful command", "stdout", "stderr", "nonzero exit", "timeout", "background process", "stdin", "ports", "snapshot create", "snapshot delete", "snapshot restore", "cleanup after failure"];
@@ -1,6 +1,6 @@
1
- import "../errors-Ch9PHKTd.mjs";
2
- import { i as supports } from "../capabilities-COKpwoFH.mjs";
3
- import { t as createSandbox } from "../sandbox-BwyHcB_C.mjs";
1
+ import "../errors-BuF9bYOQ.mjs";
2
+ import { i as supports } from "../capabilities-xs9kaHrK.mjs";
3
+ import { t as createSandbox } from "../sandbox-DgtY5hvt.mjs";
4
4
 
5
5
  //#region src/testing/conformance.ts
6
6
  const conformanceCases = [
@@ -1,5 +1,5 @@
1
1
  //#region src/core/types.d.ts
2
- declare const providerNames: readonly ["local", "e2b", "daytona", "vercel", "upstash"];
2
+ declare const providerNames: readonly ["local", "e2b", "daytona", "vercel", "upstash", "box", "railway"];
3
3
  type ProviderName = (typeof providerNames)[number];
4
4
  declare const capabilityNames: readonly ["files.read", "files.write", "files.list", "files.remove", "process.run", "process.stream", "process.background", "process.stdin", "process.cancel", "ports.expose", "ports.authenticatedRequest", "snapshot.create", "snapshot.delete", "snapshot.restore", "sandbox.resume", "filesystem.persistent", "image.custom", "network.policy", "process.pty", "compute.gpu"];
5
5
  type Capability = (typeof capabilityNames)[number];
@@ -93,8 +93,11 @@ interface Sandbox<TRaw = unknown> {
93
93
  readonly ports: SandboxPorts;
94
94
  readonly snapshots: SandboxSnapshots;
95
95
  run(command: CommandInput, options?: RunOptions): Promise<CommandResult>;
96
+ /** Stops the provider runtime. Repeated calls share the same cleanup operation. */
96
97
  stop(): Promise<void>;
98
+ /** Stops the sandbox when an `await using` scope exits. */
99
+ [Symbol.asyncDispose](): Promise<void>;
97
100
  }
98
101
  //#endregion
99
102
  export { SandboxProcesses as _, CommandResult as a, capabilityNames as b, ProcessOutputEvent as c, RunOptions as d, Sandbox as f, SandboxProcess as g, SandboxPorts as h, CommandInput as i, ProcessStatus as l, SandboxFiles as m, CapabilityMap as n, ExposedPort as o, SandboxDirectoryEntry as p, CapabilityMode as r, FileValue as s, Capability as t, ProviderName as u, SandboxSnapshot as v, providerNames as x, SandboxSnapshots as y };
100
- //# sourceMappingURL=types-BTagTtsp.d.mts.map
103
+ //# sourceMappingURL=types-Bv6I2U1c.d.mts.map