@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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## @opencoredev/sandbox-sdk@0.2.0
2
+
3
+ - Add Ascii Box and Railway Sandbox provider adapters, package exports, capabilities, examples,
4
+ live-test entry points, and provider documentation.
5
+ - Normalize HTTP response status codes from provider SDK errors.
6
+
7
+ ## @opencoredev/sandbox-sdk@0.1.1
8
+
9
+ - Add `Symbol.asyncDispose` to `Sandbox` so `await using` provides automatic cleanup.
10
+
1
11
  ## @opencoredev/sandbox-sdk@0.1.0
2
12
 
3
13
  ### Initial release
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img alt="Sandbox SDK with supported provider logos" src="https://raw.githubusercontent.com/opencoredev/sandbox-sdk/main/Background-with-text.png" width="820" />
3
3
  </p>
4
4
 
5
- Run the same TypeScript sandbox code on Local, E2B, Daytona, Vercel Sandbox, or Upstash Box.
5
+ Run the same TypeScript sandbox code on Local, E2B, Daytona, Vercel Sandbox, Upstash Box, Ascii Box, or Railway Sandboxes.
6
6
 
7
7
  ## Install
8
8
 
@@ -12,15 +12,31 @@ bun add @opencoredev/sandbox-sdk
12
12
 
13
13
  Node.js 22 or 24 is supported. Bun 1.3 or newer is also supported.
14
14
 
15
+ ## Quickstart
16
+
17
+ ```ts
18
+ import { createSandbox } from "@opencoredev/sandbox-sdk";
19
+ import { local } from "@opencoredev/sandbox-sdk/local";
20
+
21
+ await using sandbox = await createSandbox({ provider: local() });
22
+ console.log((await sandbox.run("node --version")).stdout);
23
+ ```
24
+
25
+ `await using` stops the sandbox automatically when its scope exits, including when an operation throws.
26
+
27
+ Node.js 24 and Bun run this syntax directly. On Node.js 22, compile TypeScript to ES2022 or use the callback-style `withSandbox()` helper.
28
+
15
29
  ## Providers
16
30
 
