@opencoredev/sandbox-sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +21 -7
- package/dist/{agentos-BOFA_q-a.mjs → agentos-DFJ4TFaY.mjs} +2 -2
- package/dist/{agentos-BOFA_q-a.mjs.map → agentos-DFJ4TFaY.mjs.map} +1 -1
- package/dist/ai/harness.d.mts +2 -2
- package/dist/ai/index.d.mts +1 -1
- package/dist/{capabilities-CMnszzpt.d.mts → capabilities-DftdOpIu.d.mts} +2 -2
- package/dist/eve/index.d.mts +2 -2
- package/dist/{index-B1YT6OQ8.d.mts → index-Bk6GmoEt.d.mts} +2 -2
- package/dist/{index-BMFkO6Fv.d.mts → index-BufLdrbp.d.mts} +2 -2
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/mastra/index.d.mts +2 -2
- package/dist/metadata.d.mts +1 -1
- package/dist/metadata.mjs +2 -2
- package/dist/metadata.mjs.map +1 -1
- package/dist/{provider-_caCV8kk.d.mts → provider-BzzkIVmv.d.mts} +2 -2
- package/dist/{provider-utils-DilOYLBO.mjs → provider-utils-BjOSWNsh.mjs} +2 -2
- package/dist/{provider-utils-DilOYLBO.mjs.map → provider-utils-BjOSWNsh.mjs.map} +1 -1
- package/dist/providers/agentos/index.d.mts +6 -6
- package/dist/providers/agentos/index.mjs +3 -3
- package/dist/providers/daytona/index.d.mts +5 -5
- package/dist/providers/daytona/index.mjs +2 -2
- package/dist/providers/e2b/index.d.mts +5 -5
- package/dist/providers/e2b/index.mjs +2 -2
- package/dist/providers/local/index.d.mts +6 -6
- package/dist/providers/local/index.mjs +3 -3
- package/dist/providers/upstash/index.d.mts +5 -5
- package/dist/providers/upstash/index.mjs +2 -2
- package/dist/providers/vercel/index.d.mts +6 -5
- package/dist/providers/vercel/index.mjs +2 -2
- package/dist/providers/vercel/index.mjs.map +1 -1
- package/dist/{sandbox-BUYT-1C9.d.mts → sandbox-Dco6z9aB.d.mts} +12 -3
- package/dist/{sandbox-BwyHcB_C.mjs → sandbox-rIOcbhtM.mjs} +12 -2
- package/dist/sandbox-rIOcbhtM.mjs.map +1 -0
- package/dist/testing/index.d.mts +3 -3
- package/dist/testing/index.mjs +1 -1
- package/dist/{types-BTagTtsp.d.mts → types-DEi_dfRR.d.mts} +4 -1
- package/package.json +1 -1
- package/dist/sandbox-BwyHcB_C.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -12,15 +12,29 @@ 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 |
|
|
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 |
|
|
24
38
|
|
|
25
39
|
Local is included. Cloud providers use their official SDKs and credentials.
|
|
26
40
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as SandboxError } from "./errors-Ch9PHKTd.mjs";
|
|
2
2
|
import { i as localCapabilities } from "./capabilities-CEowrzRM.mjs";
|
|
3
|
-
import { n as portResult, o as withManagedSessions, r as toUint8Array } from "./provider-utils-
|
|
3
|
+
import { n as portResult, o as withManagedSessions, r as toUint8Array } from "./provider-utils-BjOSWNsh.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
|
|
6
6
|
//#region src/providers/agentos/index.ts
|
|
@@ -386,4 +386,4 @@ function interrupted(operation) {
|
|
|
386
386
|
|
|
387
387
|
//#endregion
|
|
388
388
|
export { agentos as t };
|
|
389
|
-
//# sourceMappingURL=agentos-
|
|
389
|
+
//# sourceMappingURL=agentos-DFJ4TFaY.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;EACV,SAAS;EACT,YAAY;EACZ,gBAAgB;EAChB,oBAAoB,MAAM,OAAO;EACjC,eAAe;EACf,oBAAoB,MAAM,OAAO;EAClC;CACD,MAAM,EAAE,uBAAuB,KAAK,OAAO,MAAM;CACjD,WAAW;EACT,eAAe;EACf,kBAAkB;EAClB,0BAA0B,IAAI,OAAO;EACrC,uBAAuB,OAAO;EAC/B;CACF;;;;;;;AA8BD,SAAS,sBACP,UAAkC,EAAE,EACH;AAqLjC,QAAO,oBApL2C;EAChD,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;GAC1B,MAAM,KAAK,YAAY;GACvB,MAAM,4BAAY,IAAI,KAA6B;GACnD,MAAM,cAAc,QAAQ,WAAW,EAAE;GACzC,IAAIC,KAAu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AAC;;AAGJ,SAAS,YAAY,WAAiC;AACpD,QAAO,IAAI,aAAa;EACtB,MAAM;EACN,UAAU;EACV;EACA,SAAS;EACV,CAAC"}
|
|
1
|
+
{"version":3,"file":"agentos-DFJ4TFaY.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;EACV,SAAS;EACT,YAAY;EACZ,gBAAgB;EAChB,oBAAoB,MAAM,OAAO;EACjC,eAAe;EACf,oBAAoB,MAAM,OAAO;EAClC;CACD,MAAM,EAAE,uBAAuB,KAAK,OAAO,MAAM;CACjD,WAAW;EACT,eAAe;EACf,kBAAkB;EAClB,0BAA0B,IAAI,OAAO;EACrC,uBAAuB,OAAO;EAC/B;CACF;;;;;;;AA8BD,SAAS,sBACP,UAAkC,EAAE,EACH;AAqLjC,QAAO,oBApL2C;EAChD,I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,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"}
|
package/dist/ai/harness.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { o as SandboxProvider } from "../provider-
|
|
1
|
+
import "../types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../provider-BzzkIVmv.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
|
package/dist/ai/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as CapabilityMode } from "./types-
|
|
1
|
+
import { r as CapabilityMode } from "./types-DEi_dfRR.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>>;
|
|
@@ -10,4 +10,4 @@ declare const vercelCapabilities: Readonly<Record<"files.read" | "files.write" |
|
|
|
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
11
|
//#endregion
|
|
12
12
|
export { upstashCapabilities as a, localCapabilities as i, daytonaCapabilities as n, vercelCapabilities as o, e2bCapabilities as r, agentosCapabilities as t };
|
|
13
|
-
//# sourceMappingURL=capabilities-
|
|
13
|
+
//# sourceMappingURL=capabilities-DftdOpIu.d.mts.map
|
package/dist/eve/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { o as SandboxProvider } from "../provider-
|
|
1
|
+
import "../types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../provider-BzzkIVmv.mjs";
|
|
3
3
|
import { SandboxBackend, SandboxBackendHandle, SandboxNetworkPolicy, SandboxSession as EveSandboxSession } from "eve/sandbox";
|
|
4
4
|
|
|
5
5
|
//#region src/eve/index.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as SandboxProvider } from "./provider-
|
|
1
|
+
import { o as SandboxProvider } from "./provider-BzzkIVmv.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-
|
|
25
|
+
//# sourceMappingURL=index-Bk6GmoEt.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as Sandbox, r as CapabilityMode, t as Capability } from "./types-
|
|
1
|
+
import { f as Sandbox, r as CapabilityMode, t as Capability } from "./types-DEi_dfRR.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-
|
|
31
|
+
//# sourceMappingURL=index-BufLdrbp.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-
|
|
2
|
-
import { a as SandboxNetworkPolicy, i as ManagedSandboxSession, n as ManagedSandboxProvider, r as ManagedSandboxResumeOptions, t as ManagedSandboxCreateOptions } from "./provider-
|
|
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-
|
|
4
|
-
import { n as createSandbox, r as withSandbox } from "./sandbox-
|
|
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-DEi_dfRR.mjs";
|
|
2
|
+
import { a as SandboxNetworkPolicy, i as ManagedSandboxSession, n as ManagedSandboxProvider, r as ManagedSandboxResumeOptions, t as ManagedSandboxCreateOptions } from "./provider-BzzkIVmv.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-BufLdrbp.mjs";
|
|
4
|
+
import { n as createSandbox, r as withSandbox } from "./sandbox-Dco6z9aB.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
1
|
import { a as sandboxErrorCodes, i as redactSensitive, n as isSandboxError, t as SandboxError } from "./errors-Ch9PHKTd.mjs";
|
|
2
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-
|
|
3
|
+
import { n as withSandbox, t as createSandbox } from "./sandbox-rIOcbhtM.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/core/types.ts
|
|
6
6
|
const providerNames = [
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/core/types.ts"],"sourcesContent":["export const providerNames = [\"local\", \"e2b\", \"daytona\", \"vercel\", \"upstash\"] as const;\nexport type ProviderName = (typeof providerNames)[number];\n\nexport const capabilityNames = [\n \"files.read\",\n \"files.write\",\n \"files.list\",\n \"files.remove\",\n \"process.run\",\n \"process.stream\",\n \"process.background\",\n \"process.stdin\",\n \"process.cancel\",\n \"ports.expose\",\n \"ports.authenticatedRequest\",\n \"snapshot.create\",\n \"snapshot.delete\",\n \"snapshot.restore\",\n \"sandbox.resume\",\n \"filesystem.persistent\",\n \"image.custom\",\n \"network.policy\",\n \"process.pty\",\n \"compute.gpu\",\n] as const;\n\nexport type Capability = (typeof capabilityNames)[number];\nexport type CapabilityMode =\n | \"filesystem\"\n | \"memory\"\n | \"template\"\n | \"fork\"\n | \"public\"\n | \"authenticated\"\n | \"combined-stream\"\n | \"separate-streams\"\n | \"ephemeral\"\n | \"persistent\"\n | \"localhost\"\n | \"in-process\"\n | \"full\"\n | \"native\";\n\nexport type CapabilityMap = Readonly<Record<Capability, false | CapabilityMode>>;\n\nexport type CommandInput = string | { command: string; args?: readonly string[] };\n\nexport interface RunOptions {\n cwd?: string;\n env?: Readonly<Record<string, string>>;\n timeout?: number;\n signal?: AbortSignal;\n}\n\nexport interface CommandResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n success: boolean;\n signal?: string;\n durationMs?: number;\n}\n\nexport type FileValue = string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array>;\n\nexport interface SandboxDirectoryEntry {\n name: string;\n path: string;\n type: \"file\" | \"directory\" | \"symlink\" | \"unknown\";\n size?: number;\n}\n\nexport interface SandboxFiles {\n write(path: string, value: FileValue): Promise<void>;\n read(path: string): Promise<Uint8Array>;\n text(path: string): Promise<string>;\n list(path?: string): Promise<SandboxDirectoryEntry[]>;\n mkdir(path: string): Promise<void>;\n remove(path: string): Promise<void>;\n exists(path: string): Promise<boolean>;\n}\n\nexport interface ProcessOutputEvent {\n stream: \"stdout\" | \"stderr\";\n data: string | Uint8Array;\n timestamp?: Date;\n}\n\nexport type ProcessStatus = \"starting\" | \"running\" | \"exited\" | \"killed\" | \"unknown\";\n\nexport interface SandboxProcess {\n readonly id: string;\n status(): Promise<ProcessStatus>;\n output(): AsyncIterable<ProcessOutputEvent>;\n write(value: string | Uint8Array): Promise<void>;\n wait(): Promise<{ exitCode: number }>;\n kill(signal?: string): Promise<void>;\n}\n\nexport interface SandboxProcesses {\n start(command: CommandInput, options?: RunOptions): Promise<SandboxProcess>;\n}\n\nexport interface ExposedPort {\n readonly port: number;\n readonly url: string;\n readonly public: boolean;\n readonly authenticated: boolean;\n request?(path?: string, init?: RequestInit): Promise<Response>;\n toJSON(): Omit<ExposedPort, \"request\" | \"toJSON\">;\n}\n\nexport interface SandboxPorts {\n expose(port: number): Promise<ExposedPort>;\n}\n\nexport interface SandboxSnapshot {\n readonly id: string;\n readonly name?: string;\n readonly mode: CapabilityMode;\n readonly createdAt?: Date;\n}\n\nexport interface SandboxSnapshots {\n create(options?: { name?: string }): Promise<SandboxSnapshot>;\n delete(snapshot: SandboxSnapshot | string): Promise<void>;\n restore(snapshot: SandboxSnapshot | string): Promise<void>;\n}\n\nexport interface Sandbox<TRaw = unknown> {\n readonly id: string;\n readonly provider: ProviderName;\n readonly cwd: string;\n readonly capabilities: CapabilityMap;\n readonly raw: TRaw;\n readonly files: SandboxFiles;\n readonly processes: SandboxProcesses;\n readonly ports: SandboxPorts;\n readonly snapshots: SandboxSnapshots;\n run(command: CommandInput, options?: RunOptions): Promise<CommandResult>;\n stop(): Promise<void>;\n}\n"],"mappings":";;;;;AAAA,MAAa,gBAAgB;CAAC;CAAS;CAAO;CAAW;CAAU;CAAU;AAG7E,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/core/types.ts"],"sourcesContent":["export const providerNames = [\"local\", \"e2b\", \"daytona\", \"vercel\", \"upstash\"] as const;\nexport type ProviderName = (typeof providerNames)[number];\n\nexport const capabilityNames = [\n \"files.read\",\n \"files.write\",\n \"files.list\",\n \"files.remove\",\n \"process.run\",\n \"process.stream\",\n \"process.background\",\n \"process.stdin\",\n \"process.cancel\",\n \"ports.expose\",\n \"ports.authenticatedRequest\",\n \"snapshot.create\",\n \"snapshot.delete\",\n \"snapshot.restore\",\n \"sandbox.resume\",\n \"filesystem.persistent\",\n \"image.custom\",\n \"network.policy\",\n \"process.pty\",\n \"compute.gpu\",\n] as const;\n\nexport type Capability = (typeof capabilityNames)[number];\nexport type CapabilityMode =\n | \"filesystem\"\n | \"memory\"\n | \"template\"\n | \"fork\"\n | \"public\"\n | \"authenticated\"\n | \"combined-stream\"\n | \"separate-streams\"\n | \"ephemeral\"\n | \"persistent\"\n | \"localhost\"\n | \"in-process\"\n | \"full\"\n | \"native\";\n\nexport type CapabilityMap = Readonly<Record<Capability, false | CapabilityMode>>;\n\nexport type CommandInput = string | { command: string; args?: readonly string[] };\n\nexport interface RunOptions {\n cwd?: string;\n env?: Readonly<Record<string, string>>;\n timeout?: number;\n signal?: AbortSignal;\n}\n\nexport interface CommandResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n success: boolean;\n signal?: string;\n durationMs?: number;\n}\n\nexport type FileValue = string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array>;\n\nexport interface SandboxDirectoryEntry {\n name: string;\n path: string;\n type: \"file\" | \"directory\" | \"symlink\" | \"unknown\";\n size?: number;\n}\n\nexport interface SandboxFiles {\n write(path: string, value: FileValue): Promise<void>;\n read(path: string): Promise<Uint8Array>;\n text(path: string): Promise<string>;\n list(path?: string): Promise<SandboxDirectoryEntry[]>;\n mkdir(path: string): Promise<void>;\n remove(path: string): Promise<void>;\n exists(path: string): Promise<boolean>;\n}\n\nexport interface ProcessOutputEvent {\n stream: \"stdout\" | \"stderr\";\n data: string | Uint8Array;\n timestamp?: Date;\n}\n\nexport type ProcessStatus = \"starting\" | \"running\" | \"exited\" | \"killed\" | \"unknown\";\n\nexport interface SandboxProcess {\n readonly id: string;\n status(): Promise<ProcessStatus>;\n output(): AsyncIterable<ProcessOutputEvent>;\n write(value: string | Uint8Array): Promise<void>;\n wait(): Promise<{ exitCode: number }>;\n kill(signal?: string): Promise<void>;\n}\n\nexport interface SandboxProcesses {\n start(command: CommandInput, options?: RunOptions): Promise<SandboxProcess>;\n}\n\nexport interface ExposedPort {\n readonly port: number;\n readonly url: string;\n readonly public: boolean;\n readonly authenticated: boolean;\n request?(path?: string, init?: RequestInit): Promise<Response>;\n toJSON(): Omit<ExposedPort, \"request\" | \"toJSON\">;\n}\n\nexport interface SandboxPorts {\n expose(port: number): Promise<ExposedPort>;\n}\n\nexport interface SandboxSnapshot {\n readonly id: string;\n readonly name?: string;\n readonly mode: CapabilityMode;\n readonly createdAt?: Date;\n}\n\nexport interface SandboxSnapshots {\n create(options?: { name?: string }): Promise<SandboxSnapshot>;\n delete(snapshot: SandboxSnapshot | string): Promise<void>;\n restore(snapshot: SandboxSnapshot | string): Promise<void>;\n}\n\nexport interface Sandbox<TRaw = unknown> {\n readonly id: string;\n readonly provider: ProviderName;\n readonly cwd: string;\n readonly capabilities: CapabilityMap;\n readonly raw: TRaw;\n readonly files: SandboxFiles;\n readonly processes: SandboxProcesses;\n readonly ports: SandboxPorts;\n readonly snapshots: SandboxSnapshots;\n run(command: CommandInput, options?: RunOptions): Promise<CommandResult>;\n /** Stops the provider runtime. Repeated calls share the same cleanup operation. */\n stop(): Promise<void>;\n /** Stops the sandbox when an `await using` scope exits. */\n [Symbol.asyncDispose](): Promise<void>;\n}\n"],"mappings":";;;;;AAAA,MAAa,gBAAgB;CAAC;CAAS;CAAO;CAAW;CAAU;CAAU;AAG7E,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
package/dist/mastra/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as Sandbox } from "../types-
|
|
2
|
-
import { o as SandboxProvider } from "../provider-
|
|
1
|
+
import { f as Sandbox } from "../types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../provider-BzzkIVmv.mjs";
|
|
3
3
|
import { CopyOptions, FileContent, FileEntry, FilesystemInfo, InstructionsOption, ListOptions, MastraFilesystem, MastraFilesystemOptions, MastraSandbox, MastraSandboxOptions, ProcessHandle, ProcessInfo, ProviderStatus, ReadOptions, RemoveOptions, SandboxInfo, SandboxProcessManager, SpawnProcessOptions, Workspace, WorkspaceConfig, WriteOptions } from "@mastra/core/workspace";
|
|
4
4
|
import { RequestContext } from "@mastra/core/di";
|
|
5
5
|
|
package/dist/metadata.d.mts
CHANGED
package/dist/metadata.mjs
CHANGED
|
@@ -23,7 +23,7 @@ const providers = [
|
|
|
23
23
|
{
|
|
24
24
|
id: "e2b",
|
|
25
25
|
displayName: "E2B",
|
|
26
|
-
officialUrl: "https://e2b.dev",
|
|
26
|
+
officialUrl: "https://e2b.dev/docs",
|
|
27
27
|
packageName: "e2b",
|
|
28
28
|
packageVersion: "2.32.0",
|
|
29
29
|
capabilities: e2bCapabilities,
|
|
@@ -39,7 +39,7 @@ const providers = [
|
|
|
39
39
|
{
|
|
40
40
|
id: "daytona",
|
|
41
41
|
displayName: "Daytona",
|
|
42
|
-
officialUrl: "https://www.daytona.io",
|
|
42
|
+
officialUrl: "https://www.daytona.io/docs/en/sandboxes/",
|
|
43
43
|
packageName: "@daytona/sdk",
|
|
44
44
|
packageVersion: "0.196.0",
|
|
45
45
|
capabilities: daytonaCapabilities,
|
package/dist/metadata.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.mjs","names":["providers: readonly ProviderMetadata[]"],"sources":["../src/metadata.ts"],"sourcesContent":["import {\n daytonaCapabilities,\n e2bCapabilities,\n localCapabilities,\n upstashCapabilities,\n vercelCapabilities,\n} from \"./providers/capabilities\";\nimport type { CapabilityMap, ProviderName } from \"./core/types\";\n\nexport interface LiveTestResult {\n provider: ProviderName;\n testedAt: string;\n adapterVersion: string;\n providerSdkVersion: string;\n passed: number;\n failed: number;\n skipped: number;\n capabilities: Partial<CapabilityMap>;\n}\n\nexport interface ProviderMetadata {\n id: ProviderName;\n displayName: string;\n officialUrl: string;\n packageName: string | null;\n packageVersion: string;\n capabilities: CapabilityMap;\n environmentVariables: readonly string[];\n technicalStatus: \"supported\" | \"experimental\";\n providerReviewed: boolean;\n sponsor: boolean;\n liveTest: LiveTestResult | null;\n portBehavior: string;\n snapshotBehavior: string;\n runtimeLimitations: string;\n}\n\nexport const providers: readonly ProviderMetadata[] = [\n {\n id: \"local\",\n displayName: \"Local\",\n officialUrl: \"https://rivet.dev/docs/agent-os/\",\n packageName: \"@rivet-dev/agentos-core\",\n packageVersion: \"0.2.7\",\n capabilities: localCapabilities,\n environmentVariables: [],\n technicalStatus: \"supported\",\n providerReviewed: false,\n sponsor: false,\n liveTest: null,\n portBehavior:\n \"Returns a private in-process URL. HTTP traffic is bridged through ExposedPort.request().\",\n snapshotBehavior:\n \"Exports the AgentOS virtual filesystem and recreates the VM when restoring it.\",\n runtimeLimitations:\n \"Powered by the beta AgentOS runtime. Requires a supported Node.js host and cannot run arbitrary native Linux binaries.\",\n },\n {\n id: \"e2b\",\n displayName: \"E2B\",\n officialUrl: \"https://e2b.dev\",\n packageName: \"e2b\",\n packageVersion: \"2.32.0\",\n capabilities: e2bCapabilities,\n environmentVariables: [\"E2B_API_KEY\"],\n technicalStatus: \"supported\",\n providerReviewed: false,\n sponsor: false,\n liveTest: null,\n portBehavior:\n \"Returns an E2B host. Restricted traffic uses the native access token only inside request().\",\n snapshotBehavior:\n \"Creates persistent E2B snapshot templates; restore creates a new native sandbox and remains on raw.\",\n runtimeLimitations: \"Requires Node.js 20.18.1 or newer and an E2B account.\",\n },\n {\n id: \"daytona\",\n displayName: \"Daytona\",\n officialUrl: \"https://www.daytona.io
|
|
1
|
+
{"version":3,"file":"metadata.mjs","names":["providers: readonly ProviderMetadata[]"],"sources":["../src/metadata.ts"],"sourcesContent":["import {\n daytonaCapabilities,\n e2bCapabilities,\n localCapabilities,\n upstashCapabilities,\n vercelCapabilities,\n} from \"./providers/capabilities\";\nimport type { CapabilityMap, ProviderName } from \"./core/types\";\n\nexport interface LiveTestResult {\n provider: ProviderName;\n testedAt: string;\n adapterVersion: string;\n providerSdkVersion: string;\n passed: number;\n failed: number;\n skipped: number;\n capabilities: Partial<CapabilityMap>;\n}\n\nexport interface ProviderMetadata {\n id: ProviderName;\n displayName: string;\n officialUrl: string;\n packageName: string | null;\n packageVersion: string;\n capabilities: CapabilityMap;\n environmentVariables: readonly string[];\n technicalStatus: \"supported\" | \"experimental\";\n providerReviewed: boolean;\n sponsor: boolean;\n liveTest: LiveTestResult | null;\n portBehavior: string;\n snapshotBehavior: string;\n runtimeLimitations: string;\n}\n\nexport const providers: readonly ProviderMetadata[] = [\n {\n id: \"local\",\n displayName: \"Local\",\n officialUrl: \"https://rivet.dev/docs/agent-os/\",\n packageName: \"@rivet-dev/agentos-core\",\n packageVersion: \"0.2.7\",\n capabilities: localCapabilities,\n environmentVariables: [],\n technicalStatus: \"supported\",\n providerReviewed: false,\n sponsor: false,\n liveTest: null,\n portBehavior:\n \"Returns a private in-process URL. HTTP traffic is bridged through ExposedPort.request().\",\n snapshotBehavior:\n \"Exports the AgentOS virtual filesystem and recreates the VM when restoring it.\",\n runtimeLimitations:\n \"Powered by the beta AgentOS runtime. Requires a supported Node.js host and cannot run arbitrary native Linux binaries.\",\n },\n {\n id: \"e2b\",\n displayName: \"E2B\",\n officialUrl: \"https://e2b.dev/docs\",\n packageName: \"e2b\",\n packageVersion: \"2.32.0\",\n capabilities: e2bCapabilities,\n environmentVariables: [\"E2B_API_KEY\"],\n technicalStatus: \"supported\",\n providerReviewed: false,\n sponsor: false,\n liveTest: null,\n portBehavior:\n \"Returns an E2B host. Restricted traffic uses the native access token only inside request().\",\n snapshotBehavior:\n \"Creates persistent E2B snapshot templates; restore creates a new native sandbox and remains on raw.\",\n runtimeLimitations: \"Requires Node.js 20.18.1 or newer and an E2B account.\",\n },\n {\n id: \"daytona\",\n displayName: \"Daytona\",\n officialUrl: \"https://www.daytona.io/docs/en/sandboxes/\",\n packageName: \"@daytona/sdk\",\n packageVersion: \"0.196.0\",\n capabilities: daytonaCapabilities,\n environmentVariables: [\"DAYTONA_API_KEY\", \"DAYTONA_API_URL\", \"DAYTONA_TARGET\"],\n technicalStatus: \"supported\",\n providerReviewed: false,\n sponsor: false,\n liveTest: null,\n portBehavior:\n \"Returns public or token-authenticated preview URLs according to the sandbox setting.\",\n snapshotBehavior:\n \"Daytona snapshot and fork operations have provider-specific lifecycle semantics and remain on raw.\",\n runtimeLimitations: \"Some binary and streaming methods require a Node.js-compatible runtime.\",\n },\n {\n id: \"vercel\",\n displayName: \"Vercel Sandbox\",\n officialUrl: \"https://vercel.com/docs/sandbox\",\n packageName: \"@vercel/sandbox\",\n packageVersion: \"2.5.0\",\n capabilities: vercelCapabilities,\n environmentVariables: [\n \"VERCEL_OIDC_TOKEN\",\n \"VERCEL_TOKEN\",\n \"VERCEL_TEAM_ID\",\n \"VERCEL_PROJECT_ID\",\n ],\n technicalStatus: \"supported\",\n providerReviewed: false,\n sponsor: false,\n liveTest: null,\n portBehavior:\n \"Returns a public vercel.run route. Port registration is updated when expose() is called.\",\n snapshotBehavior:\n \"Creating a filesystem snapshot stops the session. Starting from it creates a new sandbox through raw.\",\n runtimeLimitations:\n \"Available runtimes are controlled by Vercel; node24 is the adapter default.\",\n },\n {\n id: \"upstash\",\n displayName: \"Upstash Box\",\n officialUrl: \"https://upstash.com/docs/box\",\n packageName: \"@upstash/box\",\n packageVersion: \"0.5.3\",\n capabilities: upstashCapabilities,\n environmentVariables: [\"UPSTASH_BOX_API_KEY\"],\n technicalStatus: \"supported\",\n providerReviewed: false,\n sponsor: false,\n liveTest: null,\n portBehavior:\n \"Creates a public URL by default, or a bearer-token URL whose credential stays inside request().\",\n snapshotBehavior:\n \"Captures persistent workspace state. Restoring creates a new Box and remains available through raw.\",\n runtimeLimitations:\n \"Durable Debian or Alpine boxes with Node.js, Python, Go, Ruby, or Rust runtimes.\",\n },\n];\n\nexport function getProviderMetadata(id: ProviderName): ProviderMetadata {\n return providers.find((provider) => provider.id === id)!;\n}\n"],"mappings":";;;;;AAqCA,MAAaA,YAAyC;CACpD;EACE,IAAI;EACJ,aAAa;EACb,aAAa;EACb,aAAa;EACb,gBAAgB;EAChB,cAAc;EACd,sBAAsB,EAAE;EACxB,iBAAiB;EACjB,kBAAkB;EAClB,SAAS;EACT,UAAU;EACV,cACE;EACF,kBACE;EACF,oBACE;EACH;CACD;EACE,IAAI;EACJ,aAAa;EACb,aAAa;EACb,aAAa;EACb,gBAAgB;EAChB,cAAc;EACd,sBAAsB,CAAC,cAAc;EACrC,iBAAiB;EACjB,kBAAkB;EAClB,SAAS;EACT,UAAU;EACV,cACE;EACF,kBACE;EACF,oBAAoB;EACrB;CACD;EACE,IAAI;EACJ,aAAa;EACb,aAAa;EACb,aAAa;EACb,gBAAgB;EAChB,cAAc;EACd,sBAAsB;GAAC;GAAmB;GAAmB;GAAiB;EAC9E,iBAAiB;EACjB,kBAAkB;EAClB,SAAS;EACT,UAAU;EACV,cACE;EACF,kBACE;EACF,oBAAoB;EACrB;CACD;EACE,IAAI;EACJ,aAAa;EACb,aAAa;EACb,aAAa;EACb,gBAAgB;EAChB,cAAc;EACd,sBAAsB;GACpB;GACA;GACA;GACA;GACD;EACD,iBAAiB;EACjB,kBAAkB;EAClB,SAAS;EACT,UAAU;EACV,cACE;EACF,kBACE;EACF,oBACE;EACH;CACD;EACE,IAAI;EACJ,aAAa;EACb,aAAa;EACb,aAAa;EACb,gBAAgB;EAChB,cAAc;EACd,sBAAsB,CAAC,sBAAsB;EAC7C,iBAAiB;EACjB,kBAAkB;EAClB,SAAS;EACT,UAAU;EACV,cACE;EACF,kBACE;EACF,oBACE;EACH;CACF;AAED,SAAgB,oBAAoB,IAAoC;AACtE,QAAO,UAAU,MAAM,aAAa,SAAS,OAAO,GAAG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as CommandResult, d as RunOptions, f as Sandbox, g as SandboxProcess, i as CommandInput, n as CapabilityMap, o as ExposedPort, p as SandboxDirectoryEntry, s as FileValue, u as ProviderName, v as SandboxSnapshot } from "./types-
|
|
1
|
+
import { a as CommandResult, d as RunOptions, f as Sandbox, g as SandboxProcess, i as CommandInput, n as CapabilityMap, o as ExposedPort, p as SandboxDirectoryEntry, s as FileValue, u as ProviderName, v as SandboxSnapshot } from "./types-DEi_dfRR.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/core/provider.d.ts
|
|
4
4
|
interface ProviderCreateOptions {
|
|
@@ -88,4 +88,4 @@ interface ManagedSandboxProvider {
|
|
|
88
88
|
}
|
|
89
89
|
//#endregion
|
|
90
90
|
export { SandboxNetworkPolicy as a, ManagedSandboxSession as i, ManagedSandboxProvider as n, SandboxProvider as o, ManagedSandboxResumeOptions as r, ManagedSandboxCreateOptions as t };
|
|
91
|
-
//# sourceMappingURL=provider-
|
|
91
|
+
//# sourceMappingURL=provider-BzzkIVmv.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as SandboxError } from "./errors-Ch9PHKTd.mjs";
|
|
2
|
-
import { t as createSandbox } from "./sandbox-
|
|
2
|
+
import { t as createSandbox } from "./sandbox-rIOcbhtM.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/internal/managed-provider.ts
|
|
5
5
|
/**
|
|
@@ -198,4 +198,4 @@ function unsupportedSnapshots(provider) {
|
|
|
198
198
|
|
|
199
199
|
//#endregion
|
|
200
200
|
export { unsupportedSnapshots as a, unsupported as i, portResult as n, withManagedSessions as o, toUint8Array as r, commandString as t };
|
|
201
|
-
//# sourceMappingURL=provider-utils-
|
|
201
|
+
//# sourceMappingURL=provider-utils-BjOSWNsh.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-utils-DilOYLBO.mjs","names":["managed: ManagedSandboxProvider","ownedTemplate: Promise<TemplateFile[]> | undefined","result: TemplateFile[]"],"sources":["../src/internal/managed-provider.ts","../src/internal/provider-utils.ts"],"sourcesContent":["import { SandboxError } from \"../core/errors\";\nimport type {\n ManagedSandboxProvider,\n ManagedSandboxSession,\n SandboxProvider,\n} from \"../core/provider\";\nimport { createSandbox } from \"../core/sandbox\";\nimport type { Sandbox } from \"../core/types\";\nimport type { SandboxNetworkPolicy } from \"../core/provider\";\n\ntype TemplateFile = { path: string; content: Uint8Array };\n\n/**\n * Shared managed lifecycle for built-in providers. Provider-native implementations\n * can replace this optional surface without changing `createSandbox()`.\n */\nexport function withManagedSessions<TRaw>(\n provider: SandboxProvider<TRaw>,\n configuredPorts: ReadonlyArray<number> = [],\n lifecycle: {\n stop?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n resume?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n destroy?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n setPorts?: (\n sandbox: Sandbox<TRaw>,\n ports: ReadonlyArray<number>,\n signal?: AbortSignal,\n ) => Promise<void>;\n setNetworkPolicy?: (sandbox: Sandbox<TRaw>, policy: SandboxNetworkPolicy) => Promise<void>;\n } = {},\n): SandboxProvider<TRaw> {\n const sessions = new Map<string, ManagedSandboxSession>();\n const templates = new Map<string, Promise<TemplateFile[]>>();\n\n const managed: ManagedSandboxProvider = {\n async create(options) {\n const existing = sessions.get(options.sessionId);\n if (existing) return existing;\n const sandbox = await createSandbox({\n provider,\n cwd: options.cwd,\n env: options.env,\n signal: options.signal,\n });\n const ports = new Set([...configuredPorts, ...(options.ports ?? [])]);\n let ownedTemplate: Promise<TemplateFile[]> | undefined;\n try {\n if (options.identity) {\n let template = templates.get(options.identity);\n if (!template) {\n template = (async () => {\n await options.onFirstCreate?.(sandbox);\n return captureFiles(sandbox, sandbox.cwd);\n })();\n ownedTemplate = template;\n templates.set(options.identity, template);\n await template;\n } else {\n await restoreFiles(sandbox, await template);\n }\n } else {\n await options.onFirstCreate?.(sandbox);\n }\n const session = createManagedSession(\n options.sessionId,\n sandbox,\n ports,\n sessions,\n lifecycle,\n );\n sessions.set(options.sessionId, session);\n return session;\n } catch (error) {\n if (\n options.identity &&\n ownedTemplate &&\n templates.get(options.identity) === ownedTemplate\n ) {\n templates.delete(options.identity);\n }\n try {\n if (lifecycle.destroy) await lifecycle.destroy(sandbox);\n else await sandbox.stop();\n } catch (cleanupError) {\n if (error instanceof Error) {\n Object.defineProperty(error, \"cleanupError\", {\n value: cleanupError,\n enumerable: false,\n });\n }\n }\n throw error;\n }\n },\n async resume(options) {\n const session = sessions.get(options.sessionId);\n if (!session) {\n throw new SandboxError({\n code: \"not_found\",\n provider: provider.id,\n operation: \"managed.resume\",\n message: `Managed sandbox session not found: ${options.sessionId}`,\n });\n }\n await session.resume();\n return session;\n },\n };\n return { ...provider, managed };\n}\n\nfunction createManagedSession<TRaw>(\n id: string,\n sandbox: Sandbox<TRaw>,\n initialPorts: Set<number>,\n sessions: Map<string, ManagedSandboxSession>,\n lifecycle: {\n stop?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n resume?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n destroy?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n setPorts?: (\n sandbox: Sandbox<TRaw>,\n ports: ReadonlyArray<number>,\n signal?: AbortSignal,\n ) => Promise<void>;\n setNetworkPolicy?: (sandbox: Sandbox<TRaw>, policy: SandboxNetworkPolicy) => Promise<void>;\n },\n): ManagedSandboxSession {\n let destroyed = false;\n let stopped = false;\n const assertActive = () => {\n if (destroyed) {\n throw new SandboxError({\n code: \"terminated\",\n provider: sandbox.provider,\n operation: \"managed.session\",\n message: `Managed sandbox session has been destroyed: ${id}`,\n });\n }\n };\n const session: ManagedSandboxSession = {\n id,\n sandbox,\n defaultWorkingDirectory: sandbox.cwd,\n get ports() {\n return [...initialPorts];\n },\n async getPortUrl({ port, protocol }) {\n assertActive();\n if (!initialPorts.has(port)) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: sandbox.provider,\n operation: \"managed.getPortUrl\",\n message: `Port ${port} is not exposed by this session`,\n });\n }\n const exposed = await sandbox.ports.expose(port);\n const url = new URL(exposed.url);\n if (protocol) url.protocol = `${protocol}:`;\n return url.toString().replace(/\\/$/, \"\");\n },\n async stop() {\n assertActive();\n if (stopped) return;\n await lifecycle.stop?.(sandbox);\n stopped = true;\n },\n async resume() {\n assertActive();\n if (!stopped) return;\n await lifecycle.resume?.(sandbox);\n stopped = false;\n },\n async destroy() {\n if (destroyed) return;\n destroyed = true;\n sessions.delete(id);\n if (lifecycle.destroy) await lifecycle.destroy(sandbox);\n else await sandbox.stop();\n },\n ...(lifecycle.setPorts\n ? {\n async setPorts(ports: ReadonlyArray<number>, options?: { signal?: AbortSignal }) {\n assertActive();\n await lifecycle.setPorts!(sandbox, ports, options?.signal);\n initialPorts.clear();\n for (const port of ports) initialPorts.add(port);\n },\n }\n : {}),\n ...(lifecycle.setNetworkPolicy\n ? {\n setNetworkPolicy: (policy: SandboxNetworkPolicy) => {\n assertActive();\n return lifecycle.setNetworkPolicy!(sandbox, policy);\n },\n }\n : {}),\n };\n return session;\n}\n\nasync function captureFiles(sandbox: Sandbox, path: string): Promise<TemplateFile[]> {\n const result: TemplateFile[] = [];\n for (const entry of await sandbox.files.list(path)) {\n if (entry.type === \"directory\") result.push(...(await captureFiles(sandbox, entry.path)));\n else if (entry.type === \"file\")\n result.push({\n path: entry.path,\n content: await sandbox.files.read(entry.path),\n });\n }\n return result;\n}\n\nasync function restoreFiles(sandbox: Sandbox, files: ReadonlyArray<TemplateFile>): Promise<void> {\n await Promise.all(files.map((file) => sandbox.files.write(file.path, file.content)));\n}\n","import { SandboxError } from \"../core/errors\";\nimport type { CommandInput, ExposedPort, FileValue, SandboxSnapshot } from \"../core/types\";\n\nexport async function toUint8Array(value: FileValue): Promise<Uint8Array> {\n if (typeof value === \"string\") return new TextEncoder().encode(value);\n if (value instanceof Uint8Array) return value;\n if (value instanceof ArrayBuffer) return new Uint8Array(value);\n if (value instanceof Blob) return new Uint8Array(await value.arrayBuffer());\n const response = new Response(value);\n return new Uint8Array(await response.arrayBuffer());\n}\n\nexport function commandString(input: CommandInput): string {\n if (typeof input === \"string\") return input;\n return [input.command, ...(input.args ?? [])].map(shellQuote).join(\" \");\n}\n\nfunction shellQuote(value: string): string {\n return `'${value.replaceAll(\"'\", `'\"'\"'`)}'`;\n}\n\nexport function portResult(\n port: number,\n url: string,\n isPublic: boolean,\n authenticated: boolean,\n request?: (path?: string, init?: RequestInit) => Promise<Response>,\n): ExposedPort {\n return {\n port,\n url,\n public: isPublic,\n authenticated,\n request,\n toJSON: () => ({\n port,\n url: authenticated ? redactUrl(url) : url,\n public: isPublic,\n authenticated,\n }),\n };\n}\n\nfunction redactUrl(url: string): string {\n const parsed = new URL(url);\n for (const key of parsed.searchParams.keys()) parsed.searchParams.set(key, \"[REDACTED]\");\n return parsed.toString();\n}\n\nexport function unsupported(provider: string, operation: string): never {\n throw new SandboxError({\n code: \"unsupported\",\n provider,\n operation,\n message: `${provider} does not support normalized ${operation}`,\n });\n}\n\nexport function unsupportedSnapshots(provider: string) {\n return {\n create: async (): Promise<SandboxSnapshot> => unsupported(provider, \"snapshot.create\"),\n delete: async (): Promise<void> => unsupported(provider, \"snapshot.delete\"),\n restore: async (): Promise<void> => unsupported(provider, \"snapshot.restore\"),\n };\n}\n"],"mappings":";;;;;;;;AAgBA,SAAgB,oBACd,UACA,kBAAyC,EAAE,EAC3C,YAUI,EAAE,EACiB;CACvB,MAAM,2BAAW,IAAI,KAAoC;CACzD,MAAM,4BAAY,IAAI,KAAsC;CAE5D,MAAMA,UAAkC;EACtC,MAAM,OAAO,SAAS;GACpB,MAAM,WAAW,SAAS,IAAI,QAAQ,UAAU;AAChD,OAAI,SAAU,QAAO;GACrB,MAA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;GACA,KAAK,gBAAgB,UAAU,IAAI,GAAG;GACtC,QAAQ;GACR;GACD;EACF;;AAGH,SAAS,UAAU,KAAqB;CACtC,MAAM,SAAS,IAAI,IAAI,IAAI;AAC3B,MAAK,MAAM,OAAO,OAAO,aAAa,MAAM,CAAE,QAAO,aAAa,IAAI,KAAK,aAAa;AACxF,QAAO,OAAO,UAAU;;AAG1B,SAAgB,YAAY,UAAkB,WAA0B;AACtE,OAAM,IAAI,aAAa;EACrB,MAAM;EACN;EACA;EACA,SAAS,GAAG,SAAS,+BAA+B;EACrD,CAAC;;AAGJ,SAAgB,qBAAqB,UAAkB;AACrD,QAAO;EACL,QAAQ,YAAsC,YAAY,UAAU,kBAAkB;EACtF,QAAQ,YAA2B,YAAY,UAAU,kBAAkB;EAC3E,SAAS,YAA2B,YAAY,UAAU,mBAAmB;EAC9E"}
|
|
1
|
+
{"version":3,"file":"provider-utils-BjOSWNsh.mjs","names":["managed: ManagedSandboxProvider","ownedTemplate: Promise<TemplateFile[]> | undefined","result: TemplateFile[]"],"sources":["../src/internal/managed-provider.ts","../src/internal/provider-utils.ts"],"sourcesContent":["import { SandboxError } from \"../core/errors\";\nimport type {\n ManagedSandboxProvider,\n ManagedSandboxSession,\n SandboxProvider,\n} from \"../core/provider\";\nimport { createSandbox } from \"../core/sandbox\";\nimport type { Sandbox } from \"../core/types\";\nimport type { SandboxNetworkPolicy } from \"../core/provider\";\n\ntype TemplateFile = { path: string; content: Uint8Array };\n\n/**\n * Shared managed lifecycle for built-in providers. Provider-native implementations\n * can replace this optional surface without changing `createSandbox()`.\n */\nexport function withManagedSessions<TRaw>(\n provider: SandboxProvider<TRaw>,\n configuredPorts: ReadonlyArray<number> = [],\n lifecycle: {\n stop?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n resume?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n destroy?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n setPorts?: (\n sandbox: Sandbox<TRaw>,\n ports: ReadonlyArray<number>,\n signal?: AbortSignal,\n ) => Promise<void>;\n setNetworkPolicy?: (sandbox: Sandbox<TRaw>, policy: SandboxNetworkPolicy) => Promise<void>;\n } = {},\n): SandboxProvider<TRaw> {\n const sessions = new Map<string, ManagedSandboxSession>();\n const templates = new Map<string, Promise<TemplateFile[]>>();\n\n const managed: ManagedSandboxProvider = {\n async create(options) {\n const existing = sessions.get(options.sessionId);\n if (existing) return existing;\n const sandbox = await createSandbox({\n provider,\n cwd: options.cwd,\n env: options.env,\n signal: options.signal,\n });\n const ports = new Set([...configuredPorts, ...(options.ports ?? [])]);\n let ownedTemplate: Promise<TemplateFile[]> | undefined;\n try {\n if (options.identity) {\n let template = templates.get(options.identity);\n if (!template) {\n template = (async () => {\n await options.onFirstCreate?.(sandbox);\n return captureFiles(sandbox, sandbox.cwd);\n })();\n ownedTemplate = template;\n templates.set(options.identity, template);\n await template;\n } else {\n await restoreFiles(sandbox, await template);\n }\n } else {\n await options.onFirstCreate?.(sandbox);\n }\n const session = createManagedSession(\n options.sessionId,\n sandbox,\n ports,\n sessions,\n lifecycle,\n );\n sessions.set(options.sessionId, session);\n return session;\n } catch (error) {\n if (\n options.identity &&\n ownedTemplate &&\n templates.get(options.identity) === ownedTemplate\n ) {\n templates.delete(options.identity);\n }\n try {\n if (lifecycle.destroy) await lifecycle.destroy(sandbox);\n else await sandbox.stop();\n } catch (cleanupError) {\n if (error instanceof Error) {\n Object.defineProperty(error, \"cleanupError\", {\n value: cleanupError,\n enumerable: false,\n });\n }\n }\n throw error;\n }\n },\n async resume(options) {\n const session = sessions.get(options.sessionId);\n if (!session) {\n throw new SandboxError({\n code: \"not_found\",\n provider: provider.id,\n operation: \"managed.resume\",\n message: `Managed sandbox session not found: ${options.sessionId}`,\n });\n }\n await session.resume();\n return session;\n },\n };\n return { ...provider, managed };\n}\n\nfunction createManagedSession<TRaw>(\n id: string,\n sandbox: Sandbox<TRaw>,\n initialPorts: Set<number>,\n sessions: Map<string, ManagedSandboxSession>,\n lifecycle: {\n stop?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n resume?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n destroy?: (sandbox: Sandbox<TRaw>) => Promise<void>;\n setPorts?: (\n sandbox: Sandbox<TRaw>,\n ports: ReadonlyArray<number>,\n signal?: AbortSignal,\n ) => Promise<void>;\n setNetworkPolicy?: (sandbox: Sandbox<TRaw>, policy: SandboxNetworkPolicy) => Promise<void>;\n },\n): ManagedSandboxSession {\n let destroyed = false;\n let stopped = false;\n const assertActive = () => {\n if (destroyed) {\n throw new SandboxError({\n code: \"terminated\",\n provider: sandbox.provider,\n operation: \"managed.session\",\n message: `Managed sandbox session has been destroyed: ${id}`,\n });\n }\n };\n const session: ManagedSandboxSession = {\n id,\n sandbox,\n defaultWorkingDirectory: sandbox.cwd,\n get ports() {\n return [...initialPorts];\n },\n async getPortUrl({ port, protocol }) {\n assertActive();\n if (!initialPorts.has(port)) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: sandbox.provider,\n operation: \"managed.getPortUrl\",\n message: `Port ${port} is not exposed by this session`,\n });\n }\n const exposed = await sandbox.ports.expose(port);\n const url = new URL(exposed.url);\n if (protocol) url.protocol = `${protocol}:`;\n return url.toString().replace(/\\/$/, \"\");\n },\n async stop() {\n assertActive();\n if (stopped) return;\n await lifecycle.stop?.(sandbox);\n stopped = true;\n },\n async resume() {\n assertActive();\n if (!stopped) return;\n await lifecycle.resume?.(sandbox);\n stopped = false;\n },\n async destroy() {\n if (destroyed) return;\n destroyed = true;\n sessions.delete(id);\n if (lifecycle.destroy) await lifecycle.destroy(sandbox);\n else await sandbox.stop();\n },\n ...(lifecycle.setPorts\n ? {\n async setPorts(ports: ReadonlyArray<number>, options?: { signal?: AbortSignal }) {\n assertActive();\n await lifecycle.setPorts!(sandbox, ports, options?.signal);\n initialPorts.clear();\n for (const port of ports) initialPorts.add(port);\n },\n }\n : {}),\n ...(lifecycle.setNetworkPolicy\n ? {\n setNetworkPolicy: (policy: SandboxNetworkPolicy) => {\n assertActive();\n return lifecycle.setNetworkPolicy!(sandbox, policy);\n },\n }\n : {}),\n };\n return session;\n}\n\nasync function captureFiles(sandbox: Sandbox, path: string): Promise<TemplateFile[]> {\n const result: TemplateFile[] = [];\n for (const entry of await sandbox.files.list(path)) {\n if (entry.type === \"directory\") result.push(...(await captureFiles(sandbox, entry.path)));\n else if (entry.type === \"file\")\n result.push({\n path: entry.path,\n content: await sandbox.files.read(entry.path),\n });\n }\n return result;\n}\n\nasync function restoreFiles(sandbox: Sandbox, files: ReadonlyArray<TemplateFile>): Promise<void> {\n await Promise.all(files.map((file) => sandbox.files.write(file.path, file.content)));\n}\n","import { SandboxError } from \"../core/errors\";\nimport type { CommandInput, ExposedPort, FileValue, SandboxSnapshot } from \"../core/types\";\n\nexport async function toUint8Array(value: FileValue): Promise<Uint8Array> {\n if (typeof value === \"string\") return new TextEncoder().encode(value);\n if (value instanceof Uint8Array) return value;\n if (value instanceof ArrayBuffer) return new Uint8Array(value);\n if (value instanceof Blob) return new Uint8Array(await value.arrayBuffer());\n const response = new Response(value);\n return new Uint8Array(await response.arrayBuffer());\n}\n\nexport function commandString(input: CommandInput): string {\n if (typeof input === \"string\") return input;\n return [input.command, ...(input.args ?? [])].map(shellQuote).join(\" \");\n}\n\nfunction shellQuote(value: string): string {\n return `'${value.replaceAll(\"'\", `'\"'\"'`)}'`;\n}\n\nexport function portResult(\n port: number,\n url: string,\n isPublic: boolean,\n authenticated: boolean,\n request?: (path?: string, init?: RequestInit) => Promise<Response>,\n): ExposedPort {\n return {\n port,\n url,\n public: isPublic,\n authenticated,\n request,\n toJSON: () => ({\n port,\n url: authenticated ? redactUrl(url) : url,\n public: isPublic,\n authenticated,\n }),\n };\n}\n\nfunction redactUrl(url: string): string {\n const parsed = new URL(url);\n for (const key of parsed.searchParams.keys()) parsed.searchParams.set(key, \"[REDACTED]\");\n return parsed.toString();\n}\n\nexport function unsupported(provider: string, operation: string): never {\n throw new SandboxError({\n code: \"unsupported\",\n provider,\n operation,\n message: `${provider} does not support normalized ${operation}`,\n });\n}\n\nexport function unsupportedSnapshots(provider: string) {\n return {\n create: async (): Promise<SandboxSnapshot> => unsupported(provider, \"snapshot.create\"),\n delete: async (): Promise<void> => unsupported(provider, \"snapshot.delete\"),\n restore: async (): Promise<void> => unsupported(provider, \"snapshot.restore\"),\n };\n}\n"],"mappings":";;;;;;;;AAgBA,SAAgB,oBACd,UACA,kBAAyC,EAAE,EAC3C,YAUI,EAAE,EACiB;CACvB,MAAM,2BAAW,IAAI,KAAoC;CACzD,MAAM,4BAAY,IAAI,KAAsC;CAE5D,MAAMA,UAAkC;EACtC,MAAM,OAAO,SAAS;GACpB,MAAM,WAAW,SAAS,IAAI,QAAQ,UAAU;AAChD,OAAI,SAAU,QAAO;GACrB,MAAM,UAAU,MAAM,cAAc;IAClC;IACA,KAAK,QAAQ;IACb,KAAK,QAAQ;IACb,QAAQ,QAAQ;IACjB,CAAC;GACF,MAAM,QAAQ,IAAI,IAAI,CAAC,GAAG,iBAAiB,GAAI,QAAQ,SAAS,EAAE,CAAE,CAAC;GACrE,IAAIC;AACJ,OAAI;AACF,QAAI,QAAQ,UAAU;KACpB,IAAI,WAAW,UAAU,IAAI,QAAQ,SAAS;AAC9C,SAAI,CAAC,UAAU;AACb,kBAAY,YAAY;AACtB,aAAM,QAAQ,gBAAgB,QAAQ;AACtC,cAAO,aAAa,SAAS,QAAQ,IAAI;UACvC;AACJ,sBAAgB;AAChB,gBAAU,IAAI,QAAQ,UAAU,SAAS;AACzC,YAAM;WAEN,OAAM,aAAa,SAAS,MAAM,SAAS;UAG7C,OAAM,QAAQ,gBAAgB,QAAQ;IAExC,MAAM,UAAU,qBACd,QAAQ,WACR,SACA,OACA,UACA,UACD;AACD,aAAS,IAAI,QAAQ,WAAW,QAAQ;AACxC,WAAO;YACA,OAAO;AACd,QACE,QAAQ,YACR,iBACA,UAAU,IAAI,QAAQ,SAAS,KAAK,cAEpC,WAAU,OAAO,QAAQ,S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;AAC9D,KAAI,iBAAiB,KAAM,QAAO,IAAI,WAAW,MAAM,MAAM,aAAa,CAAC;CAC3E,MAAM,WAAW,IAAI,SAAS,MAAM;AACpC,QAAO,IAAI,WAAW,MAAM,SAAS,aAAa,CAAC;;AAGrD,SAAgB,cAAc,OAA6B;AACzD,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAO,CAAC,MAAM,SAAS,GAAI,MAAM,QAAQ,EAAE,CAAE,CAAC,IAAI,WAAW,CAAC,KAAK,IAAI;;AAGzE,SAAS,WAAW,OAAuB;AACzC,QAAO,IAAI,MAAM,WAAW,KAAK,QAAQ,CAAC;;AAG5C,SAAgB,WACd,MACA,KACA,UACA,eACA,SACa;AACb,QAAO;EACL;EACA;EACA,QAAQ;EACR;EACA;EACA,eAAe;GACb;GACA,KAAK,gBAAgB,UAAU,IAAI,GAAG;GACtC,QAAQ;GACR;GACD;EACF;;AAGH,SAAS,UAAU,KAAqB;CACtC,MAAM,SAAS,IAAI,IAAI,IAAI;AAC3B,MAAK,MAAM,OAAO,OAAO,aAAa,MAAM,CAAE,QAAO,aAAa,IAAI,KAAK,aAAa;AACxF,QAAO,OAAO,UAAU;;AAG1B,SAAgB,YAAY,UAAkB,WAA0B;AACtE,OAAM,IAAI,aAAa;EACrB,MAAM;EACN;EACA;EACA,SAAS,GAAG,SAAS,+BAA+B;EACrD,CAAC;;AAGJ,SAAgB,qBAAqB,UAAkB;AACrD,QAAO;EACL,QAAQ,YAAsC,YAAY,UAAU,kBAAkB;EACtF,QAAQ,YAA2B,YAAY,UAAU,kBAAkB;EAC3E,SAAS,YAA2B,YAAY,UAAU,mBAAmB;EAC9E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import "../../provider-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import "../../sandbox-
|
|
5
|
-
import { t as agentosCapabilities } from "../../capabilities-
|
|
6
|
-
import { n as AgentOsSandbox, r as agentos, t as AgentOsProviderOptions } from "../../index-
|
|
1
|
+
import "../../types-DEi_dfRR.mjs";
|
|
2
|
+
import "../../provider-BzzkIVmv.mjs";
|
|
3
|
+
import "../../index-BufLdrbp.mjs";
|
|
4
|
+
import "../../sandbox-Dco6z9aB.mjs";
|
|
5
|
+
import { t as agentosCapabilities } from "../../capabilities-DftdOpIu.mjs";
|
|
6
|
+
import { n as AgentOsSandbox, r as agentos, t as AgentOsProviderOptions } from "../../index-Bk6GmoEt.mjs";
|
|
7
7
|
export { AgentOsProviderOptions, AgentOsSandbox, agentos, agentosCapabilities };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "../../errors-Ch9PHKTd.mjs";
|
|
2
2
|
import "../../capabilities-COKpwoFH.mjs";
|
|
3
|
-
import "../../sandbox-
|
|
3
|
+
import "../../sandbox-rIOcbhtM.mjs";
|
|
4
4
|
import { t as agentosCapabilities } from "../../capabilities-CEowrzRM.mjs";
|
|
5
|
-
import "../../provider-utils-
|
|
6
|
-
import { t as agentos } from "../../agentos-
|
|
5
|
+
import "../../provider-utils-BjOSWNsh.mjs";
|
|
6
|
+
import { t as agentos } from "../../agentos-DFJ4TFaY.mjs";
|
|
7
7
|
|
|
8
8
|
export { agentos, agentosCapabilities };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { o as SandboxProvider } from "../../provider-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import "../../sandbox-
|
|
5
|
-
import { n as daytonaCapabilities } from "../../capabilities-
|
|
1
|
+
import "../../types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../../provider-BzzkIVmv.mjs";
|
|
3
|
+
import "../../index-BufLdrbp.mjs";
|
|
4
|
+
import "../../sandbox-Dco6z9aB.mjs";
|
|
5
|
+
import { n as daytonaCapabilities } from "../../capabilities-DftdOpIu.mjs";
|
|
6
6
|
import { Sandbox as DaytonaSandbox } from "@daytona/sdk";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/daytona/index.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { r as normalizeError } from "../../errors-Ch9PHKTd.mjs";
|
|
2
2
|
import "../../capabilities-COKpwoFH.mjs";
|
|
3
|
-
import "../../sandbox-
|
|
3
|
+
import "../../sandbox-rIOcbhtM.mjs";
|
|
4
4
|
import { n as daytonaCapabilities } from "../../capabilities-CEowrzRM.mjs";
|
|
5
|
-
import { a as unsupportedSnapshots, n as portResult, o as withManagedSessions, r as toUint8Array, t as commandString } from "../../provider-utils-
|
|
5
|
+
import { a as unsupportedSnapshots, n as portResult, o as withManagedSessions, r as toUint8Array, t as commandString } from "../../provider-utils-BjOSWNsh.mjs";
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { Daytona } from "@daytona/sdk";
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { o as SandboxProvider } from "../../provider-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import "../../sandbox-
|
|
5
|
-
import { r as e2bCapabilities } from "../../capabilities-
|
|
1
|
+
import "../../types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../../provider-BzzkIVmv.mjs";
|
|
3
|
+
import "../../index-BufLdrbp.mjs";
|
|
4
|
+
import "../../sandbox-Dco6z9aB.mjs";
|
|
5
|
+
import { r as e2bCapabilities } from "../../capabilities-DftdOpIu.mjs";
|
|
6
6
|
import { Sandbox as E2BSandbox } from "e2b";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/e2b/index.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { r as normalizeError } from "../../errors-Ch9PHKTd.mjs";
|
|
2
2
|
import "../../capabilities-COKpwoFH.mjs";
|
|
3
|
-
import "../../sandbox-
|
|
3
|
+
import "../../sandbox-rIOcbhtM.mjs";
|
|
4
4
|
import { r as e2bCapabilities } from "../../capabilities-CEowrzRM.mjs";
|
|
5
|
-
import { i as unsupported, n as portResult, o as withManagedSessions, r as toUint8Array, t as commandString } from "../../provider-utils-
|
|
5
|
+
import { i as unsupported, n as portResult, o as withManagedSessions, r as toUint8Array, t as commandString } from "../../provider-utils-BjOSWNsh.mjs";
|
|
6
6
|
import { Sandbox } from "e2b";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/e2b/index.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { o as SandboxProvider } from "../../provider-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import "../../sandbox-
|
|
5
|
-
import { i as localCapabilities } from "../../capabilities-
|
|
6
|
-
import { n as AgentOsSandbox, t as AgentOsProviderOptions } from "../../index-
|
|
1
|
+
import "../../types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../../provider-BzzkIVmv.mjs";
|
|
3
|
+
import "../../index-BufLdrbp.mjs";
|
|
4
|
+
import "../../sandbox-Dco6z9aB.mjs";
|
|
5
|
+
import { i as localCapabilities } from "../../capabilities-DftdOpIu.mjs";
|
|
6
|
+
import { n as AgentOsSandbox, t as AgentOsProviderOptions } from "../../index-Bk6GmoEt.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/local/index.d.ts
|
|
9
9
|
/** Options passed to the AgentOS VM that powers the Local provider. */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "../../errors-Ch9PHKTd.mjs";
|
|
2
2
|
import "../../capabilities-COKpwoFH.mjs";
|
|
3
|
-
import "../../sandbox-
|
|
3
|
+
import "../../sandbox-rIOcbhtM.mjs";
|
|
4
4
|
import { i as localCapabilities } from "../../capabilities-CEowrzRM.mjs";
|
|
5
|
-
import "../../provider-utils-
|
|
6
|
-
import { t as agentos } from "../../agentos-
|
|
5
|
+
import "../../provider-utils-BjOSWNsh.mjs";
|
|
6
|
+
import { t as agentos } from "../../agentos-DFJ4TFaY.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/local/index.ts
|
|
9
9
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { o as SandboxProvider } from "../../provider-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import "../../sandbox-
|
|
5
|
-
import { a as upstashCapabilities } from "../../capabilities-
|
|
1
|
+
import "../../types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../../provider-BzzkIVmv.mjs";
|
|
3
|
+
import "../../index-BufLdrbp.mjs";
|
|
4
|
+
import "../../sandbox-Dco6z9aB.mjs";
|
|
5
|
+
import { a as upstashCapabilities } from "../../capabilities-DftdOpIu.mjs";
|
|
6
6
|
import { Box, BoxConfig } from "@upstash/box";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/upstash/index.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as SandboxError } from "../../errors-Ch9PHKTd.mjs";
|
|
2
2
|
import "../../capabilities-COKpwoFH.mjs";
|
|
3
|
-
import "../../sandbox-
|
|
3
|
+
import "../../sandbox-rIOcbhtM.mjs";
|
|
4
4
|
import { a as upstashCapabilities } from "../../capabilities-CEowrzRM.mjs";
|
|
5
|
-
import { i as unsupported, n as portResult, o as withManagedSessions, r as toUint8Array, t as commandString } from "../../provider-utils-
|
|
5
|
+
import { i as unsupported, n as portResult, o as withManagedSessions, r as toUint8Array, t as commandString } from "../../provider-utils-BjOSWNsh.mjs";
|
|
6
6
|
import { Box } from "@upstash/box";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/upstash/index.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { o as SandboxProvider } from "../../provider-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import "../../sandbox-
|
|
5
|
-
import { o as vercelCapabilities } from "../../capabilities-
|
|
1
|
+
import "../../types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../../provider-BzzkIVmv.mjs";
|
|
3
|
+
import "../../index-BufLdrbp.mjs";
|
|
4
|
+
import "../../sandbox-Dco6z9aB.mjs";
|
|
5
|
+
import { o as vercelCapabilities } from "../../capabilities-DftdOpIu.mjs";
|
|
6
6
|
import { Sandbox as VercelSandbox } from "@vercel/sandbox";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/vercel/index.d.ts
|
|
@@ -10,6 +10,7 @@ interface VercelBaseOptions {
|
|
|
10
10
|
runtime?: "node24" | "node22" | "node26" | "python3.13" | (string & {});
|
|
11
11
|
name?: string;
|
|
12
12
|
ports?: number[];
|
|
13
|
+
/** Whether the sandbox persists across sessions. Defaults to true. */
|
|
13
14
|
persistent?: boolean;
|
|
14
15
|
}
|
|
15
16
|
type VercelOptions = VercelBaseOptions & ({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { r as normalizeError, t as SandboxError } from "../../errors-Ch9PHKTd.mjs";
|
|
2
2
|
import "../../capabilities-COKpwoFH.mjs";
|
|
3
|
-
import "../../sandbox-
|
|
3
|
+
import "../../sandbox-rIOcbhtM.mjs";
|
|
4
4
|
import { o as vercelCapabilities } from "../../capabilities-CEowrzRM.mjs";
|
|
5
|
-
import { i as unsupported, n as portResult, o as withManagedSessions, r as toUint8Array } from "../../provider-utils-
|
|
5
|
+
import { i as unsupported, n as portResult, o as withManagedSessions, r as toUint8Array } from "../../provider-utils-BjOSWNsh.mjs";
|
|
6
6
|
import { Sandbox, Snapshot } from "@vercel/sandbox";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/vercel/index.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["VercelSandbox","events: ProcessOutputEvent[]","VercelSnapshot"],"sources":["../../../src/providers/vercel/index.ts"],"sourcesContent":["import { Sandbox as VercelSandbox, Snapshot as VercelSnapshot } from \"@vercel/sandbox\";\nimport { normalizeError, SandboxError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type {\n CommandInput,\n ProcessOutputEvent,\n SandboxProcess,\n SandboxSnapshot,\n} from \"../../core/types\";\nimport { portResult, toUint8Array, unsupported } from \"../../internal/provider-utils\";\nimport { vercelCapabilities } from \"../capabilities\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\n\ninterface VercelBaseOptions {\n runtime?: \"node24\" | \"node22\" | \"node26\" | \"python3.13\" | (string & {});\n name?: string;\n ports?: number[];\n persistent?: boolean;\n}\n\nexport type VercelOptions = VercelBaseOptions &\n (\n | { token: string; teamId: string; projectId: string }\n | { token?: never; teamId?: never; projectId?: never }\n );\n\nexport { vercelCapabilities } from \"../capabilities\";\n\nexport function vercel(options: VercelOptions = {}): SandboxProvider<VercelSandbox> {\n return withManagedSessions(\n {\n id: \"vercel\",\n capabilities: vercelCapabilities,\n async create(createOptions) {\n const credentials =\n options.token && options.teamId && options.projectId\n ? {\n token: options.token,\n teamId: options.teamId,\n projectId: options.projectId,\n }\n : {};\n const exposed = new Set(options.ports ?? []);\n const raw = await VercelSandbox.create({\n ...credentials,\n runtime: options.runtime ?? \"node24\",\n name: options.name,\n ports: [...exposed],\n persistent: options.persistent,\n timeout: createOptions.timeout,\n env: { ...createOptions.env },\n signal: createOptions.signal,\n });\n const snapshots = new Map<string, VercelSnapshot>();\n await raw.fs.mkdir(createOptions.cwd, { recursive: true });\n return {\n id: raw.name,\n raw,\n capabilities: vercelCapabilities,\n files: {\n async write(path, value) {\n await raw.fs.writeFile(path, await toUint8Array(value));\n },\n async read(path) {\n return new Uint8Array(await raw.fs.readFile(path));\n },\n async list(path) {\n const entries = await raw.fs.readdir(path, {\n withFileTypes: true,\n });\n return Promise.all(\n entries.map(async (entry) => {\n const entryPath = `${path.replace(/\\/$/, \"\")}/${entry.name}`;\n const info = await raw.fs.lstat(entryPath);\n return {\n name: entry.name,\n path: entryPath,\n type: entry.isFile()\n ? (\"file\" as const)\n : entry.isDirectory()\n ? (\"directory\" as const)\n : entry.isSymbolicLink()\n ? (\"symlink\" as const)\n : (\"unknown\" as const),\n size: entry.isFile() ? info.size : undefined,\n };\n }),\n );\n },\n async mkdir(path) {\n await raw.fs.mkdir(path, { recursive: true });\n },\n async remove(path) {\n await raw.fs.rm(path, { recursive: true, force: true });\n },\n exists: (path) => raw.fs.exists(path),\n },\n async run(command, runOptions) {\n try {\n const result = await runCommand(raw, command, runOptions, false);\n const [stdout, stderr] = await Promise.all([\n result.stdout({ signal: runOptions.signal }),\n result.stderr({ signal: runOptions.signal }),\n ]);\n if (\n runOptions.timeout !== undefined &&\n result.exitCode === 137 &&\n result.durationMs !== undefined &&\n result.durationMs >= runOptions.timeout\n ) {\n throw new SandboxError({\n code: \"timeout\",\n provider: \"vercel\",\n operation: \"process.run\",\n message: `Command timed out after ${runOptions.timeout}ms`,\n });\n }\n return {\n stdout,\n stderr,\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: result.durationMs,\n };\n } catch (error) {\n throw normalizeError(\"vercel\", \"process.run\", error);\n }\n },\n async start(command, runOptions) {\n const handle = await runCommand(raw, command, runOptions, true);\n const events: ProcessOutputEvent[] = [];\n let running = true;\n const stream = handle.logs({ signal: runOptions.signal });\n const completed = handle.wait().then((result) => ({ exitCode: result.exitCode }));\n const process: SandboxProcess = {\n id: handle.cmdId,\n async status() {\n return running ? \"running\" : \"exited\";\n },\n async *output() {\n try {\n for await (const event of stream) {\n const normalized = {\n stream: event.stream,\n data: event.data,\n timestamp: new Date(),\n } satisfies ProcessOutputEvent;\n events.push(normalized);\n yield normalized;\n }\n } finally {\n running = false;\n }\n },\n async write() {\n unsupported(\"vercel\", \"process.stdin\");\n },\n wait: () => completed,\n async kill(signal = \"SIGTERM\") {\n await handle.kill(signal as Parameters<typeof handle.kill>[0]);\n running = false;\n },\n };\n return process;\n },\n async expose(port) {\n if (!exposed.has(port)) {\n exposed.add(port);\n await raw.update({ ports: [...exposed] });\n }\n const url = raw.domain(port);\n return portResult(port, url, true, false);\n },\n snapshots: {\n async create() {\n const snapshot = await raw.snapshot();\n snapshots.set(snapshot.snapshotId, snapshot);\n return {\n id: snapshot.snapshotId,\n mode: \"filesystem\",\n createdAt: snapshot.createdAt,\n } satisfies SandboxSnapshot;\n },\n async delete(snapshot) {\n const id = typeof snapshot === \"string\" ? snapshot : snapshot.id;\n const native =\n snapshots.get(id) ?? (await VercelSnapshot.get({ snapshotId: id, ...credentials }));\n await native.delete();\n snapshots.delete(id);\n },\n async restore() {\n unsupported(\"vercel\", \"snapshot.restore\");\n },\n },\n async stop() {\n if (raw.status !== \"stopped\") await raw.stop();\n },\n };\n },\n },\n options.ports,\n {\n stop: async (sandbox) => {\n await sandbox.raw.stop();\n },\n destroy: (sandbox) => sandbox.raw.delete(),\n setPorts: (sandbox, ports, signal) => sandbox.raw.update({ ports: [...ports] }, { signal }),\n setNetworkPolicy: (sandbox, policy) =>\n sandbox.raw.update({\n networkPolicy:\n policy.mode === \"allow-all\" || policy.mode === \"deny-all\"\n ? policy.mode\n : policy.mode === \"native\"\n ? (policy.value as import(\"@vercel/sandbox\").NetworkPolicy)\n : { allow: [...(policy.allowedHosts ?? [])] },\n }),\n },\n );\n}\n\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: false,\n): Promise<import(\"@vercel/sandbox\").CommandFinished>;\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: true,\n): Promise<import(\"@vercel/sandbox\").Command>;\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: boolean,\n) {\n const command = typeof input === \"string\" ? { command: \"/bin/sh\", args: [\"-lc\", input] } : input;\n return raw.runCommand({\n cmd: command.command,\n args: [...(command.args ?? [])],\n cwd: options.cwd,\n env: { ...options.env },\n signal: options.signal,\n timeoutMs: options.timeout,\n detached,\n });\n}\n\nexport type { VercelSandbox };\n"],"mappings":";;;;;;;;AA4BA,SAAgB,OAAO,UAAyB,EAAE,EAAkC;AAClF,QAAO,oBACL;EACE,IAAI;EACJ,cAAc;EACd,M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S,WAC1B,QAAQ,IAAI,OAAO,EACjB,eACE,OAAO,SAAS,eAAe,OAAO,SAAS,aAC3C,OAAO,OACP,OAAO,SAAS,WACb,OAAO,QACR,EAAE,OAAO,CAAC,GAAI,OAAO,gBAAgB,EAAE,CAAE,EAAE,EACpD,CAAC;EACL,CACF;;AAeH,eAAe,WACb,KACA,OACA,SACA,UACA;CACA,MAAM,UAAU,OAAO,UAAU,WAAW;EAAE,SAAS;EAAW,MAAM,CAAC,OAAO,MAAM;EAAE,GAAG;AAC3F,QAAO,IAAI,WAAW;EACpB,KAAK,QAAQ;EACb,MAAM,CAAC,GAAI,QAAQ,QAAQ,EAAE,CAAE;EAC/B,KAAK,QAAQ;EACb,KAAK,EAAE,GAAG,QAAQ,KAAK;EACvB,QAAQ,QAAQ;EAChB,WAAW,QAAQ;EACnB;EACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["VercelSandbox","events: ProcessOutputEvent[]","VercelSnapshot"],"sources":["../../../src/providers/vercel/index.ts"],"sourcesContent":["import { Sandbox as VercelSandbox, Snapshot as VercelSnapshot } from \"@vercel/sandbox\";\nimport { normalizeError, SandboxError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type {\n CommandInput,\n ProcessOutputEvent,\n SandboxProcess,\n SandboxSnapshot,\n} from \"../../core/types\";\nimport { portResult, toUint8Array, unsupported } from \"../../internal/provider-utils\";\nimport { vercelCapabilities } from \"../capabilities\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\n\ninterface VercelBaseOptions {\n runtime?: \"node24\" | \"node22\" | \"node26\" | \"python3.13\" | (string & {});\n name?: string;\n ports?: number[];\n /** Whether the sandbox persists across sessions. Defaults to true. */\n persistent?: boolean;\n}\n\nexport type VercelOptions = VercelBaseOptions &\n (\n | { token: string; teamId: string; projectId: string }\n | { token?: never; teamId?: never; projectId?: never }\n );\n\nexport { vercelCapabilities } from \"../capabilities\";\n\nexport function vercel(options: VercelOptions = {}): SandboxProvider<VercelSandbox> {\n return withManagedSessions(\n {\n id: \"vercel\",\n capabilities: vercelCapabilities,\n async create(createOptions) {\n const credentials =\n options.token && options.teamId && options.projectId\n ? {\n token: options.token,\n teamId: options.teamId,\n projectId: options.projectId,\n }\n : {};\n const exposed = new Set(options.ports ?? []);\n const raw = await VercelSandbox.create({\n ...credentials,\n runtime: options.runtime ?? \"node24\",\n name: options.name,\n ports: [...exposed],\n persistent: options.persistent,\n timeout: createOptions.timeout,\n env: { ...createOptions.env },\n signal: createOptions.signal,\n });\n const snapshots = new Map<string, VercelSnapshot>();\n await raw.fs.mkdir(createOptions.cwd, { recursive: true });\n return {\n id: raw.name,\n raw,\n capabilities: vercelCapabilities,\n files: {\n async write(path, value) {\n await raw.fs.writeFile(path, await toUint8Array(value));\n },\n async read(path) {\n return new Uint8Array(await raw.fs.readFile(path));\n },\n async list(path) {\n const entries = await raw.fs.readdir(path, {\n withFileTypes: true,\n });\n return Promise.all(\n entries.map(async (entry) => {\n const entryPath = `${path.replace(/\\/$/, \"\")}/${entry.name}`;\n const info = await raw.fs.lstat(entryPath);\n return {\n name: entry.name,\n path: entryPath,\n type: entry.isFile()\n ? (\"file\" as const)\n : entry.isDirectory()\n ? (\"directory\" as const)\n : entry.isSymbolicLink()\n ? (\"symlink\" as const)\n : (\"unknown\" as const),\n size: entry.isFile() ? info.size : undefined,\n };\n }),\n );\n },\n async mkdir(path) {\n await raw.fs.mkdir(path, { recursive: true });\n },\n async remove(path) {\n await raw.fs.rm(path, { recursive: true, force: true });\n },\n exists: (path) => raw.fs.exists(path),\n },\n async run(command, runOptions) {\n try {\n const result = await runCommand(raw, command, runOptions, false);\n const [stdout, stderr] = await Promise.all([\n result.stdout({ signal: runOptions.signal }),\n result.stderr({ signal: runOptions.signal }),\n ]);\n if (\n runOptions.timeout !== undefined &&\n result.exitCode === 137 &&\n result.durationMs !== undefined &&\n result.durationMs >= runOptions.timeout\n ) {\n throw new SandboxError({\n code: \"timeout\",\n provider: \"vercel\",\n operation: \"process.run\",\n message: `Command timed out after ${runOptions.timeout}ms`,\n });\n }\n return {\n stdout,\n stderr,\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: result.durationMs,\n };\n } catch (error) {\n throw normalizeError(\"vercel\", \"process.run\", error);\n }\n },\n async start(command, runOptions) {\n const handle = await runCommand(raw, command, runOptions, true);\n const events: ProcessOutputEvent[] = [];\n let running = true;\n const stream = handle.logs({ signal: runOptions.signal });\n const completed = handle.wait().then((result) => ({ exitCode: result.exitCode }));\n const process: SandboxProcess = {\n id: handle.cmdId,\n async status() {\n return running ? \"running\" : \"exited\";\n },\n async *output() {\n try {\n for await (const event of stream) {\n const normalized = {\n stream: event.stream,\n data: event.data,\n timestamp: new Date(),\n } satisfies ProcessOutputEvent;\n events.push(normalized);\n yield normalized;\n }\n } finally {\n running = false;\n }\n },\n async write() {\n unsupported(\"vercel\", \"process.stdin\");\n },\n wait: () => completed,\n async kill(signal = \"SIGTERM\") {\n await handle.kill(signal as Parameters<typeof handle.kill>[0]);\n running = false;\n },\n };\n return process;\n },\n async expose(port) {\n if (!exposed.has(port)) {\n exposed.add(port);\n await raw.update({ ports: [...exposed] });\n }\n const url = raw.domain(port);\n return portResult(port, url, true, false);\n },\n snapshots: {\n async create() {\n const snapshot = await raw.snapshot();\n snapshots.set(snapshot.snapshotId, snapshot);\n return {\n id: snapshot.snapshotId,\n mode: \"filesystem\",\n createdAt: snapshot.createdAt,\n } satisfies SandboxSnapshot;\n },\n async delete(snapshot) {\n const id = typeof snapshot === \"string\" ? snapshot : snapshot.id;\n const native =\n snapshots.get(id) ?? (await VercelSnapshot.get({ snapshotId: id, ...credentials }));\n await native.delete();\n snapshots.delete(id);\n },\n async restore() {\n unsupported(\"vercel\", \"snapshot.restore\");\n },\n },\n async stop() {\n if (raw.status !== \"stopped\") await raw.stop();\n },\n };\n },\n },\n options.ports,\n {\n stop: async (sandbox) => {\n await sandbox.raw.stop();\n },\n destroy: (sandbox) => sandbox.raw.delete(),\n setPorts: (sandbox, ports, signal) => sandbox.raw.update({ ports: [...ports] }, { signal }),\n setNetworkPolicy: (sandbox, policy) =>\n sandbox.raw.update({\n networkPolicy:\n policy.mode === \"allow-all\" || policy.mode === \"deny-all\"\n ? policy.mode\n : policy.mode === \"native\"\n ? (policy.value as import(\"@vercel/sandbox\").NetworkPolicy)\n : { allow: [...(policy.allowedHosts ?? [])] },\n }),\n },\n );\n}\n\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: false,\n): Promise<import(\"@vercel/sandbox\").CommandFinished>;\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: true,\n): Promise<import(\"@vercel/sandbox\").Command>;\nasync function runCommand(\n raw: VercelSandbox,\n input: CommandInput,\n options: import(\"../../core/types\").RunOptions,\n detached: boolean,\n) {\n const command = typeof input === \"string\" ? { command: \"/bin/sh\", args: [\"-lc\", input] } : input;\n return raw.runCommand({\n cmd: command.command,\n args: [...(command.args ?? [])],\n cwd: options.cwd,\n env: { ...options.env },\n signal: options.signal,\n timeoutMs: options.timeout,\n detached,\n });\n}\n\nexport type { VercelSandbox };\n"],"mappings":";;;;;;;;AA6BA,SAAgB,OAAO,UAAyB,EAAE,EAAkC;AAClF,QAAO,oBACL;EACE,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;GAC1B,MAAM,cACJ,QAAQ,SAAS,QAAQ,UAAU,QAAQ,YACvC;IACE,OAAO,QAAQ;IACf,QAAQ,QAAQ;IAChB,WAAW,QAAQ;IACpB,GACD,EAAE;GACR,MAAM,UAAU,IAAI,IAAI,QAAQ,SAAS,EAAE,CAAC;GAC5C,MAAM,MAAM,MAAMA,QAAc,OAAO;IACrC,GAAG;IACH,SAAS,QAAQ,WAAW;IAC5B,MAAM,QAAQ;IACd,OAAO,CAAC,GAAG,QAAQ;IACnB,YAAY,QAAQ;IACpB,SAAS,cAAc;IACvB,KA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,CAAC,GAAI,QAAQ,QAAQ,EAAE,CAAE;EAC/B,KAAK,QAAQ;EACb,KAAK,EAAE,GAAG,QAAQ,KAAK;EACvB,QAAQ,QAAQ;EAChB,WAAW,QAAQ;EACnB;EACD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as Sandbox } from "./types-
|
|
2
|
-
import { o as SandboxProvider } from "./provider-
|
|
1
|
+
import { f as Sandbox } from "./types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "./provider-BzzkIVmv.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/core/sandbox.d.ts
|
|
5
5
|
interface CreateSandboxOptions<TProvider extends SandboxProvider<unknown>> {
|
|
@@ -10,8 +10,17 @@ interface CreateSandboxOptions<TProvider extends SandboxProvider<unknown>> {
|
|
|
10
10
|
signal?: AbortSignal;
|
|
11
11
|
}
|
|
12
12
|
type RawOf<TProvider> = TProvider extends SandboxProvider<infer TRaw> ? TRaw : never;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a normalized sandbox. Prefer `await using` so cleanup runs when the scope exits.
|
|
15
|
+
*/
|
|
13
16
|
declare function createSandbox<TProvider extends SandboxProvider<unknown>>(options: CreateSandboxOptions<TProvider>): Promise<Sandbox<RawOf<TProvider>>>;
|
|
17
|
+
/**
|
|
18
|
+
* Runs a callback with a sandbox and stops it afterward.
|
|
19
|
+
*
|
|
20
|
+
* Prefer `await using` with `createSandbox()` in new code. This helper remains useful for
|
|
21
|
+
* callback-style code and runtimes that do not parse explicit resource management syntax.
|
|
22
|
+
*/
|
|
14
23
|
declare function withSandbox<TProvider extends SandboxProvider<unknown>, TResult>(options: CreateSandboxOptions<TProvider>, callback: (sandbox: Sandbox<RawOf<TProvider>>) => TResult | Promise<TResult>): Promise<TResult>;
|
|
15
24
|
//#endregion
|
|
16
25
|
export { createSandbox as n, withSandbox as r, CreateSandboxOptions as t };
|
|
17
|
-
//# sourceMappingURL=sandbox-
|
|
26
|
+
//# sourceMappingURL=sandbox-Dco6z9aB.d.mts.map
|
|
@@ -20,6 +20,9 @@ function validatePath(cwd, value) {
|
|
|
20
20
|
if (value.startsWith("/")) return value.replace(/\/{2,}/g, "/");
|
|
21
21
|
return `${cwd}/${value}`.replace(/\/{2,}/g, "/");
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a normalized sandbox. Prefer `await using` so cleanup runs when the scope exits.
|
|
25
|
+
*/
|
|
23
26
|
async function createSandbox(options) {
|
|
24
27
|
const cwd = validateCwd(options.cwd ?? "/workspace");
|
|
25
28
|
const env = options.env ?? {};
|
|
@@ -69,7 +72,8 @@ async function createSandbox(options) {
|
|
|
69
72
|
restore: (snapshot) => call("snapshot.restore", () => runtime.snapshots.restore(snapshot))
|
|
70
73
|
},
|
|
71
74
|
run: (command, runOptions = {}) => call("process.run", () => runtime.run(command, normalizeRunOptions(cwd, runOptions))),
|
|
72
|
-
stop
|
|
75
|
+
stop,
|
|
76
|
+
[Symbol.asyncDispose]: stop
|
|
73
77
|
};
|
|
74
78
|
}
|
|
75
79
|
function normalizeRunOptions(cwd, options) {
|
|
@@ -78,6 +82,12 @@ function normalizeRunOptions(cwd, options) {
|
|
|
78
82
|
cwd: options.cwd ? validatePath(cwd, options.cwd) : cwd
|
|
79
83
|
};
|
|
80
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Runs a callback with a sandbox and stops it afterward.
|
|
87
|
+
*
|
|
88
|
+
* Prefer `await using` with `createSandbox()` in new code. This helper remains useful for
|
|
89
|
+
* callback-style code and runtimes that do not parse explicit resource management syntax.
|
|
90
|
+
*/
|
|
81
91
|
async function withSandbox(options, callback) {
|
|
82
92
|
const sandbox = await createSandbox(options);
|
|
83
93
|
try {
|
|
@@ -99,4 +109,4 @@ async function withSandbox(options, callback) {
|
|
|
99
109
|
|
|
100
110
|
//#endregion
|
|
101
111
|
export { withSandbox as n, createSandbox as t };
|
|
102
|
-
//# sourceMappingURL=sandbox-
|
|
112
|
+
//# sourceMappingURL=sandbox-rIOcbhtM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-rIOcbhtM.mjs","names":["stopPromise: Promise<void> | undefined"],"sources":["../src/core/sandbox.ts"],"sourcesContent":["import { normalizeError, SandboxError } from \"./errors\";\nimport type { SandboxProvider } from \"./provider\";\nimport type { FileValue, RunOptions, Sandbox } from \"./types\";\n\nexport interface CreateSandboxOptions<TProvider extends SandboxProvider<unknown>> {\n provider: TProvider;\n cwd?: string;\n env?: Readonly<Record<string, string>>;\n timeout?: number;\n signal?: AbortSignal;\n}\n\ntype RawOf<TProvider> = TProvider extends SandboxProvider<infer TRaw> ? TRaw : never;\n\nfunction validateCwd(cwd: string): string {\n if (!cwd.startsWith(\"/\") || cwd.includes(\"\\0\")) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"core\",\n operation: \"create\",\n message: \"cwd must be an absolute path\",\n });\n }\n return cwd.replace(/\\/$/, \"\") || \"/\";\n}\n\nfunction validatePath(cwd: string, value: string): string {\n if (!value || value.includes(\"\\0\") || value.split(\"/\").includes(\"..\")) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"core\",\n operation: \"path\",\n message: `Invalid sandbox path: ${value}`,\n });\n }\n if (value.startsWith(\"/\")) return value.replace(/\\/{2,}/g, \"/\");\n return `${cwd}/${value}`.replace(/\\/{2,}/g, \"/\");\n}\n\n/**\n * Creates a normalized sandbox. Prefer `await using` so cleanup runs when the scope exits.\n */\nexport async function createSandbox<TProvider extends SandboxProvider<unknown>>(\n options: CreateSandboxOptions<TProvider>,\n): Promise<Sandbox<RawOf<TProvider>>> {\n const cwd = validateCwd(options.cwd ?? \"/workspace\");\n const env = options.env ?? {};\n let runtime;\n try {\n runtime = await options.provider.create({\n cwd,\n env,\n timeout: options.timeout,\n signal: options.signal,\n });\n } catch (error) {\n throw normalizeError(options.provider.id, \"sandbox.create\", error);\n }\n let stopPromise: Promise<void> | undefined;\n const stop = async () => {\n stopPromise ??= call(\"sandbox.stop\", () => runtime.stop());\n return stopPromise;\n };\n const call = async <T>(operation: string, fn: () => Promise<T>): Promise<T> => {\n try {\n return await fn();\n } catch (error) {\n throw normalizeError(options.provider.id, operation, error);\n }\n };\n return {\n id: runtime.id,\n provider: options.provider.id,\n cwd,\n capabilities: runtime.capabilities,\n raw: runtime.raw as RawOf<TProvider>,\n files: {\n write: async (path: string, value: FileValue) =>\n call(\"files.write\", () => runtime.files.write(validatePath(cwd, path), value)),\n read: async (path: string) =>\n call(\"files.read\", () => runtime.files.read(validatePath(cwd, path))),\n text: async (path: string) =>\n new TextDecoder().decode(\n await call(\"files.read\", () => runtime.files.read(validatePath(cwd, path))),\n ),\n list: async (path = \".\") =>\n call(\"files.list\", () => runtime.files.list(path === \".\" ? cwd : validatePath(cwd, path))),\n mkdir: async (path: string) =>\n call(\"files.mkdir\", () => runtime.files.mkdir(validatePath(cwd, path))),\n remove: async (path: string) =>\n call(\"files.remove\", () => runtime.files.remove(validatePath(cwd, path))),\n exists: async (path: string) =>\n call(\"files.exists\", () => runtime.files.exists(validatePath(cwd, path))),\n },\n processes: {\n start: (command, runOptions = {}) =>\n call(\"process.start\", () => runtime.start(command, normalizeRunOptions(cwd, runOptions))),\n },\n ports: { expose: (port) => call(\"ports.expose\", () => runtime.expose(port)) },\n snapshots: {\n create: (snapshotOptions) =>\n call(\"snapshot.create\", () => runtime.snapshots.create(snapshotOptions)),\n delete: (snapshot) => call(\"snapshot.delete\", () => runtime.snapshots.delete(snapshot)),\n restore: (snapshot) => call(\"snapshot.restore\", () => runtime.snapshots.restore(snapshot)),\n },\n run: (command, runOptions = {}) =>\n call(\"process.run\", () => runtime.run(command, normalizeRunOptions(cwd, runOptions))),\n stop,\n [Symbol.asyncDispose]: stop,\n };\n}\n\nfunction normalizeRunOptions(cwd: string, options: RunOptions): RunOptions {\n return { ...options, cwd: options.cwd ? validatePath(cwd, options.cwd) : cwd };\n}\n\n/**\n * Runs a callback with a sandbox and stops it afterward.\n *\n * Prefer `await using` with `createSandbox()` in new code. This helper remains useful for\n * callback-style code and runtimes that do not parse explicit resource management syntax.\n */\nexport async function withSandbox<TProvider extends SandboxProvider<unknown>, TResult>(\n options: CreateSandboxOptions<TProvider>,\n callback: (sandbox: Sandbox<RawOf<TProvider>>) => TResult | Promise<TResult>,\n): Promise<TResult> {\n const sandbox = await createSandbox(options);\n try {\n const result = await callback(sandbox);\n await sandbox.stop();\n return result;\n } catch (error) {\n try {\n await sandbox.stop();\n } catch (cleanupError) {\n if (error instanceof Error) {\n Object.defineProperty(error, \"cleanupError\", { value: cleanupError, enumerable: false });\n }\n }\n throw error;\n }\n}\n"],"mappings":";;;AAcA,SAAS,YAAY,KAAqB;AACxC,KAAI,CAAC,IAAI,WAAW,IAAI,IAAI,IAAI,SAAS,KAAK,CAC5C,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU;EACV,WAAW;EACX,SAAS;EACV,CAAC;AAEJ,QAAO,IAAI,QAAQ,OAAO,GAAG,IAAI;;AAGnC,SAAS,aAAa,KAAa,OAAuB;AACxD,KAAI,CAAC,SAAS,MAAM,SAAS,KAAK,IAAI,MAAM,MAAM,IAAI,CAAC,SAAS,KAAK,CACnE,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU;EACV,WAAW;EACX,SAAS,yBAAyB;EACnC,CAAC;AAEJ,KAAI,MAAM,WAAW,IAAI,CAAE,QAAO,MAAM,QAAQ,WAAW,IAAI;AAC/D,QAAO,GAAG,IAAI,GAAG,QAAQ,QAAQ,WAAW,IAAI;;;;;AAMlD,eAAsB,cACpB,SACoC;CACpC,MAAM,MAAM,YAAY,QAAQ,OAAO,aAAa;CACpD,MAAM,MAAM,QAAQ,OAAO,EAAE;CAC7B,IAAI;AACJ,KAAI;AACF,YAAU,MAAM,QAAQ,SAAS,OAAO;GACtC;GACA;GACA,SAAS,QAAQ;GACjB,QAAQ,QAAQ;GACjB,CAAC;UACK,OAAO;AACd,QAAM,eAAe,QAAQ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AsB,QAAQ,OAAO,KAAK,CAAC,EAAE;EAC7E,WAAW;GACT,SAAS,oBACP,KAAK,yBAAyB,QAAQ,UAAU,OAAO,gBAAgB,CAAC;GAC1E,SAAS,aAAa,KAAK,yBAAyB,QAAQ,UAAU,OAAO,SAAS,CAAC;GACvF,UAAU,aAAa,KAAK,0BAA0B,QAAQ,UAAU,QAAQ,SAAS,CAAC;GAC3F;EACD,MAAM,SAAS,aAAa,EAAE,KAC5B,KAAK,qBAAqB,QAAQ,IAAI,SAAS,oBAAoB,KAAK,WAAW,CAAC,CAAC;EACvF;GACC,OAAO,eAAe;EACxB;;AAGH,SAAS,oBAAoB,KAAa,SAAiC;AACzE,QAAO;EAAE,GAAG;EAAS,KAAK,QAAQ,MAAM,aAAa,KAAK,QAAQ,IAAI,GAAG;EAAK;;;;;;;;AAShF,eAAsB,YACpB,SACA,UACkB;CAClB,MAAM,UAAU,MAAM,cAAc,QAAQ;AAC5C,KAAI;EACF,MAAM,SAAS,MAAM,SAAS,QAAQ;AACtC,QAAM,QAAQ,MAAM;AACpB,SAAO;UACA,OAAO;AACd,MAAI;AACF,SAAM,QAAQ,MAAM;WACb,cAAc;AACrB,OAAI,iBAAiB,MACnB,QAAO,eAAe,OAAO,gBAAgB;IAAE,OAAO;IAAc,YAAY;IAAO,CAAC;;AAG5F,QAAM"}
|
package/dist/testing/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { o as SandboxProvider } from "../provider-
|
|
3
|
-
import { t as CreateSandboxOptions } from "../sandbox-
|
|
1
|
+
import "../types-DEi_dfRR.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../provider-BzzkIVmv.mjs";
|
|
3
|
+
import { t as CreateSandboxOptions } from "../sandbox-Dco6z9aB.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/testing/conformance.d.ts
|
|
6
6
|
declare const conformanceCases: readonly ["create and stop", "idempotent stop", "text files", "binary files", "directories", "relative paths", "invalid paths", "successful command", "stdout", "stderr", "nonzero exit", "timeout", "background process", "stdin", "ports", "snapshot create", "snapshot delete", "snapshot restore", "cleanup after failure"];
|
package/dist/testing/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../errors-Ch9PHKTd.mjs";
|
|
2
2
|
import { i as supports } from "../capabilities-COKpwoFH.mjs";
|
|
3
|
-
import { t as createSandbox } from "../sandbox-
|
|
3
|
+
import { t as createSandbox } from "../sandbox-rIOcbhtM.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/testing/conformance.ts
|
|
6
6
|
const conformanceCases = [
|
|
@@ -93,8 +93,11 @@ interface Sandbox<TRaw = unknown> {
|
|
|
93
93
|
readonly ports: SandboxPorts;
|
|
94
94
|
readonly snapshots: SandboxSnapshots;
|
|
95
95
|
run(command: CommandInput, options?: RunOptions): Promise<CommandResult>;
|
|
96
|
+
/** Stops the provider runtime. Repeated calls share the same cleanup operation. */
|
|
96
97
|
stop(): Promise<void>;
|
|
98
|
+
/** Stops the sandbox when an `await using` scope exits. */
|
|
99
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
97
100
|
}
|
|
98
101
|
//#endregion
|
|
99
102
|
export { SandboxProcesses as _, CommandResult as a, capabilityNames as b, ProcessOutputEvent as c, RunOptions as d, Sandbox as f, SandboxProcess as g, SandboxPorts as h, CommandInput as i, ProcessStatus as l, SandboxFiles as m, CapabilityMap as n, ExposedPort as o, SandboxDirectoryEntry as p, CapabilityMode as r, FileValue as s, Capability as t, ProviderName as u, SandboxSnapshot as v, providerNames as x, SandboxSnapshots as y };
|
|
100
|
-
//# sourceMappingURL=types-
|
|
103
|
+
//# sourceMappingURL=types-DEi_dfRR.d.mts.map
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-BwyHcB_C.mjs","names":["stopPromise: Promise<void> | undefined"],"sources":["../src/core/sandbox.ts"],"sourcesContent":["import { normalizeError, SandboxError } from \"./errors\";\nimport type { SandboxProvider } from \"./provider\";\nimport type { FileValue, RunOptions, Sandbox } from \"./types\";\n\nexport interface CreateSandboxOptions<TProvider extends SandboxProvider<unknown>> {\n provider: TProvider;\n cwd?: string;\n env?: Readonly<Record<string, string>>;\n timeout?: number;\n signal?: AbortSignal;\n}\n\ntype RawOf<TProvider> = TProvider extends SandboxProvider<infer TRaw> ? TRaw : never;\n\nfunction validateCwd(cwd: string): string {\n if (!cwd.startsWith(\"/\") || cwd.includes(\"\\0\")) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"core\",\n operation: \"create\",\n message: \"cwd must be an absolute path\",\n });\n }\n return cwd.replace(/\\/$/, \"\") || \"/\";\n}\n\nfunction validatePath(cwd: string, value: string): string {\n if (!value || value.includes(\"\\0\") || value.split(\"/\").includes(\"..\")) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"core\",\n operation: \"path\",\n message: `Invalid sandbox path: ${value}`,\n });\n }\n if (value.startsWith(\"/\")) return value.replace(/\\/{2,}/g, \"/\");\n return `${cwd}/${value}`.replace(/\\/{2,}/g, \"/\");\n}\n\nexport async function createSandbox<TProvider extends SandboxProvider<unknown>>(\n options: CreateSandboxOptions<TProvider>,\n): Promise<Sandbox<RawOf<TProvider>>> {\n const cwd = validateCwd(options.cwd ?? \"/workspace\");\n const env = options.env ?? {};\n let runtime;\n try {\n runtime = await options.provider.create({\n cwd,\n env,\n timeout: options.timeout,\n signal: options.signal,\n });\n } catch (error) {\n throw normalizeError(options.provider.id, \"sandbox.create\", error);\n }\n let stopPromise: Promise<void> | undefined;\n const stop = async () => {\n stopPromise ??= call(\"sandbox.stop\", () => runtime.stop());\n return stopPromise;\n };\n const call = async <T>(operation: string, fn: () => Promise<T>): Promise<T> => {\n try {\n return await fn();\n } catch (error) {\n throw normalizeError(options.provider.id, operation, error);\n }\n };\n return {\n id: runtime.id,\n provider: options.provider.id,\n cwd,\n capabilities: runtime.capabilities,\n raw: runtime.raw as RawOf<TProvider>,\n files: {\n write: async (path: string, value: FileValue) =>\n call(\"files.write\", () => runtime.files.write(validatePath(cwd, path), value)),\n read: async (path: string) =>\n call(\"files.read\", () => runtime.files.read(validatePath(cwd, path))),\n text: async (path: string) =>\n new TextDecoder().decode(\n await call(\"files.read\", () => runtime.files.read(validatePath(cwd, path))),\n ),\n list: async (path = \".\") =>\n call(\"files.list\", () => runtime.files.list(path === \".\" ? cwd : validatePath(cwd, path))),\n mkdir: async (path: string) =>\n call(\"files.mkdir\", () => runtime.files.mkdir(validatePath(cwd, path))),\n remove: async (path: string) =>\n call(\"files.remove\", () => runtime.files.remove(validatePath(cwd, path))),\n exists: async (path: string) =>\n call(\"files.exists\", () => runtime.files.exists(validatePath(cwd, path))),\n },\n processes: {\n start: (command, runOptions = {}) =>\n call(\"process.start\", () => runtime.start(command, normalizeRunOptions(cwd, runOptions))),\n },\n ports: { expose: (port) => call(\"ports.expose\", () => runtime.expose(port)) },\n snapshots: {\n create: (snapshotOptions) =>\n call(\"snapshot.create\", () => runtime.snapshots.create(snapshotOptions)),\n delete: (snapshot) => call(\"snapshot.delete\", () => runtime.snapshots.delete(snapshot)),\n restore: (snapshot) => call(\"snapshot.restore\", () => runtime.snapshots.restore(snapshot)),\n },\n run: (command, runOptions = {}) =>\n call(\"process.run\", () => runtime.run(command, normalizeRunOptions(cwd, runOptions))),\n stop,\n };\n}\n\nfunction normalizeRunOptions(cwd: string, options: RunOptions): RunOptions {\n return { ...options, cwd: options.cwd ? validatePath(cwd, options.cwd) : cwd };\n}\n\nexport async function withSandbox<TProvider extends SandboxProvider<unknown>, TResult>(\n options: CreateSandboxOptions<TProvider>,\n callback: (sandbox: Sandbox<RawOf<TProvider>>) => TResult | Promise<TResult>,\n): Promise<TResult> {\n const sandbox = await createSandbox(options);\n try {\n const result = await callback(sandbox);\n await sandbox.stop();\n return result;\n } catch (error) {\n try {\n await sandbox.stop();\n } catch (cleanupError) {\n if (error instanceof Error) {\n Object.defineProperty(error, \"cleanupError\", { value: cleanup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