17
- | Provider | Runtime | Best for |
18
- | --------------------------------------------------------------- | ----------------------- | -------------------------------------- |
19
- | [Local](https://sandbox-sdk.app/docs/providers/local) | AgentOS VM | Development, CI, and self-hosting |
20
- | [E2B](https://sandbox-sdk.app/docs/providers/e2b) | Hosted Linux sandbox | Coding agents and isolated jobs |
21
- | [Daytona](https://sandbox-sdk.app/docs/providers/daytona) | Cloud workspace | Persistent projects and GPUs |
22
- | [Vercel Sandbox](https://sandbox-sdk.app/docs/providers/vercel) | Hosted Linux sandbox | Vercel workloads and previews |
23
- | [Upstash Box](https://sandbox-sdk.app/docs/providers/upstash) | Durable cloud container | Serverless agents and long-lived state |
31
+ | Provider | Runtime | Best for |
32
+ | --------------------------------------------------------------- | ----------------------- | --------------------------------------- |
33
+ | [Local](https://sandbox-sdk.app/docs/providers/local) | AgentOS VM | Development, CI, and self-hosting |
34
+ | [E2B](https://sandbox-sdk.app/docs/providers/e2b) | Hosted Linux sandbox | Coding agents and isolated jobs |
35
+ | [Daytona](https://sandbox-sdk.app/docs/providers/daytona) | Cloud workspace | Persistent projects and GPUs |
36
+ | [Vercel Sandbox](https://sandbox-sdk.app/docs/providers/vercel) | Hosted Linux sandbox | Coding agents and persistent workspaces |
37
+ | [Upstash Box](https://sandbox-sdk.app/docs/providers/upstash) | Durable cloud container | Serverless agents and long-lived state |
38
+ | [Ascii Box](https://sandbox-sdk.app/docs/providers/box) | Persistent cloud VM | Full VMs and protected app previews |
39
+ | [Railway](https://sandbox-sdk.app/docs/providers/railway) | Ephemeral cloud VM | Durable jobs and private networking |
24
40
 
25
41
  Local is included. Cloud providers use their official SDKs and credentials.
26
42
 
@@ -1,6 +1,7 @@
1
- import { t as SandboxError } from "./errors-Ch9PHKTd.mjs";
2
- import { i as localCapabilities } from "./capabilities-CEowrzRM.mjs";
3
- import { n as portResult, o as withManagedSessions, r as toUint8Array } from "./provider-utils-DilOYLBO.mjs";
1
+ import { t as SandboxError } from "./errors-BuF9bYOQ.mjs";
2
+ import { a as localCapabilities } from "./capabilities-CaSNd6J1.mjs";
3
+ import { t as withManagedSessions } from "./managed-provider-BsZGVQ4I.mjs";
4
+ import { n as portResult, r as toUint8Array } from "./provider-utils-CfB9nvJx.mjs";
4
5
  import { randomUUID } from "node:crypto";
5
6
 
6
7
  //#region src/providers/agentos/index.ts
@@ -386,4 +387,4 @@ function interrupted(operation) {
386
387
 
387
388
  //#endregion
388
389
  export { agentos as t };
389
- //# sourceMappingURL=agentos-BOFA_q-a.mjs.map
390
+ //# sourceMappingURL=agentos-CbrZW7R0.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"agentos-BOFA_q-a.mjs","names":["DEFAULT_PERMISSIONS: Permissions","DEFAULT_LIMITS: NonNullable<AgentOsOptions[\"limits\"]>","vm: AgentOsVm | null","suspendedRoot: RootSnapshotExport | undefined","AgentOs: (typeof import(\"@rivet-dev/agentos-core\"))[\"AgentOs\"]","snapshot: SandboxSnapshot","id","history: ProcessOutputEvent[]","state: ProcessStatus","exitCode: number | undefined","stdout: Uint8Array[]","stderr: Uint8Array[]","timeout: ReturnType<typeof setTimeout> | undefined","interruptions: Promise<never>[]"],"sources":["../src/providers/agentos/index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type {\n AgentOs as AgentOsVm,\n AgentOsOptions,\n Permissions,\n RootSnapshotExport,\n} from \"@rivet-dev/agentos-core\";\nimport { SandboxError } from \"../../core/errors\";\nimport type { SandboxProvider, SandboxRuntime } from \"../../core/provider\";\nimport type {\n CommandInput,\n CommandResult,\n ProcessOutputEvent,\n ProcessStatus,\n RunOptions,\n SandboxDirectoryEntry,\n SandboxProcess,\n SandboxSnapshot,\n} from \"../../core/types\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\nimport { portResult, toUint8Array } from \"../../internal/provider-utils\";\nimport { localCapabilities } from \"../capabilities\";\n\nconst DEFAULT_PERMISSIONS: Permissions = {\n fs: \"allow\",\n childProcess: \"allow\",\n process: \"allow\",\n env: \"allow\",\n network: {\n default: \"deny\",\n rules: [\n { mode: \"allow\", operations: [\"listen\"], patterns: [\"**\"] },\n {\n mode: \"allow\",\n operations: [\"http\"],\n patterns: [\"tcp://127.0.0.1:*\", \"tcp://[::1]:*\", \"tcp://localhost:*\"],\n },\n ],\n },\n binding: \"deny\",\n};\n\nconst DEFAULT_LIMITS: NonNullable<AgentOsOptions[\"limits\"]> = {\n resources: {\n cpuCount: 1,\n maxProcesses: 64,\n maxOpenFds: 256,\n maxPipes: 128,\n maxPtys: 16,\n maxSockets: 128,\n maxConnections: 64,\n maxFilesystemBytes: 512 * 1024 * 1024,\n maxInodeCount: 100_000,\n maxWasmMemoryBytes: 256 * 1024 * 1024,\n },\n http: { maxFetchResponseBytes: 16 * 1024 * 1024 },\n jsRuntime: {\n v8HeapLimitMb: 256,\n wallClockLimitMs: 120_000,\n capturedOutputLimitBytes: 8 * 1024 * 1024,\n stdinBufferLimitBytes: 1024 * 1024,\n },\n};\n\nexport interface AgentOsProviderOptions {\n /**\n * Native agentOS VM options. The provider supplies production-oriented permissions and limits\n * unless these fields are explicitly provided.\n */\n agentOs?: AgentOsOptions;\n}\n\nexport interface AgentOsSandbox {\n /** The currently running native VM. Access throws while the sandbox is suspended or stopped. */\n readonly vm: AgentOsVm;\n suspend(): Promise<void>;\n resume(): Promise<void>;\n}\n\ntype StoredSnapshot = {\n metadata: SandboxSnapshot;\n root: RootSnapshotExport;\n};\n\nexport { agentosCapabilities } from \"../capabilities\";\n\n/**\n * Internal constructor for the AgentOS VM that powers the Local provider.\n *\n * Outbound networking is denied by default. Pass an explicit agentOS permission policy when the\n * guest needs network or host bindings.\n */\nfunction createAgentOsProvider(\n options: AgentOsProviderOptions = {},\n): SandboxProvider<AgentOsSandbox> {\n const provider: SandboxProvider<AgentOsSandbox> = {\n id: \"local\",\n capabilities: localCapabilities,\n async create(createOptions) {\n const id = randomUUID();\n const snapshots = new Map<string, StoredSnapshot>();\n const baseOptions = options.agentOs ?? {};\n let vm: AgentOsVm | null = null;\n let suspendedRoot: RootSnapshotExport | undefined;\n let stopped = false;\n\n const createVm = async (root?: RootSnapshotExport): Promise<AgentOsVm> => {\n let AgentOs: (typeof import(\"@rivet-dev/agentos-core\"))[\"AgentOs\"];\n try {\n ({ AgentOs } = await import(\"@rivet-dev/agentos-core\"));\n } catch (error) {\n throw new SandboxError({\n code: \"unavailable\",\n provider: \"local\",\n operation: \"sandbox.create\",\n message:\n \"The Local provider could not load its @rivet-dev/agentos-core runtime dependency.\",\n cause: error,\n });\n }\n const next = await AgentOs.create({\n ...baseOptions,\n permissions: baseOptions.permissions ?? DEFAULT_PERMISSIONS,\n limits: baseOptions.limits ?? DEFAULT_LIMITS,\n ...(root\n ? {\n rootFilesystem: {\n disableDefaultBaseLayer: true,\n lowers: [root],\n },\n }\n : {}),\n });\n await next.mkdir(createOptions.cwd, { recursive: true });\n return next;\n };\n\n const currentVm = (): AgentOsVm => {\n if (stopped)\n throw new SandboxError({\n code: \"terminated\",\n provider: \"local\",\n operation: \"sandbox\",\n message: \"Sandbox has stopped\",\n });\n if (!vm)\n throw new SandboxError({\n code: \"terminated\",\n provider: \"local\",\n operation: \"sandbox\",\n message: \"Sandbox is suspended; call sandbox.raw.resume() before using it\",\n });\n return vm;\n };\n\n const suspend = async () => {\n if (stopped || !vm) return;\n suspendedRoot = await vm.snapshotRootFilesystem();\n await vm.dispose();\n vm = null;\n };\n\n const resume = async () => {\n if (stopped)\n throw new SandboxError({\n code: \"terminated\",\n provider: \"local\",\n operation: \"sandbox.resume\",\n message: \"A stopped sandbox cannot be resumed\",\n });\n if (vm) return;\n vm = await createVm(suspendedRoot);\n suspendedRoot = undefined;\n };\n\n vm = await createVm();\n const raw: AgentOsSandbox = {\n get vm() {\n return currentVm();\n },\n suspend,\n resume,\n };\n\n const runtime: SandboxRuntime<AgentOsSandbox> = {\n id,\n raw,\n capabilities: localCapabilities,\n files: {\n write: async (path, value) => currentVm().writeFile(path, await toUint8Array(value)),\n read: (path) => currentVm().readFile(path),\n async list(path) {\n const entries = await currentVm().readdirRecursive(path, { maxDepth: 0 });\n return entries.map(\n (entry): SandboxDirectoryEntry => ({\n name: entry.path.slice(entry.path.lastIndexOf(\"/\") + 1),\n path: entry.path,\n type: entry.type,\n size: entry.type === \"file\" ? entry.size : undefined,\n }),\n );\n },\n mkdir: (path) => currentVm().mkdir(path, { recursive: true }),\n async remove(path) {\n if (path === \"/\")\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"local\",\n operation: \"files.remove\",\n message: \"Cannot remove the sandbox root\",\n });\n await currentVm().delete(path, { recursive: true });\n },\n exists: (path) => currentVm().exists(path),\n },\n run: (command, runOptions) =>\n runCommand(currentVm(), command, withEnv(createOptions, runOptions)),\n async start(command, runOptions) {\n return startProcess(currentVm(), command, withEnv(createOptions, runOptions));\n },\n async expose(port) {\n validatePort(port);\n const url = `http://agentos-${id}.internal:${port}`;\n return portResult(port, url, false, false, (path = \"/\", init) => {\n const request = new Request(new URL(path, url), init);\n return currentVm().fetch(port, request);\n });\n },\n snapshots: {\n async create(snapshotOptions) {\n const snapshot: SandboxSnapshot = {\n id: randomUUID(),\n name: snapshotOptions?.name,\n mode: \"filesystem\",\n createdAt: new Date(),\n };\n snapshots.set(snapshot.id, {\n metadata: snapshot,\n root: await currentVm().snapshotRootFilesystem(),\n });\n return snapshot;\n },\n async delete(snapshot) {\n const id = typeof snapshot === \"string\" ? snapshot : snapshot.id;\n if (!snapshots.delete(id)) throw snapshotNotFound(id, \"snapshot.delete\");\n },\n async restore(snapshot) {\n const id = typeof snapshot === \"string\" ? snapshot : snapshot.id;\n const stored = snapshots.get(id);\n if (!stored) throw snapshotNotFound(id, \"snapshot.restore\");\n const previous = currentVm();\n vm = null;\n await previous.dispose();\n try {\n vm = await createVm(stored.root);\n } catch (error) {\n stopped = true;\n throw error;\n }\n },\n },\n async stop() {\n if (stopped) return;\n stopped = true;\n suspendedRoot = undefined;\n snapshots.clear();\n const active = vm;\n vm = null;\n await active?.dispose();\n },\n };\n return runtime;\n },\n };\n\n return withManagedSessions(provider, [], {\n stop: (sandbox) => sandbox.raw.suspend(),\n resume: (sandbox) => sandbox.raw.resume(),\n });\n}\n\n/**\n * @deprecated AgentOS now powers `local()` under the hood. Import `local` from\n * `@opencoredev/sandbox-sdk/local` instead.\n */\nexport function agentos(options: AgentOsProviderOptions = {}): SandboxProvider<AgentOsSandbox> {\n return createAgentOsProvider(options);\n}\n\nfunction withEnv(\n createOptions: { env: Readonly<Record<string, string>> },\n runOptions: RunOptions,\n): RunOptions {\n return { ...runOptions, env: { ...createOptions.env, ...runOptions.env } };\n}\n\nfunction commandParts(command: CommandInput): [string, string[]] {\n return typeof command === \"string\"\n ? [\"sh\", [\"-lc\", command]]\n : [command.command, [...(command.args ?? [])]];\n}\n\nfunction startProcess(vm: AgentOsVm, command: CommandInput, options: RunOptions): SandboxProcess {\n if (options.signal?.aborted) throw interrupted(\"process.start\");\n const [executable, args] = commandParts(command);\n const history: ProcessOutputEvent[] = [];\n const waiting = new Set<() => void>();\n let state: ProcessStatus = \"running\";\n let exitCode: number | undefined;\n const push = (stream: \"stdout\" | \"stderr\", data: Uint8Array) => {\n const output = stream === \"stderr\" ? withoutInternalAgentOsWarnings(data) : data;\n if (output.byteLength === 0) return;\n history.push({ stream, data: new Uint8Array(output), timestamp: new Date() });\n for (const wake of waiting) wake();\n waiting.clear();\n };\n const process = vm.spawn(executable, args, {\n cwd: options.cwd,\n env: options.env ? { ...options.env } : undefined,\n streamStdin: true,\n onStdout: (data) => push(\"stdout\", data),\n onStderr: (data) => push(\"stderr\", data),\n });\n const completed = vm.waitProcess(process.pid).then((code) => {\n exitCode = code;\n state = code === 137 || code === 143 ? \"killed\" : \"exited\";\n for (const wake of waiting) wake();\n waiting.clear();\n return { exitCode: code };\n });\n const abort = () => vm.stopProcess(process.pid);\n options.signal?.addEventListener(\"abort\", abort, { once: true });\n void completed.finally(() => options.signal?.removeEventListener(\"abort\", abort));\n\n return {\n id: String(process.pid),\n async status() {\n return state;\n },\n async *output() {\n let index = 0;\n while (state === \"running\" || index < history.length) {\n while (index < history.length) yield history[index++]!;\n if (state !== \"running\") break;\n await new Promise<void>((resolve) => waiting.add(resolve));\n }\n },\n write: (value) => vm.writeProcessStdin(process.pid, value),\n wait: () => (exitCode === undefined ? completed : Promise.resolve({ exitCode })),\n async kill(signal = \"SIGTERM\") {\n if (state !== \"running\") return;\n if (signal === \"SIGKILL\" || signal === \"KILL\" || signal === \"9\") vm.killProcess(process.pid);\n else vm.stopProcess(process.pid);\n },\n };\n}\n\nfunction withoutInternalAgentOsWarnings(data: Uint8Array): Uint8Array {\n const value = new TextDecoder()\n .decode(data)\n .replaceAll(\"\\u001b[33m WARN\\u001b[0m could not retrieve pid for child process\\n\", \"\");\n return new TextEncoder().encode(value);\n}\n\nasync function runCommand(\n vm: AgentOsVm,\n command: CommandInput,\n options: RunOptions,\n): Promise<CommandResult> {\n const started = performance.now();\n const process = startProcess(vm, command, options);\n const stdout: Uint8Array[] = [];\n const stderr: Uint8Array[] = [];\n const collect = (async () => {\n for await (const event of process.output()) {\n const bytes =\n typeof event.data === \"string\" ? new TextEncoder().encode(event.data) : event.data;\n (event.stream === \"stdout\" ? stdout : stderr).push(bytes);\n }\n })();\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let removeAbort = () => {};\n const interruptions: Promise<never>[] = [];\n\n if (options.timeout && options.timeout > 0) {\n interruptions.push(\n new Promise<never>((_, reject) => {\n timeout = setTimeout(() => {\n void process.kill(\"SIGKILL\");\n reject(\n new SandboxError({\n code: \"timeout\",\n provider: \"local\",\n operation: \"process.run\",\n message: `Command timed out after ${options.timeout}ms`,\n }),\n );\n }, options.timeout);\n }),\n );\n }\n if (options.signal) {\n interruptions.push(\n new Promise<never>((_, reject) => {\n const abort = () => {\n void process.kill(\"SIGKILL\");\n reject(interrupted(\"process.run\"));\n };\n options.signal!.addEventListener(\"abort\", abort, { once: true });\n removeAbort = () => options.signal!.removeEventListener(\"abort\", abort);\n }),\n );\n }\n\n try {\n const result = await Promise.race([process.wait(), ...interruptions]);\n await collect;\n return {\n stdout: decodeChunks(stdout),\n stderr: decodeChunks(stderr),\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: Math.round(performance.now() - started),\n };\n } catch (error) {\n await process.wait().catch(() => {});\n await collect.catch(() => {});\n throw error;\n } finally {\n if (timeout) clearTimeout(timeout);\n removeAbort();\n }\n}\n\nfunction decodeChunks(chunks: Uint8Array[]): string {\n const length = chunks.reduce((total, chunk) => total + chunk.byteLength, 0);\n const output = new Uint8Array(length);\n let offset = 0;\n for (const chunk of chunks) {\n output.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return new TextDecoder().decode(output);\n}\n\nfunction validatePort(port: number): void {\n if (!Number.isInteger(port) || port < 1 || port > 65_535)\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"local\",\n operation: \"ports.expose\",\n message: `Invalid port: ${port}`,\n });\n}\n\nfunction snapshotNotFound(id: string, operation: string): SandboxError {\n return new SandboxError({\n code: \"not_found\",\n provider: \"local\",\n operation,\n message: `Snapshot not found: ${id}`,\n });\n}\n\nfunction interrupted(operation: string): SandboxError {\n return new SandboxError({\n code: \"terminated\",\n provider: \"local\",\n operation,\n message: \"Operation was aborted\",\n });\n}\n"],"mappings":";;;;;;AAuBA,MAAMA,sBAAmC;CACvC,IAAI;CACJ,cAAc;CACd,SAAS;CACT,KAAK;CACL,SAAS;EACP,SAAS;EACT,OAAO,CACL;GAAE,MAAM;GAAS,YAAY,CAAC,SAAS;GAAE,UAAU,CAAC,KAAK;GAAE,EAC3D;GACE,MAAM;GACN,YAAY,CAAC,OAAO;GACpB,UAAU;IAAC;IAAqB;IAAiB;IAAoB;GACtE,CACF;EACF;CACD,SAAS;CACV;AAED,MAAMC,iBAAwD;CAC5D,WAAW;EACT,UAAU;EACV,cAAc;EACd,YAAY;EACZ,UAAU;EAC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CAC3E,MAAM,SAAS,IAAI,WAAW,OAAO;CACrC,IAAI,SAAS;AACb,MAAK,MAAM,SAAS,QAAQ;AAC1B,SAAO,IAAI,OAAO,OAAO;AACzB,YAAU,MAAM;;AAElB,QAAO,IAAI,aAAa,CAAC,OAAO,OAAO;;AAGzC,SAAS,aAAa,MAAoB;AACxC,KAAI,CAAC,OAAO,UAAU,KAAK,IAAI,OAAO,KAAK,OAAO,MAChD,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU;EACV,WAAW;EACX,SAAS,iBAAiB;EAC3B,CAAC;;AAGN,SAAS,iBAAiB,IAAY,WAAiC;AACrE,QAAO,IAAI,aAAa;EACtB,MAAM;EACN,UAAU;EACV;EACA,SAAS,uBAAuB;EACjC,CAAC;;AAGJ,SAAS,YAAY,WAAiC;AACpD,QAAO,IAAI,aAAa;EACtB,MAAM;EACN,UAAU;EACV;EACA,SAAS;EACV,CAAC"}
1
+ {"version":3,"file":"agentos-CbrZW7R0.mjs","names":["DEFAULT_PERMISSIONS: Permissions","DEFAULT_LIMITS: NonNullable<AgentOsOptions[\"limits\"]>","vm: AgentOsVm | null","suspendedRoot: RootSnapshotExport | undefined","AgentOs: (typeof import(\"@rivet-dev/agentos-core\"))[\"AgentOs\"]","snapshot: SandboxSnapshot","id","history: ProcessOutputEvent[]","state: ProcessStatus","exitCode: number | undefined","stdout: Uint8Array[]","stderr: Uint8Array[]","timeout: ReturnType<typeof setTimeout> | undefined","interruptions: Promise<never>[]"],"sources":["../src/providers/agentos/index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type {\n AgentOs as AgentOsVm,\n AgentOsOptions,\n Permissions,\n RootSnapshotExport,\n} from \"@rivet-dev/agentos-core\";\nimport { SandboxError } from \"../../core/errors\";\nimport type { SandboxProvider, SandboxRuntime } from \"../../core/provider\";\nimport type {\n CommandInput,\n CommandResult,\n ProcessOutputEvent,\n ProcessStatus,\n RunOptions,\n SandboxDirectoryEntry,\n SandboxProcess,\n SandboxSnapshot,\n} from \"../../core/types\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\nimport { portResult, toUint8Array } from \"../../internal/provider-utils\";\nimport { localCapabilities } from \"../capabilities\";\n\nconst DEFAULT_PERMISSIONS: Permissions = {\n fs: \"allow\",\n childProcess: \"allow\",\n process: \"allow\",\n env: \"allow\",\n network: {\n default: \"deny\",\n rules: [\n { mode: \"allow\", operations: [\"listen\"], patterns: [\"**\"] },\n {\n mode: \"allow\",\n operations: [\"http\"],\n patterns: [\"tcp://127.0.0.1:*\", \"tcp://[::1]:*\", \"tcp://localhost:*\"],\n },\n ],\n },\n binding: \"deny\",\n};\n\nconst DEFAULT_LIMITS: NonNullable<AgentOsOptions[\"limits\"]> = {\n resources: {\n cpuCount: 1,\n maxProcesses: 64,\n maxOpenFds: 256,\n maxPipes: 128,\n maxPtys: 16,\n maxSockets: 128,\n maxConnections: 64,\n maxFilesystemBytes: 512 * 1024 * 1024,\n maxInodeCount: 100_000,\n maxWasmMemoryBytes: 256 * 1024 * 1024,\n },\n http: { maxFetchResponseBytes: 16 * 1024 * 1024 },\n jsRuntime: {\n v8HeapLimitMb: 256,\n wallClockLimitMs: 120_000,\n capturedOutputLimitBytes: 8 * 1024 * 1024,\n stdinBufferLimitBytes: 1024 * 1024,\n },\n};\n\nexport interface AgentOsProviderOptions {\n /**\n * Native agentOS VM options. The provider supplies production-oriented permissions and limits\n * unless these fields are explicitly provided.\n */\n agentOs?: AgentOsOptions;\n}\n\nexport interface AgentOsSandbox {\n /** The currently running native VM. Access throws while the sandbox is suspended or stopped. */\n readonly vm: AgentOsVm;\n suspend(): Promise<void>;\n resume(): Promise<void>;\n}\n\ntype StoredSnapshot = {\n metadata: SandboxSnapshot;\n root: RootSnapshotExport;\n};\n\nexport { agentosCapabilities } from \"../capabilities\";\n\n/**\n * Internal constructor for the AgentOS VM that powers the Local provider.\n *\n * Outbound networking is denied by default. Pass an explicit agentOS permission policy when the\n * guest needs network or host bindings.\n */\nfunction createAgentOsProvider(\n options: AgentOsProviderOptions = {},\n): SandboxProvider<AgentOsSandbox> {\n const provider: SandboxProvider<AgentOsSandbox> = {\n id: \"local\",\n capabilities: localCapabilities,\n async create(createOptions) {\n const id = randomUUID();\n const snapshots = new Map<string, StoredSnapshot>();\n const baseOptions = options.agentOs ?? {};\n let vm: AgentOsVm | null = null;\n let suspendedRoot: RootSnapshotExport | undefined;\n let stopped = false;\n\n const createVm = async (root?: RootSnapshotExport): Promise<AgentOsVm> => {\n let AgentOs: (typeof import(\"@rivet-dev/agentos-core\"))[\"AgentOs\"];\n try {\n ({ AgentOs } = await import(\"@rivet-dev/agentos-core\"));\n } catch (error) {\n throw new SandboxError({\n code: \"unavailable\",\n provider: \"local\",\n operation: \"sandbox.create\",\n message:\n \"The Local provider could not load its @rivet-dev/agentos-core runtime dependency.\",\n cause: error,\n });\n }\n const next = await AgentOs.create({\n ...baseOptions,\n permissions: baseOptions.permissions ?? DEFAULT_PERMISSIONS,\n limits: baseOptions.limits ?? DEFAULT_LIMITS,\n ...(root\n ? {\n rootFilesystem: {\n disableDefaultBaseLayer: true,\n lowers: [root],\n },\n }\n : {}),\n });\n await next.mkdir(createOptions.cwd, { recursive: true });\n return next;\n };\n\n const currentVm = (): AgentOsVm => {\n if (stopped)\n throw new SandboxError({\n code: \"terminated\",\n provider: \"local\",\n operation: \"sandbox\",\n message: \"Sandbox has stopped\",\n });\n if (!vm)\n throw new SandboxError({\n code: \"terminated\",\n provider: \"local\",\n operation: \"sandbox\",\n message: \"Sandbox is suspended; call sandbox.raw.resume() before using it\",\n });\n return vm;\n };\n\n const suspend = async () => {\n if (stopped || !vm) return;\n suspendedRoot = await vm.snapshotRootFilesystem();\n await vm.dispose();\n vm = null;\n };\n\n const resume = async () => {\n if (stopped)\n throw new SandboxError({\n code: \"terminated\",\n provider: \"local\",\n operation: \"sandbox.resume\",\n message: \"A stopped sandbox cannot be resumed\",\n });\n if (vm) return;\n vm = await createVm(suspendedRoot);\n suspendedRoot = undefined;\n };\n\n vm = await createVm();\n const raw: AgentOsSandbox = {\n get vm() {\n return currentVm();\n },\n suspend,\n resume,\n };\n\n const runtime: SandboxRuntime<AgentOsSandbox> = {\n id,\n raw,\n capabilities: localCapabilities,\n files: {\n write: async (path, value) => currentVm().writeFile(path, await toUint8Array(value)),\n read: (path) => currentVm().readFile(path),\n async list(path) {\n const entries = await currentVm().readdirRecursive(path, { maxDepth: 0 });\n return entries.map(\n (entry): SandboxDirectoryEntry => ({\n name: entry.path.slice(entry.path.lastIndexOf(\"/\") + 1),\n path: entry.path,\n type: entry.type,\n size: entry.type === \"file\" ? entry.size : undefined,\n }),\n );\n },\n mkdir: (path) => currentVm().mkdir(path, { recursive: true }),\n async remove(path) {\n if (path === \"/\")\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"local\",\n operation: \"files.remove\",\n message: \"Cannot remove the sandbox root\",\n });\n await currentVm().delete(path, { recursive: true });\n },\n exists: (path) => currentVm().exists(path),\n },\n run: (command, runOptions) =>\n runCommand(currentVm(), command, withEnv(createOptions, runOptions)),\n async start(command, runOptions) {\n return startProcess(currentVm(), command, withEnv(createOptions, runOptions));\n },\n async expose(port) {\n validatePort(port);\n const url = `http://agentos-${id}.internal:${port}`;\n return portResult(port, url, false, false, (path = \"/\", init) => {\n const request = new Request(new URL(path, url), init);\n return currentVm().fetch(port, request);\n });\n },\n snapshots: {\n async create(snapshotOptions) {\n const snapshot: SandboxSnapshot = {\n id: randomUUID(),\n name: snapshotOptions?.name,\n mode: \"filesystem\",\n createdAt: new Date(),\n };\n snapshots.set(snapshot.id, {\n metadata: snapshot,\n root: await currentVm().snapshotRootFilesystem(),\n });\n return snapshot;\n },\n async delete(snapshot) {\n const id = typeof snapshot === \"string\" ? snapshot : snapshot.id;\n if (!snapshots.delete(id)) throw snapshotNotFound(id, \"snapshot.delete\");\n },\n async restore(snapshot) {\n const id = typeof snapshot === \"string\" ? snapshot : snapshot.id;\n const stored = snapshots.get(id);\n if (!stored) throw snapshotNotFound(id, \"snapshot.restore\");\n const previous = currentVm();\n vm = null;\n await previous.dispose();\n try {\n vm = await createVm(stored.root);\n } catch (error) {\n stopped = true;\n throw error;\n }\n },\n },\n async stop() {\n if (stopped) return;\n stopped = true;\n suspendedRoot = undefined;\n snapshots.clear();\n const active = vm;\n vm = null;\n await active?.dispose();\n },\n };\n return runtime;\n },\n };\n\n return withManagedSessions(provider, [], {\n stop: (sandbox) => sandbox.raw.suspend(),\n resume: (sandbox) => sandbox.raw.resume(),\n });\n}\n\n/**\n * @deprecated AgentOS now powers `local()` under the hood. Import `local` from\n * `@opencoredev/sandbox-sdk/local` instead.\n */\nexport function agentos(options: AgentOsProviderOptions = {}): SandboxProvider<AgentOsSandbox> {\n return createAgentOsProvider(options);\n}\n\nfunction withEnv(\n createOptions: { env: Readonly<Record<string, string>> },\n runOptions: RunOptions,\n): RunOptions {\n return { ...runOptions, env: { ...createOptions.env, ...runOptions.env } };\n}\n\nfunction commandParts(command: CommandInput): [string, string[]] {\n return typeof command === \"string\"\n ? [\"sh\", [\"-lc\", command]]\n : [command.command, [...(command.args ?? [])]];\n}\n\nfunction startProcess(vm: AgentOsVm, command: CommandInput, options: RunOptions): SandboxProcess {\n if (options.signal?.aborted) throw interrupted(\"process.start\");\n const [executable, args] = commandParts(command);\n const history: ProcessOutputEvent[] = [];\n const waiting = new Set<() => void>();\n let state: ProcessStatus = \"running\";\n let exitCode: number | undefined;\n const push = (stream: \"stdout\" | \"stderr\", data: Uint8Array) => {\n const output = stream === \"stderr\" ? withoutInternalAgentOsWarnings(data) : data;\n if (output.byteLength === 0) return;\n history.push({ stream, data: new Uint8Array(output), timestamp: new Date() });\n for (const wake of waiting) wake();\n waiting.clear();\n };\n const process = vm.spawn(executable, args, {\n cwd: options.cwd,\n env: options.env ? { ...options.env } : undefined,\n streamStdin: true,\n onStdout: (data) => push(\"stdout\", data),\n onStderr: (data) => push(\"stderr\", data),\n });\n const completed = vm.waitProcess(process.pid).then((code) => {\n exitCode = code;\n state = code === 137 || code === 143 ? \"killed\" : \"exited\";\n for (const wake of waiting) wake();\n waiting.clear();\n return { exitCode: code };\n });\n const abort = () => vm.stopProcess(process.pid);\n options.signal?.addEventListener(\"abort\", abort, { once: true });\n void completed.finally(() => options.signal?.removeEventListener(\"abort\", abort));\n\n return {\n id: String(process.pid),\n async status() {\n return state;\n },\n async *output() {\n let index = 0;\n while (state === \"running\" || index < history.length) {\n while (index < history.length) yield history[index++]!;\n if (state !== \"running\") break;\n await new Promise<void>((resolve) => waiting.add(resolve));\n }\n },\n write: (value) => vm.writeProcessStdin(process.pid, value),\n wait: () => (exitCode === undefined ? completed : Promise.resolve({ exitCode })),\n async kill(signal = \"SIGTERM\") {\n if (state !== \"running\") return;\n if (signal === \"SIGKILL\" || signal === \"KILL\" || signal === \"9\") vm.killProcess(process.pid);\n else vm.stopProcess(process.pid);\n },\n };\n}\n\nfunction withoutInternalAgentOsWarnings(data: Uint8Array): Uint8Array {\n const value = new TextDecoder()\n .decode(data)\n .replaceAll(\"\\u001b[33m WARN\\u001b[0m could not retrieve pid for child process\\n\", \"\");\n return new TextEncoder().encode(value);\n}\n\nasync function runCommand(\n vm: AgentOsVm,\n command: CommandInput,\n options: RunOptions,\n): Promise<CommandResult> {\n const started = performance.now();\n const process = startProcess(vm, command, options);\n const stdout: Uint8Array[] = [];\n const stderr: Uint8Array[] = [];\n const collect = (async () => {\n for await (const event of process.output()) {\n const bytes =\n typeof event.data === \"string\" ? new TextEncoder().encode(event.data) : event.data;\n (event.stream === \"stdout\" ? stdout : stderr).push(bytes);\n }\n })();\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let removeAbort = () => {};\n const interruptions: Promise<never>[] = [];\n\n if (options.timeout && options.timeout > 0) {\n interruptions.push(\n new Promise<never>((_, reject) => {\n timeout = setTimeout(() => {\n void process.kill(\"SIGKILL\");\n reject(\n new SandboxError({\n code: \"timeout\",\n provider: \"local\",\n operation: \"process.run\",\n message: `Command timed out after ${options.timeout}ms`,\n }),\n );\n }, options.timeout);\n }),\n );\n }\n if (options.signal) {\n interruptions.push(\n new Promise<never>((_, reject) => {\n const abort = () => {\n void process.kill(\"SIGKILL\");\n reject(interrupted(\"process.run\"));\n };\n options.signal!.addEventListener(\"abort\", abort, { once: true });\n removeAbort = () => options.signal!.removeEventListener(\"abort\", abort);\n }),\n );\n }\n\n try {\n const result = await Promise.race([process.wait(), ...interruptions]);\n await collect;\n return {\n stdout: decodeChunks(stdout),\n stderr: decodeChunks(stderr),\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: Math.round(performance.now() - started),\n };\n } catch (error) {\n await process.wait().catch(() => {});\n await collect.catch(() => {});\n throw error;\n } finally {\n if (timeout) clearTimeout(timeout);\n removeAbort();\n }\n}\n\nfunction decodeChunks(chunks: Uint8Array[]): string {\n const length = chunks.reduce((total, chunk) => total + chunk.byteLength, 0);\n const output = new Uint8Array(length);\n let offset = 0;\n for (const chunk of chunks) {\n output.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return new TextDecoder().decode(output);\n}\n\nfunction validatePort(port: number): void {\n if (!Number.isInteger(port) || port < 1 || port > 65_535)\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"local\",\n operation: \"ports.expose\",\n message: `Invalid port: ${port}`,\n });\n}\n\nfunction snapshotNotFound(id: string, operation: string): SandboxError {\n return new SandboxError({\n code: \"not_found\",\n provider: \"local\",\n operation,\n message: `Snapshot not found: ${id}`,\n });\n}\n\nfunction interrupted(operation: string): SandboxError {\n return new SandboxError({\n code: \"terminated\",\n provider: \"local\",\n operation,\n message: \"Operation was aborted\",\n });\n}\n"],"mappings":";;;;;;;AAuBA,MAAMA,sBAAmC;CACvC,IAAI;CACJ,cAAc;CACd,SAAS;CACT,KAAK;CACL,SAAS;EACP,SAAS;EACT,OAAO,CACL;GAAE,MAAM;GAAS,YAAY,CAAC,SAAS;GAAE,UAAU,CAAC,KAAK;GAAE,EAC3D;GACE,MAAM;GACN,YAAY,CAAC,OAAO;GACpB,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;WACE;AACR,MAAI,QAAS,cAAa,QAAQ;AAClC,eAAa;;;AAIjB,SAAS,aAAa,QAA8B;CAClD,MAAM,SAAS,OAAO,QAAQ,OAAO,UAAU,QAAQ,MAAM,YAAY,EAAE;CAC3E,MAAM,SAAS,IAAI,WAAW,OAAO;CACrC,IAAI,SAAS;AACb,MAAK,MAAM,SAAS,QAAQ;AAC1B,SAAO,IAAI,OAAO,OAAO;AACzB,YAAU,MAAM;;AAElB,QAAO,IAAI,aAAa,CAAC,OAAO,OAAO;;AAGzC,SAAS,aAAa,MAAoB;AACxC,KAAI,CAAC,OAAO,UAAU,KAAK,IAAI,OAAO,KAAK,OAAO,MAChD,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU;EACV,WAAW;EACX,SAAS,iBAAiB;EAC3B,CAAC;;AAGN,SAAS,iBAAiB,IAAY,WAAiC;AACrE,QAAO,IAAI,aAAa;EACtB,MAAM;EACN,UAAU;EACV;EACA,SAAS,uBAAuB;EACjC,CAAC;;AAGJ,SAAS,YAAY,WAAiC;AACpD,QAAO,IAAI,aAAa;EACtB,MAAM;EACN,UAAU;EACV;EACA,SAAS;EACV,CAAC"}
@@ -1,5 +1,5 @@
1
- import "../types-BTagTtsp.mjs";
2
- import { o as SandboxProvider } from "../provider-_caCV8kk.mjs";
1
+ import "../types-Bv6I2U1c.mjs";
2
+ import { o as SandboxProvider } from "../provider-DOBErkBO.mjs";
3
3
  import { HarnessV1NetworkPolicy, HarnessV1NetworkSandboxSession, HarnessV1SandboxProvider, HarnessV1SandboxProvider as HarnessV1SandboxProvider$1 } from "@ai-sdk/harness";
4
4
 
5
5
  //#region src/ai/harness.d.ts
@@ -1,5 +1,5 @@
1
- import { t as SandboxError } from "../errors-Ch9PHKTd.mjs";
2
- import { r as toAISandboxSession } from "../ai-DhfwIZdL.mjs";
1
+ import { t as SandboxError } from "../errors-BuF9bYOQ.mjs";
2
+ import { r as toAISandboxSession } from "../ai-DeFa8yPk.mjs";
3
3
 
4
4
  //#region src/ai/harness.ts
5
5
  /** Create an AI SDK Harness sandbox provider backed by any managed sandbox-sdk provider. */
@@ -1,4 +1,4 @@
1
- import { f as Sandbox } from "../types-BTagTtsp.mjs";
1
+ import { f as Sandbox } from "../types-Bv6I2U1c.mjs";
2
2
  import { Experimental_SandboxSession, Tool, ToolSet } from "ai";
3
3
 
4
4
  //#region src/ai/index.d.ts
package/dist/ai/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import "../errors-Ch9PHKTd.mjs";
2
- import { n as createSandboxTools, r as toAISandboxSession, t as createSandboxToolApproval } from "../ai-DhfwIZdL.mjs";
1
+ import "../errors-BuF9bYOQ.mjs";
2
+ import { n as createSandboxTools, r as toAISandboxSession, t as createSandboxToolApproval } from "../ai-DeFa8yPk.mjs";
3
3
 
4
4
  export { createSandboxToolApproval, createSandboxTools, toAISandboxSession };
@@ -1,4 +1,4 @@
1
- import { n as isSandboxError, r as normalizeError, t as SandboxError } from "./errors-Ch9PHKTd.mjs";
1
+ import { n as isSandboxError, r as normalizeError, t as SandboxError } from "./errors-BuF9bYOQ.mjs";
2
2
  import { jsonSchema, tool } from "ai";
3
3
 
4
4
  //#region src/ai/index.ts
@@ -240,4 +240,4 @@ function throwIfAborted(signal) {
240
240
 
241
241
  //#endregion
242
242
  export { createSandboxTools as n, toAISandboxSession as r, createSandboxToolApproval as t };
243
- //# sourceMappingURL=ai-DhfwIZdL.mjs.map
243
+ //# sourceMappingURL=ai-DeFa8yPk.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai-DhfwIZdL.mjs","names":["stdoutController!: ReadableStreamDefaultController<Uint8Array>","stderrController!: ReadableStreamDefaultController<Uint8Array>"],"sources":["../src/ai/index.ts"],"sourcesContent":["import { jsonSchema, tool } from \"ai\";\nimport type { Experimental_SandboxProcess, Experimental_SandboxSession, Tool, ToolSet } from \"ai\";\nimport { isSandboxError, normalizeError, SandboxError } from \"../core/errors\";\nimport type { Sandbox, SandboxProcess } from \"../core/types\";\n\nexport interface AISandboxSessionOptions {\n description?: string;\n}\n\nexport type SandboxToolApproval = \"mutations\" | \"always\" | \"never\";\n\nexport type SandboxToolApprovalConfiguration = Readonly<{\n bash: \"user-approval\" | \"not-applicable\";\n read_file: \"user-approval\" | \"not-applicable\";\n write_file: \"user-approval\" | \"not-applicable\";\n}>;\n\n/**\n * Adapt a sandbox-sdk sandbox to AI SDK 7's experimental sandbox contract.\n * The caller continues to own the original sandbox and must stop it.\n */\nexport function toAISandboxSession(\n sandbox: Sandbox,\n options: AISandboxSessionOptions = {},\n): Experimental_SandboxSession {\n const read = async (path: string, abortSignal?: AbortSignal): Promise<Uint8Array | null> => {\n throwIfAborted(abortSignal);\n try {\n const bytes = await sandbox.files.read(path);\n throwIfAborted(abortSignal);\n return bytes;\n } catch (error) {\n if (isSandboxError(error) && error.code === \"not_found\") return null;\n throw normalizeError(sandbox.provider, \"ai.readFile\", error);\n }\n };\n\n return {\n description:\n options.description ??\n `${sandbox.provider} sandbox ${sandbox.id}; default working directory: ${sandbox.cwd}`,\n async readFile({ path, abortSignal }) {\n const bytes = await read(path, abortSignal);\n return bytes === null ? null : bytesToStream(bytes);\n },\n readBinaryFile: ({ path, abortSignal }) => read(path, abortSignal),\n async readTextFile({ path, encoding = \"utf-8\", startLine, endLine, abortSignal }) {\n const bytes = await read(path, abortSignal);\n if (bytes === null) return null;\n const content = decode(bytes, encoding);\n if (startLine === undefined && endLine === undefined) return content;\n validateLineRange(startLine, endLine);\n return content\n .split(\"\\n\")\n .slice((startLine ?? 1) - 1, endLine)\n .join(\"\\n\");\n },\n async writeFile({ path, content, abortSignal }) {\n throwIfAborted(abortSignal);\n await sandbox.files.write(path, abortableStream(content, abortSignal));\n throwIfAborted(abortSignal);\n },\n async writeBinaryFile({ path, content, abortSignal }) {\n throwIfAborted(abortSignal);\n await sandbox.files.write(path, content);\n throwIfAborted(abortSignal);\n },\n async writeTextFile({ path, content, encoding = \"utf-8\", abortSignal }) {\n throwIfAborted(abortSignal);\n await sandbox.files.write(path, encode(content, encoding));\n throwIfAborted(abortSignal);\n },\n async run({ command, workingDirectory, env, abortSignal }) {\n const result = await sandbox.run(command, {\n cwd: workingDirectory,\n env,\n signal: abortSignal,\n });\n return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr };\n },\n async spawn({ command, workingDirectory, env, abortSignal }) {\n const process = await sandbox.processes.start(command, {\n cwd: workingDirectory,\n env,\n signal: abortSignal,\n });\n return toAIProcess(process, abortSignal);\n },\n };\n}\n\ntype BashInput = { command: string; workingDirectory?: string; env?: Record<string, string> };\ntype ReadFileInput = { path: string; encoding?: string; startLine?: number; endLine?: number };\ntype WriteFileInput = { path: string; content: string; encoding?: string };\n\nexport type SandboxTools = ToolSet & {\n bash: Tool<BashInput, { exitCode: number; stdout: string; stderr: string }>;\n read_file: Tool<ReadFileInput, { content: string | null }>;\n write_file: Tool<WriteFileInput, { written: true }>;\n};\n\n/** Ready-made AI SDK tools that execute only through `experimental_sandbox`. */\nexport function createSandboxTools(): SandboxTools {\n return {\n bash: tool({\n description: \"Run a shell command in the sandbox.\",\n inputSchema: jsonSchema<BashInput>({\n type: \"object\",\n properties: {\n command: { type: \"string\" },\n workingDirectory: { type: \"string\" },\n env: { type: \"object\", additionalProperties: { type: \"string\" } },\n },\n required: [\"command\"],\n additionalProperties: false,\n }),\n async execute(input, context) {\n const sandbox = requireSandbox(context.experimental_sandbox);\n return sandbox.run({\n command: input.command,\n workingDirectory: input.workingDirectory,\n env: input.env,\n abortSignal: context.abortSignal,\n });\n },\n }),\n read_file: tool({\n description: \"Read a text file from the sandbox. Missing files return null.\",\n inputSchema: jsonSchema<ReadFileInput>({\n type: \"object\",\n properties: {\n path: { type: \"string\" },\n encoding: { type: \"string\" },\n startLine: { type: \"integer\", minimum: 1 },\n endLine: { type: \"integer\", minimum: 1 },\n },\n required: [\"path\"],\n additionalProperties: false,\n }),\n async execute(input, context) {\n const sandbox = requireSandbox(context.experimental_sandbox);\n return {\n content: await sandbox.readTextFile({\n ...input,\n abortSignal: context.abortSignal,\n }),\n };\n },\n }),\n write_file: tool({\n description: \"Write a text file in the sandbox, creating parent directories.\",\n inputSchema: jsonSchema<WriteFileInput>({\n type: \"object\",\n properties: {\n path: { type: \"string\" },\n content: { type: \"string\" },\n encoding: { type: \"string\" },\n },\n required: [\"path\", \"content\"],\n additionalProperties: false,\n }),\n async execute(input, context) {\n const sandbox = requireSandbox(context.experimental_sandbox);\n await sandbox.writeTextFile({ ...input, abortSignal: context.abortSignal });\n return { written: true as const };\n },\n }),\n };\n}\n\n/** Create the AI SDK 7 `toolApproval` policy for the ready-made sandbox tools. */\nexport function createSandboxToolApproval(\n approval: SandboxToolApproval = \"mutations\",\n): SandboxToolApprovalConfiguration {\n const status = (mutation: boolean) =>\n approval === \"always\" || (approval === \"mutations\" && mutation)\n ? (\"user-approval\" as const)\n : (\"not-applicable\" as const);\n\n return {\n bash: status(true),\n read_file: status(false),\n write_file: status(true),\n };\n}\n\nfunction requireSandbox(\n value: Experimental_SandboxSession | undefined,\n): Experimental_SandboxSession {\n if (!value) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"ai\",\n operation: \"tool.execute\",\n message: \"experimental_sandbox is required to execute sandbox tools\",\n });\n }\n return value;\n}\n\nfunction toAIProcess(\n process: SandboxProcess,\n abortSignal?: AbortSignal,\n): Experimental_SandboxProcess {\n let stdoutController!: ReadableStreamDefaultController<Uint8Array>;\n let stderrController!: ReadableStreamDefaultController<Uint8Array>;\n const stdout = new ReadableStream<Uint8Array>({\n start: (controller) => (stdoutController = controller),\n });\n const stderr = new ReadableStream<Uint8Array>({\n start: (controller) => (stderrController = controller),\n });\n const pump = (async () => {\n try {\n for await (const event of process.output()) {\n const bytes =\n typeof event.data === \"string\" ? new TextEncoder().encode(event.data) : event.data;\n (event.stream === \"stdout\" ? stdoutController : stderrController).enqueue(bytes);\n }\n stdoutController.close();\n stderrController.close();\n } catch (error) {\n stdoutController.error(error);\n stderrController.error(error);\n }\n })();\n const abort = () => void process.kill();\n abortSignal?.addEventListener(\"abort\", abort, { once: true });\n return {\n pid: Number.isFinite(Number(process.id)) ? Number(process.id) : undefined,\n stdout,\n stderr,\n async wait() {\n try {\n const result = await process.wait();\n await pump;\n if (abortSignal?.aborted) throw abortSignal.reason;\n return result;\n } finally {\n abortSignal?.removeEventListener(\"abort\", abort);\n }\n },\n kill: () => process.kill(),\n };\n}\n\nfunction bytesToStream(bytes: Uint8Array): ReadableStream<Uint8Array> {\n return new ReadableStream({\n start(controller) {\n controller.enqueue(bytes);\n controller.close();\n },\n });\n}\n\nfunction abortableStream(\n stream: ReadableStream<Uint8Array>,\n signal?: AbortSignal,\n): ReadableStream<Uint8Array> {\n if (!signal) return stream;\n return stream.pipeThrough(\n new TransformStream({\n transform(chunk, controller) {\n throwIfAborted(signal);\n controller.enqueue(chunk);\n },\n }),\n { signal },\n );\n}\n\nfunction validateLineRange(startLine?: number, endLine?: number): void {\n if (\n (startLine !== undefined && (!Number.isInteger(startLine) || startLine < 1)) ||\n (endLine !== undefined && (!Number.isInteger(endLine) || endLine < 1)) ||\n (startLine !== undefined && endLine !== undefined && endLine < startLine)\n ) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"ai\",\n operation: \"readTextFile\",\n message: \"Line ranges must be positive, 1-based, inclusive, and ordered\",\n });\n }\n}\n\nfunction decode(bytes: Uint8Array, encoding: string): string {\n try {\n return encoding.toLowerCase() === \"utf-8\" || encoding.toLowerCase() === \"utf8\"\n ? new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes)\n : Buffer.from(bytes).toString(encoding as BufferEncoding);\n } catch (error) {\n throw normalizeError(\"ai\", \"files.decode\", error, \"invalid_input\");\n }\n}\n\nfunction encode(value: string, encoding: string): Uint8Array {\n try {\n return encoding.toLowerCase() === \"utf-8\" || encoding.toLowerCase() === \"utf8\"\n ? new TextEncoder().encode(value)\n : new Uint8Array(Buffer.from(value, encoding as BufferEncoding));\n } catch (error) {\n throw normalizeError(\"ai\", \"files.encode\", error, \"invalid_input\");\n }\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted)\n throw signal.reason ?? new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"],"mappings":";;;;;;;;AAqBA,SAAgB,mBACd,SACA,UAAmC,EAAE,EACR;CAC7B,MAAM,OAAO,OAAO,MAAc,gBAA0D;AAC1F,iBAAe,YAAY;AAC3B,MAAI;GACF,MAAM,QAAQ,MAAM,QAAQ,MAAM,KAAK,KAAK;AAC5C,kBAAe,YAAY;AAC3B,UAAO;WACA,OAAO;AACd,OAAI,eAAe,MAAM,IAAI,MAAM,SAAS,YAAa,QAAO;AAChE,SAAM,eAAe,QAAQ,UAAU,eAAe,MAAM;;;AAIhE,QAAO;EACL,aACE,QAAQ,eACR,GAAG,QAAQ,SAAS,WAAW,QAAQ,GAAG,+BAA+B,QAAQ;EACnF,MAAM,SAAS,EAAE,MAAM,eAAe;GACpC,MAAM,QAAQ,MAAM,KAAK,MAAM,YAAY;AAC3C,UAAO,UAAU,OAAO,OAAO,cAAc,MAAM;;EAErD,iBAAiB,EAAE,MAAM,kBAAkB,KAAK,MAAM,YAAY;EAClE,MAAM,aAAa,EAAE,MAAM,WAAW,SAAS,WAAW,SAAS,eAAe;GAChF,MAAM,QAAQ,MAAM,KAAK,MAAM,YAAY;AAC3C,OAAI,UAAU,KAAM,QAAO;GAC3B,MAAM,UAAU,OAAO,OAAO,SAAS;AACvC,OAAI,cAAc,UAAa,YAAY,OAAW,QAAO;AAC7D,qBAAkB,WAAW,QAAQ;AACrC,UAAO,QACJ,MAAM,KAAK,CACX,OAAO,aAAa,KAAK,GAAG,QAAQ,CACpC,KAAK,KAAK;;EAEf,MAAM,UAAU,EAAE,MAAM,SAAS,eAAe;AAC9C,kBAAe,YAAY;AAC3B,SAAM,QAAQ,MAAM,MAAM,MAAM,gBAAgB,SAAS,YAAY,CAAC;AACtE,kBAAe,YAAY;;EAE7B,MAAM,gBAAgB,EAAE,MAAM,SAAS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E/D,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU;EACV,WAAW;EACX,SAAS;EACV,CAAC;;AAIN,SAAS,OAAO,OAAmB,UAA0B;AAC3D,KAAI;AACF,SAAO,SAAS,aAAa,KAAK,WAAW,SAAS,aAAa,KAAK,SACpE,IAAI,YAAY,SAAS,EAAE,OAAO,MAAM,CAAC,CAAC,OAAO,MAAM,GACvD,OAAO,KAAK,MAAM,CAAC,SAAS,SAA2B;UACpD,OAAO;AACd,QAAM,eAAe,MAAM,gBAAgB,OAAO,gBAAgB;;;AAItE,SAAS,OAAO,OAAe,UAA8B;AAC3D,KAAI;AACF,SAAO,SAAS,aAAa,KAAK,WAAW,SAAS,aAAa,KAAK,SACpE,IAAI,aAAa,CAAC,OAAO,MAAM,GAC/B,IAAI,WAAW,OAAO,KAAK,OAAO,SAA2B,CAAC;UAC3D,OAAO;AACd,QAAM,eAAe,MAAM,gBAAgB,OAAO,gBAAgB;;;AAItE,SAAS,eAAe,QAA4B;AAClD,KAAI,QAAQ,QACV,OAAM,OAAO,UAAU,IAAI,aAAa,6BAA6B,aAAa"}
1
+ {"version":3,"file":"ai-DeFa8yPk.mjs","names":["stdoutController!: ReadableStreamDefaultController<Uint8Array>","stderrController!: ReadableStreamDefaultController<Uint8Array>"],"sources":["../src/ai/index.ts"],"sourcesContent":["import { jsonSchema, tool } from \"ai\";\nimport type { Experimental_SandboxProcess, Experimental_SandboxSession, Tool, ToolSet } from \"ai\";\nimport { isSandboxError, normalizeError, SandboxError } from \"../core/errors\";\nimport type { Sandbox, SandboxProcess } from \"../core/types\";\n\nexport interface AISandboxSessionOptions {\n description?: string;\n}\n\nexport type SandboxToolApproval = \"mutations\" | \"always\" | \"never\";\n\nexport type SandboxToolApprovalConfiguration = Readonly<{\n bash: \"user-approval\" | \"not-applicable\";\n read_file: \"user-approval\" | \"not-applicable\";\n write_file: \"user-approval\" | \"not-applicable\";\n}>;\n\n/**\n * Adapt a sandbox-sdk sandbox to AI SDK 7's experimental sandbox contract.\n * The caller continues to own the original sandbox and must stop it.\n */\nexport function toAISandboxSession(\n sandbox: Sandbox,\n options: AISandboxSessionOptions = {},\n): Experimental_SandboxSession {\n const read = async (path: string, abortSignal?: AbortSignal): Promise<Uint8Array | null> => {\n throwIfAborted(abortSignal);\n try {\n const bytes = await sandbox.files.read(path);\n throwIfAborted(abortSignal);\n return bytes;\n } catch (error) {\n if (isSandboxError(error) && error.code === \"not_found\") return null;\n throw normalizeError(sandbox.provider, \"ai.readFile\", error);\n }\n };\n\n return {\n description:\n options.description ??\n `${sandbox.provider} sandbox ${sandbox.id}; default working directory: ${sandbox.cwd}`,\n async readFile({ path, abortSignal }) {\n const bytes = await read(path, abortSignal);\n return bytes === null ? null : bytesToStream(bytes);\n },\n readBinaryFile: ({ path, abortSignal }) => read(path, abortSignal),\n async readTextFile({ path, encoding = \"utf-8\", startLine, endLine, abortSignal }) {\n const bytes = await read(path, abortSignal);\n if (bytes === null) return null;\n const content = decode(bytes, encoding);\n if (startLine === undefined && endLine === undefined) return content;\n validateLineRange(startLine, endLine);\n return content\n .split(\"\\n\")\n .slice((startLine ?? 1) - 1, endLine)\n .join(\"\\n\");\n },\n async writeFile({ path, content, abortSignal }) {\n throwIfAborted(abortSignal);\n await sandbox.files.write(path, abortableStream(content, abortSignal));\n throwIfAborted(abortSignal);\n },\n async writeBinaryFile({ path, content, abortSignal }) {\n throwIfAborted(abortSignal);\n await sandbox.files.write(path, content);\n throwIfAborted(abortSignal);\n },\n async writeTextFile({ path, content, encoding = \"utf-8\", abortSignal }) {\n throwIfAborted(abortSignal);\n await sandbox.files.write(path, encode(content, encoding));\n throwIfAborted(abortSignal);\n },\n async run({ command, workingDirectory, env, abortSignal }) {\n const result = await sandbox.run(command, {\n cwd: workingDirectory,\n env,\n signal: abortSignal,\n });\n return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr };\n },\n async spawn({ command, workingDirectory, env, abortSignal }) {\n const process = await sandbox.processes.start(command, {\n cwd: workingDirectory,\n env,\n signal: abortSignal,\n });\n return toAIProcess(process, abortSignal);\n },\n };\n}\n\ntype BashInput = { command: string; workingDirectory?: string; env?: Record<string, string> };\ntype ReadFileInput = { path: string; encoding?: string; startLine?: number; endLine?: number };\ntype WriteFileInput = { path: string; content: string; encoding?: string };\n\nexport type SandboxTools = ToolSet & {\n bash: Tool<BashInput, { exitCode: number; stdout: string; stderr: string }>;\n read_file: Tool<ReadFileInput, { content: string | null }>;\n write_file: Tool<WriteFileInput, { written: true }>;\n};\n\n/** Ready-made AI SDK tools that execute only through `experimental_sandbox`. */\nexport function createSandboxTools(): SandboxTools {\n return {\n bash: tool({\n description: \"Run a shell command in the sandbox.\",\n inputSchema: jsonSchema<BashInput>({\n type: \"object\",\n properties: {\n command: { type: \"string\" },\n workingDirectory: { type: \"string\" },\n env: { type: \"object\", additionalProperties: { type: \"string\" } },\n },\n required: [\"command\"],\n additionalProperties: false,\n }),\n async execute(input, context) {\n const sandbox = requireSandbox(context.experimental_sandbox);\n return sandbox.run({\n command: input.command,\n workingDirectory: input.workingDirectory,\n env: input.env,\n abortSignal: context.abortSignal,\n });\n },\n }),\n read_file: tool({\n description: \"Read a text file from the sandbox. Missing files return null.\",\n inputSchema: jsonSchema<ReadFileInput>({\n type: \"object\",\n properties: {\n path: { type: \"string\" },\n encoding: { type: \"string\" },\n startLine: { type: \"integer\", minimum: 1 },\n endLine: { type: \"integer\", minimum: 1 },\n },\n required: [\"path\"],\n additionalProperties: false,\n }),\n async execute(input, context) {\n const sandbox = requireSandbox(context.experimental_sandbox);\n return {\n content: await sandbox.readTextFile({\n ...input,\n abortSignal: context.abortSignal,\n }),\n };\n },\n }),\n write_file: tool({\n description: \"Write a text file in the sandbox, creating parent directories.\",\n inputSchema: jsonSchema<WriteFileInput>({\n type: \"object\",\n properties: {\n path: { type: \"string\" },\n content: { type: \"string\" },\n encoding: { type: \"string\" },\n },\n required: [\"path\", \"content\"],\n additionalProperties: false,\n }),\n async execute(input, context) {\n const sandbox = requireSandbox(context.experimental_sandbox);\n await sandbox.writeTextFile({ ...input, abortSignal: context.abortSignal });\n return { written: true as const };\n },\n }),\n };\n}\n\n/** Create the AI SDK 7 `toolApproval` policy for the ready-made sandbox tools. */\nexport function createSandboxToolApproval(\n approval: SandboxToolApproval = \"mutations\",\n): SandboxToolApprovalConfiguration {\n const status = (mutation: boolean) =>\n approval === \"always\" || (approval === \"mutations\" && mutation)\n ? (\"user-approval\" as const)\n : (\"not-applicable\" as const);\n\n return {\n bash: status(true),\n read_file: status(false),\n write_file: status(true),\n };\n}\n\nfunction requireSandbox(\n value: Experimental_SandboxSession | undefined,\n): Experimental_SandboxSession {\n if (!value) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"ai\",\n operation: \"tool.execute\",\n message: \"experimental_sandbox is required to execute sandbox tools\",\n });\n }\n return value;\n}\n\nfunction toAIProcess(\n process: SandboxProcess,\n abortSignal?: AbortSignal,\n): Experimental_SandboxProcess {\n let stdoutController!: ReadableStreamDefaultController<Uint8Array>;\n let stderrController!: ReadableStreamDefaultController<Uint8Array>;\n const stdout = new ReadableStream<Uint8Array>({\n start: (controller) => (stdoutController = controller),\n });\n const stderr = new ReadableStream<Uint8Array>({\n start: (controller) => (stderrController = controller),\n });\n const pump = (async () => {\n try {\n for await (const event of process.output()) {\n const bytes =\n typeof event.data === \"string\" ? new TextEncoder().encode(event.data) : event.data;\n (event.stream === \"stdout\" ? stdoutController : stderrController).enqueue(bytes);\n }\n stdoutController.close();\n stderrController.close();\n } catch (error) {\n stdoutController.error(error);\n stderrController.error(error);\n }\n })();\n const abort = () => void process.kill();\n abortSignal?.addEventListener(\"abort\", abort, { once: true });\n return {\n pid: Number.isFinite(Number(process.id)) ? Number(process.id) : undefined,\n stdout,\n stderr,\n async wait() {\n try {\n const result = await process.wait();\n await pump;\n if (abortSignal?.aborted) throw abortSignal.reason;\n return result;\n } finally {\n abortSignal?.removeEventListener(\"abort\", abort);\n }\n },\n kill: () => process.kill(),\n };\n}\n\nfunction bytesToStream(bytes: Uint8Array): ReadableStream<Uint8Array> {\n return new ReadableStream({\n start(controller) {\n controller.enqueue(bytes);\n controller.close();\n },\n });\n}\n\nfunction abortableStream(\n stream: ReadableStream<Uint8Array>,\n signal?: AbortSignal,\n): ReadableStream<Uint8Array> {\n if (!signal) return stream;\n return stream.pipeThrough(\n new TransformStream({\n transform(chunk, controller) {\n throwIfAborted(signal);\n controller.enqueue(chunk);\n },\n }),\n { signal },\n );\n}\n\nfunction validateLineRange(startLine?: number, endLine?: number): void {\n if (\n (startLine !== undefined && (!Number.isInteger(startLine) || startLine < 1)) ||\n (endLine !== undefined && (!Number.isInteger(endLine) || endLine < 1)) ||\n (startLine !== undefined && endLine !== undefined && endLine < startLine)\n ) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"ai\",\n operation: \"readTextFile\",\n message: \"Line ranges must be positive, 1-based, inclusive, and ordered\",\n });\n }\n}\n\nfunction decode(bytes: Uint8Array, encoding: string): string {\n try {\n return encoding.toLowerCase() === \"utf-8\" || encoding.toLowerCase() === \"utf8\"\n ? new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes)\n : Buffer.from(bytes).toString(encoding as BufferEncoding);\n } catch (error) {\n throw normalizeError(\"ai\", \"files.decode\", error, \"invalid_input\");\n }\n}\n\nfunction encode(value: string, encoding: string): Uint8Array {\n try {\n return encoding.toLowerCase() === \"utf-8\" || encoding.toLowerCase() === \"utf8\"\n ? new TextEncoder().encode(value)\n : new Uint8Array(Buffer.from(value, encoding as BufferEncoding));\n } catch (error) {\n throw normalizeError(\"ai\", \"files.encode\", error, \"invalid_input\");\n }\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted)\n throw signal.reason ?? new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"],"mappings":";;;;;;;;AAqBA,SAAgB,mBACd,SACA,UAAmC,EAAE,EACR;CAC7B,MAAM,OAAO,OAAO,MAAc,gBAA0D;AAC1F,iBAAe,YAAY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GACvD,OAAO,KAAK,MAAM,CAAC,SAAS,SAA2B;UACpD,OAAO;AACd,QAAM,eAAe,MAAM,gBAAgB,OAAO,gBAAgB;;;AAItE,SAAS,OAAO,OAAe,UAA8B;AAC3D,KAAI;AACF,SAAO,SAAS,aAAa,KAAK,WAAW,SAAS,aAAa,KAAK,SACpE,IAAI,aAAa,CAAC,OAAO,MAAM,GAC/B,IAAI,WAAW,OAAO,KAAK,OAAO,SAA2B,CAAC;UAC3D,OAAO;AACd,QAAM,eAAe,MAAM,gBAAgB,OAAO,gBAAgB;;;AAItE,SAAS,eAAe,QAA4B;AAClD,KAAI,QAAQ,QACV,OAAM,OAAO,UAAU,IAAI,aAAa,6BAA6B,aAAa"}
@@ -1,4 +1,4 @@
1
- import { r as CapabilityMode } from "./types-BTagTtsp.mjs";
1
+ import { r as CapabilityMode } from "./types-Bv6I2U1c.mjs";
2
2
 
3
3
  //#region src/providers/capabilities.d.ts
4
4
  declare const localCapabilities: Readonly<Record<"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", false | CapabilityMode>>;
@@ -8,6 +8,8 @@ declare const e2bCapabilities: Readonly<Record<"files.read" | "files.write" | "f
8
8
  declare const daytonaCapabilities: Readonly<Record<"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", false | CapabilityMode>>;
9
9
  declare const vercelCapabilities: Readonly<Record<"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", false | CapabilityMode>>;
10
10
  declare const upstashCapabilities: Readonly<Record<"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", false | CapabilityMode>>;
11
+ declare const boxCapabilities: Readonly<Record<"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", false | CapabilityMode>>;
12
+ declare const railwayCapabilities: Readonly<Record<"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", false | CapabilityMode>>;
11
13
  //#endregion
12
- export { upstashCapabilities as a, localCapabilities as i, daytonaCapabilities as n, vercelCapabilities as o, e2bCapabilities as r, agentosCapabilities as t };
13
- //# sourceMappingURL=capabilities-CMnszzpt.d.mts.map
14
+ export { localCapabilities as a, vercelCapabilities as c, e2bCapabilities as i, boxCapabilities as n, railwayCapabilities as o, daytonaCapabilities as r, upstashCapabilities as s, agentosCapabilities as t };
15
+ //# sourceMappingURL=capabilities-BWvOVFbH.d.mts.map
@@ -1,4 +1,4 @@
1
- import { n as defineCapabilities } from "./capabilities-COKpwoFH.mjs";
1
+ import { n as defineCapabilities } from "./capabilities-xs9kaHrK.mjs";
2
2
 
3
3
  //#region src/providers/capabilities.ts
4
4
  const localCapabilities = defineCapabilities({
@@ -93,7 +93,33 @@ const upstashCapabilities = defineCapabilities({
93
93
  "image.custom": "native",
94
94
  "network.policy": "native"
95
95
  });
96
+ const boxCapabilities = defineCapabilities({
97
+ "files.read": "full",
98
+ "files.write": "full",
99
+ "files.list": "full",
100
+ "files.remove": "full",
101
+ "process.run": "separate-streams",
102
+ "ports.expose": "public",
103
+ "ports.authenticatedRequest": "authenticated",
104
+ "sandbox.resume": "persistent",
105
+ "filesystem.persistent": "persistent"
106
+ });
107
+ const railwayCapabilities = defineCapabilities({
108
+ "files.read": "full",
109
+ "files.write": "full",
110
+ "files.list": "full",
111
+ "files.remove": "full",
112
+ "process.run": "separate-streams",
113
+ "process.stream": "separate-streams",
114
+ "process.background": "full",
115
+ "process.cancel": "full",
116
+ "snapshot.create": "filesystem",
117
+ "snapshot.delete": "filesystem",
118
+ "filesystem.persistent": "persistent",
119
+ "image.custom": "template",
120
+ "network.policy": "native"
121
+ });
96
122
 
97
123
  //#endregion
98
- export { upstashCapabilities as a, localCapabilities as i, daytonaCapabilities as n, vercelCapabilities as o, e2bCapabilities as r, agentosCapabilities as t };
99
- //# sourceMappingURL=capabilities-CEowrzRM.mjs.map
124
+ export { localCapabilities as a, vercelCapabilities as c, e2bCapabilities as i, boxCapabilities as n, railwayCapabilities as o, daytonaCapabilities as r, upstashCapabilities as s, agentosCapabilities as t };
125
+ //# sourceMappingURL=capabilities-CaSNd6J1.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities-CEowrzRM.mjs","names":[],"sources":["../src/providers/capabilities.ts"],"sourcesContent":["import { defineCapabilities } from \"../core/capabilities\";\n\nexport const localCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"combined-stream\",\n \"process.stream\": \"combined-stream\",\n \"process.background\": \"full\",\n \"process.stdin\": \"full\",\n \"process.cancel\": \"full\",\n \"ports.expose\": \"in-process\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"snapshot.restore\": \"filesystem\",\n \"sandbox.resume\": \"memory\",\n \"filesystem.persistent\": \"ephemeral\",\n \"network.policy\": \"native\",\n});\n\n/** @deprecated AgentOS capabilities are exposed as Local capabilities. */\nexport const agentosCapabilities = localCapabilities;\n\nexport const e2bCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.stdin\": \"full\",\n \"process.cancel\": \"full\",\n \"process.pty\": \"native\",\n \"ports.expose\": \"authenticated\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"snapshot.create\": \"template\",\n \"snapshot.delete\": \"template\",\n \"sandbox.resume\": \"memory\",\n \"filesystem.persistent\": \"ephemeral\",\n \"image.custom\": \"template\",\n \"network.policy\": \"native\",\n});\n\nexport const daytonaCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"combined-stream\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.stdin\": \"full\",\n \"process.cancel\": \"full\",\n \"process.pty\": \"native\",\n \"ports.expose\": \"authenticated\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"filesystem.persistent\": \"persistent\",\n \"image.custom\": \"native\",\n \"network.policy\": \"native\",\n \"compute.gpu\": \"native\",\n});\n\nexport const vercelCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.cancel\": \"full\",\n \"process.pty\": \"native\",\n \"ports.expose\": \"public\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"sandbox.resume\": \"persistent\",\n \"filesystem.persistent\": \"persistent\",\n \"network.policy\": \"native\",\n});\n\nexport const upstashCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"combined-stream\",\n \"process.stream\": \"combined-stream\",\n \"process.background\": \"full\",\n \"ports.expose\": \"authenticated\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"sandbox.resume\": \"persistent\",\n \"filesystem.persistent\": \"persistent\",\n \"image.custom\": \"native\",\n \"network.policy\": \"native\",\n});\n"],"mappings":";;;AAEA,MAAa,oBAAoB,mBAAmB;CAClD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,iBAAiB;CACjB,kBAAkB;CAClB,gBAAgB;CAChB,mBAAmB;CACnB,mBAAmB;CACnB,oBAAoB;CACpB,kBAAkB;CAClB,yBAAyB;CACzB,kBAAkB;CACnB,CAAC;;AAGF,MAAa,sBAAsB;AAEnC,MAAa,kBAAkB,mBAAmB;CAChD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,iBAAiB;CACjB,kBAAkB;CAClB,eAAe;CACf,gBAAgB;CAChB,8BAA8B;CAC9B,mBAAmB;CACnB,mBAAmB;CACnB,kBAAkB;CAClB,yBAAyB;CACzB,gBAAgB;CAChB,kBAAkB;CACnB,CAAC;AAEF,MAAa,sBAAsB,mBAAmB;CACpD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,iBAAiB;CACjB,kBAAkB;CAClB,eAAe;CACf,gBAAgB;CAChB,8BAA8B;CAC9B,yBAAyB;CACzB,gBAAgB;CAChB,kBAAkB;CAClB,eAAe;CAChB,CAAC;AAEF,MAAa,qBAAqB,mBAAmB;CACnD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,kBAAkB;CAClB,eAAe;CACf,gBAAgB;CAChB,mBAAmB;CACnB,mBAAmB;CACnB,kBAAkB;CAClB,yBAAyB;CACzB,kBAAkB;CACnB,CAAC;AAEF,MAAa,sBAAsB,mBAAmB;CACpD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,gBAAgB;CAChB,8BAA8B;CAC9B,mBAAmB;CACnB,mBAAmB;CACnB,kBAAkB;CAClB,yBAAyB;CACzB,gBAAgB;CAChB,kBAAkB;CACnB,CAAC"}
1
+ {"version":3,"file":"capabilities-CaSNd6J1.mjs","names":[],"sources":["../src/providers/capabilities.ts"],"sourcesContent":["import { defineCapabilities } from \"../core/capabilities\";\n\nexport const localCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"combined-stream\",\n \"process.stream\": \"combined-stream\",\n \"process.background\": \"full\",\n \"process.stdin\": \"full\",\n \"process.cancel\": \"full\",\n \"ports.expose\": \"in-process\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"snapshot.restore\": \"filesystem\",\n \"sandbox.resume\": \"memory\",\n \"filesystem.persistent\": \"ephemeral\",\n \"network.policy\": \"native\",\n});\n\n/** @deprecated AgentOS capabilities are exposed as Local capabilities. */\nexport const agentosCapabilities = localCapabilities;\n\nexport const e2bCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.stdin\": \"full\",\n \"process.cancel\": \"full\",\n \"process.pty\": \"native\",\n \"ports.expose\": \"authenticated\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"snapshot.create\": \"template\",\n \"snapshot.delete\": \"template\",\n \"sandbox.resume\": \"memory\",\n \"filesystem.persistent\": \"ephemeral\",\n \"image.custom\": \"template\",\n \"network.policy\": \"native\",\n});\n\nexport const daytonaCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"combined-stream\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.stdin\": \"full\",\n \"process.cancel\": \"full\",\n \"process.pty\": \"native\",\n \"ports.expose\": \"authenticated\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"filesystem.persistent\": \"persistent\",\n \"image.custom\": \"native\",\n \"network.policy\": \"native\",\n \"compute.gpu\": \"native\",\n});\n\nexport const vercelCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.cancel\": \"full\",\n \"process.pty\": \"native\",\n \"ports.expose\": \"public\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"sandbox.resume\": \"persistent\",\n \"filesystem.persistent\": \"persistent\",\n \"network.policy\": \"native\",\n});\n\nexport const upstashCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"combined-stream\",\n \"process.stream\": \"combined-stream\",\n \"process.background\": \"full\",\n \"ports.expose\": \"authenticated\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"sandbox.resume\": \"persistent\",\n \"filesystem.persistent\": \"persistent\",\n \"image.custom\": \"native\",\n \"network.policy\": \"native\",\n});\n\nexport const boxCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"ports.expose\": \"public\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"sandbox.resume\": \"persistent\",\n \"filesystem.persistent\": \"persistent\",\n});\n\nexport const railwayCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.cancel\": \"full\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"filesystem.persistent\": \"persistent\",\n \"image.custom\": \"template\",\n \"network.policy\": \"native\",\n});\n"],"mappings":";;;AAEA,MAAa,oBAAoB,mBAAmB;CAClD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,iBAAiB;CACjB,kBAAkB;CAClB,gBAAgB;CAChB,mBAAmB;CACnB,mBAAmB;CACnB,oBAAoB;CACpB,kBAAkB;CAClB,yBAAyB;CACzB,kBAAkB;CACnB,CAAC;;AAGF,MAAa,sBAAsB;AAEnC,MAAa,kBAAkB,mBAAmB;CAChD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,iBAAiB;CACjB,kBAAkB;CAClB,eAAe;CACf,gBAAgB;CAChB,8BAA8B;CAC9B,mBAAmB;CACnB,mBAAmB;CACnB,kBAAkB;CAClB,yBAAyB;CACzB,gBAAgB;CAChB,kBAAkB;CACnB,CAAC;AAEF,MAAa,sBAAsB,mBAAmB;CACpD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,iBAAiB;CACjB,kBAAkB;CAClB,eAAe;CACf,gBAAgB;CAChB,8BAA8B;CAC9B,yBAAyB;CACzB,gBAAgB;CAChB,kBAAkB;CAClB,eAAe;CAChB,CAAC;AAEF,MAAa,qBAAqB,mBAAmB;CACnD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,kBAAkB;CAClB,eAAe;CACf,gBAAgB;CAChB,mBAAmB;CACnB,mBAAmB;CACnB,kBAAkB;CAClB,yBAAyB;CACzB,kBAAkB;CACnB,CAAC;AAEF,MAAa,sBAAsB,mBAAmB;CACpD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,gBAAgB;CAChB,8BAA8B;CAC9B,mBAAmB;CACnB,mBAAmB;CACnB,kBAAkB;CAClB,yBAAyB;CACzB,gBAAgB;CAChB,kBAAkB;CACnB,CAAC;AAEF,MAAa,kBAAkB,mBAAmB;CAChD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,gBAAgB;CAChB,8BAA8B;CAC9B,kBAAkB;CAClB,yBAAyB;CAC1B,CAAC;AAEF,MAAa,sBAAsB,mBAAmB;CACpD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,kBAAkB;CAClB,mBAAmB;CACnB,mBAAmB;CACnB,yBAAyB;CACzB,gBAAgB;CAChB,kBAAkB;CACnB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { t as SandboxError } from "./errors-Ch9PHKTd.mjs";
1
+ import { t as SandboxError } from "./errors-BuF9bYOQ.mjs";
2
2
 
3
3
  //#region src/core/capabilities.ts
4
4
  function defineCapabilities(values) {
@@ -25,4 +25,4 @@ function requireCapability(sandbox, capability) {
25
25
 
26
26
  //#endregion
27
27
  export { supports as i, defineCapabilities as n, requireCapability as r, capabilityMode as t };
28
- //# sourceMappingURL=capabilities-COKpwoFH.mjs.map
28
+ //# sourceMappingURL=capabilities-xs9kaHrK.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities-COKpwoFH.mjs","names":[],"sources":["../src/core/capabilities.ts"],"sourcesContent":["import { SandboxError } from \"./errors\";\nimport type { Capability, CapabilityMap, CapabilityMode, Sandbox } from \"./types\";\n\nexport function defineCapabilities(\n values: Partial<Record<Capability, CapabilityMode>>,\n): CapabilityMap {\n return new Proxy(values, {\n get(target, property) {\n return typeof property === \"string\" && property in target\n ? target[property as Capability]\n : false;\n },\n }) as CapabilityMap;\n}\n\nexport function supports(sandbox: Pick<Sandbox, \"capabilities\">, capability: Capability): boolean {\n return sandbox.capabilities[capability] !== false;\n}\n\nexport function capabilityMode(\n sandbox: Pick<Sandbox, \"capabilities\">,\n capability: Capability,\n): CapabilityMode | false {\n return sandbox.capabilities[capability];\n}\n\nexport function requireCapability(\n sandbox: Pick<Sandbox, \"capabilities\" | \"provider\">,\n capability: Capability,\n): CapabilityMode {\n const mode = sandbox.capabilities[capability];\n if (mode === false) {\n throw new SandboxError({\n code: \"unsupported\",\n provider: sandbox.provider,\n operation: capability,\n message: `${sandbox.provider} does not support ${capability}`,\n });\n }\n return mode;\n}\n"],"mappings":";;;AAGA,SAAgB,mBACd,QACe;AACf,QAAO,IAAI,MAAM,QAAQ,EACvB,IAAI,QAAQ,UAAU;AACpB,SAAO,OAAO,aAAa,YAAY,YAAY,SAC/C,OAAO,YACP;IAEP,CAAC;;AAGJ,SAAgB,SAAS,SAAwC,YAAiC;AAChG,QAAO,QAAQ,aAAa,gBAAgB;;AAG9C,SAAgB,eACd,SACA,YACwB;AACxB,QAAO,QAAQ,aAAa;;AAG9B,SAAgB,kBACd,SACA,YACgB;CAChB,MAAM,OAAO,QAAQ,aAAa;AAClC,KAAI,SAAS,MACX,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU,QAAQ;EAClB,WAAW;EACX,SAAS,GAAG,QAAQ,SAAS,oBAAoB;EAClD,CAAC;AAEJ,QAAO"}
1
+ {"version":3,"file":"capabilities-xs9kaHrK.mjs","names":[],"sources":["../src/core/capabilities.ts"],"sourcesContent":["import { SandboxError } from \"./errors\";\nimport type { Capability, CapabilityMap, CapabilityMode, Sandbox } from \"./types\";\n\nexport function defineCapabilities(\n values: Partial<Record<Capability, CapabilityMode>>,\n): CapabilityMap {\n return new Proxy(values, {\n get(target, property) {\n return typeof property === \"string\" && property in target\n ? target[property as Capability]\n : false;\n },\n }) as CapabilityMap;\n}\n\nexport function supports(sandbox: Pick<Sandbox, \"capabilities\">, capability: Capability): boolean {\n return sandbox.capabilities[capability] !== false;\n}\n\nexport function capabilityMode(\n sandbox: Pick<Sandbox, \"capabilities\">,\n capability: Capability,\n): CapabilityMode | false {\n return sandbox.capabilities[capability];\n}\n\nexport function requireCapability(\n sandbox: Pick<Sandbox, \"capabilities\" | \"provider\">,\n capability: Capability,\n): CapabilityMode {\n const mode = sandbox.capabilities[capability];\n if (mode === false) {\n throw new SandboxError({\n code: \"unsupported\",\n provider: sandbox.provider,\n operation: capability,\n message: `${sandbox.provider} does not support ${capability}`,\n });\n }\n return mode;\n}\n"],"mappings":";;;AAGA,SAAgB,mBACd,QACe;AACf,QAAO,IAAI,MAAM,QAAQ,EACvB,IAAI,QAAQ,UAAU;AACpB,SAAO,OAAO,aAAa,YAAY,YAAY,SAC/C,OAAO,YACP;IAEP,CAAC;;AAGJ,SAAgB,SAAS,SAAwC,YAAiC;AAChG,QAAO,QAAQ,aAAa,gBAAgB;;AAG9C,SAAgB,eACd,SACA,YACwB;AACxB,QAAO,QAAQ,aAAa;;AAG9B,SAAgB,kBACd,SACA,YACgB;CAChB,MAAM,OAAO,QAAQ,aAAa;AAClC,KAAI,SAAS,MACX,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU,QAAQ;EAClB,WAAW;EACX,SAAS,GAAG,QAAQ,SAAS,oBAAoB;EAClD,CAAC;AAEJ,QAAO"}
@@ -46,16 +46,23 @@ function isSandboxError(error) {
46
46
  function normalizeError(provider, operation, error, fallback = "internal") {
47
47
  if (isSandboxError(error)) return error;
48
48
  const message = error instanceof Error ? error.message : "Unknown provider error";
49
- const lower = message.toLowerCase();
49
+ const lower = `${error instanceof Error ? error.name : ""} ${message}`.toLowerCase();
50
+ const status = errorStatus(error);
50
51
  return new SandboxError({
51
- code: lower.includes("unauthorized") || lower.includes("api key") ? "authentication" : lower.includes("forbidden") || lower.includes("permission") ? "permission" : lower.includes("not found") || lower.includes("enoent") ? "not_found" : lower.includes("timeout") || lower.includes("timed out") ? "timeout" : lower.includes("rate limit") || lower.includes("429") ? "rate_limited" : lower.includes("already exists") || lower.includes("conflict") ? "conflict" : fallback,
52
+ code: status === 401 || lower.includes("unauthorized") || lower.includes("api key") ? "authentication" : status === 403 || lower.includes("forbidden") || lower.includes("permission") ? "permission" : status === 404 || lower.includes("not found") || lower.includes("enoent") ? "not_found" : status === 408 || lower.includes("timeout") || lower.includes("timed out") ? "timeout" : status === 429 || lower.includes("rate limit") || lower.includes("429") ? "rate_limited" : status === 409 || lower.includes("already exists") || lower.includes("conflict") ? "conflict" : fallback,
52
53
  provider,
53
54
  operation,
54
55
  message,
55
56
  cause: error
56
57
  });
57
58
  }
59
+ function errorStatus(error) {
60
+ if (typeof error !== "object" || error === null) return void 0;
61
+ if ("statusCode" in error && typeof error.statusCode === "number") return error.statusCode;
62
+ if ("status" in error && typeof error.status === "number") return error.status;
63
+ if ("response" in error && typeof error.response === "object" && error.response !== null && "status" in error.response && typeof error.response.status === "number") return error.response.status;
64
+ }
58
65
 
59
66
  //#endregion
60
67
  export { sandboxErrorCodes as a, redactSensitive as i, isSandboxError as n, normalizeError as r, SandboxError as t };
61
- //# sourceMappingURL=errors-Ch9PHKTd.mjs.map
68
+ //# sourceMappingURL=errors-BuF9bYOQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-BuF9bYOQ.mjs","names":[],"sources":["../src/core/errors.ts"],"sourcesContent":["export const sandboxErrorCodes = [\n \"authentication\",\n \"permission\",\n \"not_found\",\n \"timeout\",\n \"rate_limited\",\n \"unavailable\",\n \"unsupported\",\n \"invalid_input\",\n \"conflict\",\n \"terminated\",\n \"process_failed\",\n \"internal\",\n] as const;\n\nexport type SandboxErrorCode = (typeof sandboxErrorCodes)[number];\n\nconst sensitive =\n /((?:token|key|secret|authorization|credential|signature)=?)[^\\s&,]+|https?:\\/\\/[^\\s]+(?:token|sig|signature|key)=[^\\s&]+/gi;\n\nexport function redactSensitive(value: string): string {\n return value.replace(sensitive, \"$1[REDACTED]\");\n}\n\nexport class SandboxError extends Error {\n readonly code: SandboxErrorCode;\n readonly provider: string;\n readonly operation?: string;\n readonly retryable: boolean;\n override readonly cause?: unknown;\n\n constructor(options: {\n code: SandboxErrorCode;\n provider: string;\n message: string;\n operation?: string;\n retryable?: boolean;\n cause?: unknown;\n }) {\n super(redactSensitive(options.message), { cause: options.cause });\n this.name = \"SandboxError\";\n this.code = options.code;\n this.provider = options.provider;\n this.operation = options.operation;\n this.retryable =\n options.retryable ?? [\"rate_limited\", \"timeout\", \"unavailable\"].includes(options.code);\n this.cause = options.cause;\n }\n\n override toString(): string {\n return `${this.name} [${this.code}]: ${this.message}`;\n }\n}\n\nexport function isSandboxError(error: unknown): error is SandboxError {\n return error instanceof SandboxError;\n}\n\nexport function normalizeError(\n provider: string,\n operation: string,\n error: unknown,\n fallback: SandboxErrorCode = \"internal\",\n): SandboxError {\n if (isSandboxError(error)) return error;\n const message = error instanceof Error ? error.message : \"Unknown provider error\";\n const lower = `${error instanceof Error ? error.name : \"\"} ${message}`.toLowerCase();\n const status = errorStatus(error);\n const code =\n status === 401 || lower.includes(\"unauthorized\") || lower.includes(\"api key\")\n ? \"authentication\"\n : status === 403 || lower.includes(\"forbidden\") || lower.includes(\"permission\")\n ? \"permission\"\n : status === 404 || lower.includes(\"not found\") || lower.includes(\"enoent\")\n ? \"not_found\"\n : status === 408 || lower.includes(\"timeout\") || lower.includes(\"timed out\")\n ? \"timeout\"\n : status === 429 || lower.includes(\"rate limit\") || lower.includes(\"429\")\n ? \"rate_limited\"\n : status === 409 || lower.includes(\"already exists\") || lower.includes(\"conflict\")\n ? \"conflict\"\n : fallback;\n return new SandboxError({ code, provider, operation, message, cause: error });\n}\n\nfunction errorStatus(error: unknown): number | undefined {\n if (typeof error !== \"object\" || error === null) return undefined;\n if (\"statusCode\" in error && typeof error.statusCode === \"number\") return error.statusCode;\n if (\"status\" in error && typeof error.status === \"number\") return error.status;\n if (\n \"response\" in error &&\n typeof error.response === \"object\" &&\n error.response !== null &&\n \"status\" in error.response &&\n typeof error.response.status === \"number\"\n ) {\n return error.response.status;\n }\n return undefined;\n}\n"],"mappings":";AAAA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAID,MAAM,YACJ;AAEF,SAAgB,gBAAgB,OAAuB;AACrD,QAAO,MAAM,QAAQ,WAAW,eAAe;;AAGjD,IAAa,eAAb,cAAkC,MAAM;CACtC,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAkB;CAElB,YAAY,SAOT;AACD,QAAM,gBAAgB,QAAQ,QAAQ,EAAE,EAAE,OAAO,QAAQ,OAAO,CAAC;AACjE,OAAK,OAAO;AACZ,OAAK,OAAO,QAAQ;AACpB,OAAK,WAAW,QAAQ;AACxB,OAAK,YAAY,QAAQ;AACzB,OAAK,YACH,QAAQ,aAAa;GAAC;GAAgB;GAAW;GAAc,CAAC,SAAS,QAAQ,KAAK;AACxF,OAAK,QAAQ,QAAQ;;CAGvB,AAAS,WAAmB;AAC1B,SAAO,GAAG,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK,KAAK;;;AAIhD,SAAgB,eAAe,OAAuC;AACpE,QAAO,iBAAiB;;AAG1B,SAAgB,eACd,UACA,WACA,OACA,WAA6B,YACf;AACd,KAAI,eAAe,MAAM,CAAE,QAAO;CAClC,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;CACzD,MAAM,QAAQ,GAAG,iBAAiB,QAAQ,MAAM,OAAO,GAAG,GAAG,UAAU,aAAa;CACpF,MAAM,SAAS,YAAY,MAAM;AAejC,QAAO,IAAI,aAAa;EAAE,MAbxB,WAAW,OAAO,MAAM,SAAS,eAAe,IAAI,MAAM,SAAS,UAAU,GACzE,mBACA,WAAW,OAAO,MAAM,SAAS,YAAY,IAAI,MAAM,SAAS,aAAa,GAC3E,eACA,WAAW,OAAO,MAAM,SAAS,YAAY,IAAI,MAAM,SAAS,SAAS,GACvE,cACA,WAAW,OAAO,MAAM,SAAS,UAAU,IAAI,MAAM,SAAS,YAAY,GACxE,YACA,WAAW,OAAO,MAAM,SAAS,aAAa,IAAI,MAAM,SAAS,MAAM,GACrE,iBACA,WAAW,OAAO,MAAM,SAAS,iBAAiB,IAAI,MAAM,SAAS,WAAW,GAC9E,aACA;EACgB;EAAU;EAAW;EAAS,OAAO;EAAO,CAAC;;AAG/E,SAAS,YAAY,OAAoC;AACvD,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,KAAI,gBAAgB,SAAS,OAAO,MAAM,eAAe,SAAU,QAAO,MAAM;AAChF,KAAI,YAAY,SAAS,OAAO,MAAM,WAAW,SAAU,QAAO,MAAM;AACxE,KACE,cAAc,SACd,OAAO,MAAM,aAAa,YAC1B,MAAM,aAAa,QACnB,YAAY,MAAM,YAClB,OAAO,MAAM,SAAS,WAAW,SAEjC,QAAO,MAAM,SAAS"}
@@ -1,5 +1,5 @@
1
- import "../types-BTagTtsp.mjs";
2
- import { o as SandboxProvider } from "../provider-_caCV8kk.mjs";
1
+ import "../types-Bv6I2U1c.mjs";
2
+ import { o as SandboxProvider } from "../provider-DOBErkBO.mjs";
3
3
  import { SandboxBackend, SandboxBackendHandle, SandboxNetworkPolicy, SandboxSession as EveSandboxSession } from "eve/sandbox";
4
4
 
5
5
  //#region src/eve/index.d.ts
@@ -1,5 +1,5 @@
1
- import { n as isSandboxError, t as SandboxError } from "../errors-Ch9PHKTd.mjs";
2
- import { r as toAISandboxSession } from "../ai-DhfwIZdL.mjs";
1
+ import { n as isSandboxError, t as SandboxError } from "../errors-BuF9bYOQ.mjs";
2
+ import { r as toAISandboxSession } from "../ai-DeFa8yPk.mjs";
3
3
 
4
4
  //#region src/eve/index.ts
5
5
  /** Create an Eve beta SandboxBackend backed by a managed sandbox-sdk provider. */
@@ -1,4 +1,4 @@
1
- import { o as SandboxProvider } from "./provider-_caCV8kk.mjs";
1
+ import { o as SandboxProvider } from "./provider-DOBErkBO.mjs";
2
2
  import { AgentOs, AgentOsOptions } from "@rivet-dev/agentos-core";
3
3
 
4
4
  //#region src/providers/agentos/index.d.ts
@@ -22,4 +22,4 @@ interface AgentOsSandbox {
22
22
  declare function agentos(options?: AgentOsProviderOptions): SandboxProvider<AgentOsSandbox>;
23
23
  //#endregion
24
24
  export { AgentOsSandbox as n, agentos as r, AgentOsProviderOptions as t };
25
- //# sourceMappingURL=index-B1YT6OQ8.d.mts.map
25
+ //# sourceMappingURL=index-CkTwqD0X.d.mts.map
@@ -1,4 +1,4 @@
1
- import { f as Sandbox, r as CapabilityMode, t as Capability } from "./types-BTagTtsp.mjs";
1
+ import { f as Sandbox, r as CapabilityMode, t as Capability } from "./types-Bv6I2U1c.mjs";
2
2
 
3
3
  //#region src/core/capabilities.d.ts
4
4
  declare function supports(sandbox: Pick<Sandbox, "capabilities">, capability: Capability): boolean;
@@ -28,4 +28,4 @@ declare class SandboxError extends Error {
28
28
  declare function isSandboxError(error: unknown): error is SandboxError;
29
29
  //#endregion
30
30
  export { sandboxErrorCodes as a, supports as c, redactSensitive as i, SandboxErrorCode as n, capabilityMode as o, isSandboxError as r, requireCapability as s, SandboxError as t };
31
- //# sourceMappingURL=index-BMFkO6Fv.d.mts.map
31
+ //# sourceMappingURL=index-Dh9xob2s.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { _ as SandboxProcesses, a as CommandResult, b as capabilityNames, c as ProcessOutputEvent, d as RunOptions, f as Sandbox, g as SandboxProcess, h as SandboxPorts, i as CommandInput, l as ProcessStatus, m as SandboxFiles, n as CapabilityMap, o as ExposedPort, p as SandboxDirectoryEntry, r as CapabilityMode, s as FileValue, t as Capability, u as ProviderName, v as SandboxSnapshot, x as providerNames, y as SandboxSnapshots } from "./types-BTagTtsp.mjs";
2
- import { a as SandboxNetworkPolicy, i as ManagedSandboxSession, n as ManagedSandboxProvider, r as ManagedSandboxResumeOptions, t as ManagedSandboxCreateOptions } from "./provider-_caCV8kk.mjs";
3
- import { a as sandboxErrorCodes, c as supports, i as redactSensitive, n as SandboxErrorCode, o as capabilityMode, r as isSandboxError, s as requireCapability, t as SandboxError } from "./index-BMFkO6Fv.mjs";
4
- import { n as createSandbox, r as withSandbox } from "./sandbox-BUYT-1C9.mjs";
1
+ import { _ as SandboxProcesses, a as CommandResult, b as capabilityNames, c as ProcessOutputEvent, d as RunOptions, f as Sandbox, g as SandboxProcess, h as SandboxPorts, i as CommandInput, l as ProcessStatus, m as SandboxFiles, n as CapabilityMap, o as ExposedPort, p as SandboxDirectoryEntry, r as CapabilityMode, s as FileValue, t as Capability, u as ProviderName, v as SandboxSnapshot, x as providerNames, y as SandboxSnapshots } from "./types-Bv6I2U1c.mjs";
2
+ import { a as SandboxNetworkPolicy, i as ManagedSandboxSession, n as ManagedSandboxProvider, r as ManagedSandboxResumeOptions, t as ManagedSandboxCreateOptions } from "./provider-DOBErkBO.mjs";
3
+ import { a as sandboxErrorCodes, c as supports, i as redactSensitive, n as SandboxErrorCode, o as capabilityMode, r as isSandboxError, s as requireCapability, t as SandboxError } from "./index-Dh9xob2s.mjs";
4
+ import { n as createSandbox, r as withSandbox } from "./sandbox-DdEqoXJF.mjs";
5
5
  export { Capability, CapabilityMap, CapabilityMode, CommandInput, CommandResult, ExposedPort, FileValue, ManagedSandboxCreateOptions, ManagedSandboxProvider, ManagedSandboxResumeOptions, ManagedSandboxSession, ProcessOutputEvent, ProcessStatus, ProviderName, RunOptions, Sandbox, SandboxDirectoryEntry, SandboxError, SandboxErrorCode, SandboxFiles, SandboxNetworkPolicy, SandboxPorts, SandboxProcess, SandboxProcesses, SandboxSnapshot, SandboxSnapshots, capabilityMode, capabilityNames, createSandbox, isSandboxError, providerNames, redactSensitive, requireCapability, sandboxErrorCodes, supports, withSandbox };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { a as sandboxErrorCodes, i as redactSensitive, n as isSandboxError, t as SandboxError } from "./errors-Ch9PHKTd.mjs";
2
- import { i as supports, r as requireCapability, t as capabilityMode } from "./capabilities-COKpwoFH.mjs";
3
- import { n as withSandbox, t as createSandbox } from "./sandbox-BwyHcB_C.mjs";
1
+ import { a as sandboxErrorCodes, i as redactSensitive, n as isSandboxError, t as SandboxError } from "./errors-BuF9bYOQ.mjs";
2
+ import { i as supports, r as requireCapability, t as capabilityMode } from "./capabilities-xs9kaHrK.mjs";
3
+ import { n as withSandbox, t as createSandbox } from "./sandbox-DgtY5hvt.mjs";
4
4
 
5
5
  //#region src/core/types.ts
6
6
  const providerNames = [
@@ -8,7 +8,9 @@ const providerNames = [
8
8
  "e2b",
9
9
  "daytona",
10
10
  "vercel",
11
- "upstash"
11
+ "upstash",
12
+ "box",
13
+ "railway"
12
14
  ];
13
15
  const capabilityNames = [
14
16
  "files.read",