noumen 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +63 -8
  2. package/dist/a2a/index.d.ts +4 -2
  3. package/dist/acp/index.d.ts +5 -3
  4. package/dist/{agent-1nFVUP9E.d.ts → agent-C3eDRsxs.d.ts} +19 -508
  5. package/dist/chunk-I5SBSOS6.js +40 -0
  6. package/dist/chunk-I5SBSOS6.js.map +1 -0
  7. package/dist/{chunk-4HW6LN6D.js → chunk-WPCYGZOE.js} +58 -1228
  8. package/dist/chunk-WPCYGZOE.js.map +1 -0
  9. package/dist/{chunk-5JN4SPI7.js → chunk-WTLK2ZAR.js} +1 -1
  10. package/dist/{chunk-HL6JCRZJ.js → chunk-XZN4QZLK.js} +4 -4
  11. package/dist/cli/index.js +10 -10
  12. package/dist/computer-BPdxSo6X.d.ts +88 -0
  13. package/dist/docker.d.ts +129 -0
  14. package/dist/docker.js +401 -0
  15. package/dist/docker.js.map +1 -0
  16. package/dist/e2b.d.ts +157 -0
  17. package/dist/e2b.js +202 -0
  18. package/dist/e2b.js.map +1 -0
  19. package/dist/freestyle.d.ts +174 -0
  20. package/dist/freestyle.js +240 -0
  21. package/dist/freestyle.js.map +1 -0
  22. package/dist/index.d.ts +9 -201
  23. package/dist/index.js +24 -48
  24. package/dist/lsp/index.d.ts +3 -2
  25. package/dist/mcp/index.d.ts +4 -3
  26. package/dist/mcp/index.js +2 -2
  27. package/dist/{provider-factory-KCLIF34X.js → provider-factory-KI7OZUY3.js} +2 -2
  28. package/dist/{resolve-4JA2BBDA.js → resolve-GDSHNMG6.js} +2 -2
  29. package/dist/sandbox-9qeMTNrD.d.ts +126 -0
  30. package/dist/server/index.d.ts +4 -2
  31. package/dist/{server-CHMxuWKq.d.ts → server-Cu9gv1dk.d.ts} +1 -1
  32. package/dist/sprites.d.ts +136 -0
  33. package/dist/sprites.js +334 -0
  34. package/dist/sprites.js.map +1 -0
  35. package/dist/ssh.d.ts +187 -0
  36. package/dist/ssh.js +392 -0
  37. package/dist/ssh.js.map +1 -0
  38. package/dist/{types-RPKUTu1k.d.ts → types-BA87bHPV.d.ts} +2 -88
  39. package/package.json +28 -1
  40. package/dist/chunk-4HW6LN6D.js.map +0 -1
  41. /package/dist/{chunk-5JN4SPI7.js.map → chunk-WTLK2ZAR.js.map} +0 -0
  42. /package/dist/{chunk-HL6JCRZJ.js.map → chunk-XZN4QZLK.js.map} +0 -0
  43. /package/dist/{provider-factory-KCLIF34X.js.map → provider-factory-KI7OZUY3.js.map} +0 -0
  44. /package/dist/{resolve-4JA2BBDA.js.map → resolve-GDSHNMG6.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/virtual/docker-fs.ts","../src/virtual/docker-computer.ts","../src/virtual/docker-sandbox.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport type { VirtualFs, FileEntry, FileStat, ReadOptions } from \"./fs.js\";\nimport type { DockerContainer } from \"./docker-computer.js\";\n\nexport interface DockerFsOptions {\n /** A dockerode Container instance for the target container. */\n container: DockerContainer;\n /** Working directory for relative path resolution (default: /). */\n workingDir?: string;\n}\n\n/**\n * VirtualFs backed by file operations inside a Docker container.\n *\n * Uses `container.exec()` to run filesystem commands (cat, tee, rm, mkdir,\n * stat, etc.) inside the container. File writes use exec + tee to avoid\n * tar archive overhead for text content.\n *\n * Requires `dockerode` as an optional peer dependency.\n * The user is responsible for container lifecycle.\n */\nexport class DockerFs implements VirtualFs {\n private container: DockerContainer;\n private workingDir: string;\n\n constructor(opts: DockerFsOptions) {\n this.container = opts.container;\n this.workingDir = opts.workingDir ?? \"/\";\n }\n\n private resolvePath(p: string): string {\n if (p.includes(\"\\0\")) {\n throw new Error(\"Path contains null bytes\");\n }\n const normalizedBase = this.workingDir.endsWith(\"/\") ? this.workingDir : this.workingDir + \"/\";\n if (p.startsWith(\"/\")) {\n const normalized = path.normalize(p);\n if (normalized !== this.workingDir && !normalized.startsWith(normalizedBase)) {\n throw new Error(`Absolute path \"${p}\" is outside working directory \"${this.workingDir}\"`);\n }\n return normalized;\n }\n const resolved = path.resolve(this.workingDir, p);\n if (resolved !== this.workingDir && !resolved.startsWith(normalizedBase)) {\n throw new Error(`Path \"${p}\" escapes working directory \"${this.workingDir}\"`);\n }\n return resolved;\n }\n\n private async exec(\n cmd: string[],\n ): Promise<{ exitCode: number; stdout: string; stderr: string }> {\n const execInstance = await this.container.exec({\n Cmd: cmd,\n AttachStdout: true,\n AttachStderr: true,\n Tty: false,\n });\n const stream = await execInstance.start({ hijack: true, stdin: false });\n const result = await collectExecStream(stream);\n const inspection = await execInstance.inspect();\n return { exitCode: inspection.ExitCode, ...result };\n }\n\n async readFile(path: string, _opts?: ReadOptions): Promise<string> {\n const resolved = this.resolvePath(path);\n const { exitCode, stdout, stderr } = await this.exec([\n \"cat\",\n resolved,\n ]);\n if (exitCode !== 0) {\n throw new Error(`DockerFs readFile failed: ${stderr.trim() || `exit code ${exitCode}`}`);\n }\n return stdout;\n }\n\n async readFileBytes(path: string, maxBytes?: number): Promise<Buffer> {\n const resolved = this.resolvePath(path);\n const cmd = maxBytes !== undefined\n ? [\"head\", \"-c\", String(maxBytes), resolved]\n : [\"cat\", resolved];\n const { exitCode, stdout, stderr } = await this.exec([\n \"bash\", \"-c\",\n `${cmd.map(shellEscape).join(\" \")} | base64`,\n ]);\n if (exitCode !== 0) {\n throw new Error(`DockerFs readFileBytes failed: ${stderr.trim() || `exit code ${exitCode}`}`);\n }\n return Buffer.from(stdout.trim(), \"base64\");\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n const resolved = this.resolvePath(path);\n const dir = resolved.substring(0, resolved.lastIndexOf(\"/\"));\n if (dir) {\n await this.exec([\"mkdir\", \"-p\", dir]);\n }\n\n const encoded = Buffer.from(content, \"utf-8\").toString(\"base64\");\n\n const MAX_INLINE_LEN = 100_000;\n if (encoded.length <= MAX_INLINE_LEN) {\n const { exitCode, stderr } = await this.exec([\n \"bash\",\n \"-c\",\n `echo ${shellEscape(encoded)} | base64 -d > ${shellEscape(resolved)}`,\n ]);\n if (exitCode !== 0) {\n throw new Error(`DockerFs writeFile failed: ${stderr.trim()}`);\n }\n } else {\n const execInstance = await this.container.exec({\n Cmd: [\"bash\", \"-c\", `base64 -d > ${shellEscape(resolved)}`],\n AttachStdout: true,\n AttachStderr: true,\n AttachStdin: true,\n Tty: false,\n });\n const stream = await execInstance.start({ hijack: true, stdin: true });\n const writable = stream as unknown as NodeJS.WritableStream;\n writable.write(encoded);\n writable.end();\n const result = await collectExecStream(stream as unknown as NodeJS.ReadableStream);\n const inspection = await execInstance.inspect();\n if (inspection.ExitCode !== 0) {\n throw new Error(`DockerFs writeFile failed: ${result.stderr.trim()}`);\n }\n }\n }\n\n async appendFile(path: string, content: string): Promise<void> {\n const resolved = this.resolvePath(path);\n const dir = resolved.substring(0, resolved.lastIndexOf(\"/\"));\n if (dir) {\n await this.exec([\"mkdir\", \"-p\", dir]);\n }\n const encoded = Buffer.from(content, \"utf-8\").toString(\"base64\");\n const { exitCode, stderr } = await this.exec([\n \"bash\",\n \"-c\",\n `echo ${shellEscape(encoded)} | base64 -d >> ${shellEscape(resolved)}`,\n ]);\n if (exitCode !== 0) {\n throw new Error(`DockerFs appendFile failed: ${stderr.trim()}`);\n }\n }\n\n async deleteFile(\n path: string,\n opts?: { recursive?: boolean },\n ): Promise<void> {\n const resolved = this.resolvePath(path);\n const args = opts?.recursive ? [\"rm\", \"-rf\", resolved] : [\"rm\", \"-f\", resolved];\n await this.exec(args);\n }\n\n async mkdir(path: string, opts?: { recursive?: boolean }): Promise<void> {\n const resolved = this.resolvePath(path);\n const args = opts?.recursive\n ? [\"mkdir\", \"-p\", resolved]\n : [\"mkdir\", resolved];\n await this.exec(args);\n }\n\n async readdir(\n path: string,\n _opts?: { recursive?: boolean },\n ): Promise<FileEntry[]> {\n const resolved = this.resolvePath(path);\n const { exitCode, stdout, stderr } = await this.exec([\n \"bash\",\n \"-c\",\n `find ${shellEscape(resolved)} -maxdepth 1 -mindepth 1 -printf '%y %p\\\\n' 2>/dev/null`,\n ]);\n if (exitCode !== 0 && stderr.trim()) {\n throw new Error(`DockerFs readdir failed: ${stderr.trim()}`);\n }\n\n const entries: FileEntry[] = [];\n for (const line of stdout.trim().split(\"\\n\")) {\n if (!line) continue;\n const spaceIdx = line.indexOf(\" \");\n const type = line.substring(0, spaceIdx);\n const fullPath = line.substring(spaceIdx + 1);\n const name = fullPath.substring(fullPath.lastIndexOf(\"/\") + 1);\n entries.push({\n name,\n path: fullPath,\n isDirectory: type === \"d\",\n isFile: type === \"f\",\n });\n }\n return entries;\n }\n\n async exists(path: string): Promise<boolean> {\n const resolved = this.resolvePath(path);\n const { exitCode } = await this.exec([\"test\", \"-e\", resolved]);\n return exitCode === 0;\n }\n\n async stat(path: string): Promise<FileStat> {\n const resolved = this.resolvePath(path);\n const { exitCode, stdout, stderr } = await this.exec([\n \"stat\",\n \"-c\",\n \"%s\\t%F\\t%W\\t%Y\",\n resolved,\n ]);\n if (exitCode !== 0) {\n throw new Error(`DockerFs stat failed: ${stderr.trim() || `exit code ${exitCode}`}`);\n }\n\n const parts = stdout.trim().split(\"\\t\");\n const size = parseInt(parts[0], 10);\n const fileType = parts[1];\n const createdEpoch = parseInt(parts[2], 10);\n const modifiedEpoch = parseInt(parts[3], 10);\n\n return {\n size,\n isDirectory: fileType === \"directory\",\n isFile: fileType.startsWith(\"regular\"),\n createdAt: createdEpoch > 0 ? new Date(createdEpoch * 1000) : undefined,\n modifiedAt: modifiedEpoch > 0 ? new Date(modifiedEpoch * 1000) : undefined,\n };\n }\n}\n\nfunction shellEscape(s: string): string {\n return `'${s.replace(/'/g, \"'\\\\''\")}'`;\n}\n\nfunction collectExecStream(\n stream: NodeJS.ReadableStream,\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n const stdoutBufs: Buffer[] = [];\n const stderrBufs: Buffer[] = [];\n let pending: Buffer = Buffer.alloc(0);\n\n stream.on(\"data\", (chunk: Buffer) => {\n let buf = pending.length > 0 ? Buffer.concat([pending, chunk]) : chunk;\n let offset = 0;\n while (offset + 8 <= buf.length) {\n const payloadLen = buf.readUInt32BE(offset + 4);\n if (offset + 8 + payloadLen > buf.length) break;\n const streamType = buf[offset];\n const payload = buf.subarray(offset + 8, offset + 8 + payloadLen);\n if (streamType === 2) {\n stderrBufs.push(payload);\n } else {\n stdoutBufs.push(payload);\n }\n offset += 8 + payloadLen;\n }\n pending = offset < buf.length ? buf.subarray(offset) : Buffer.alloc(0);\n });\n\n stream.on(\"end\", () => {\n resolve({\n stdout: Buffer.concat(stdoutBufs).toString(\"utf-8\"),\n stderr: Buffer.concat(stderrBufs).toString(\"utf-8\"),\n });\n });\n\n stream.on(\"error\", (err: Error) => reject(err));\n });\n}\n","import type { VirtualComputer, ExecOptions, CommandResult } from \"./computer.js\";\n\n/**\n * Minimal subset of the dockerode Container interface used by DockerComputer.\n * Avoids a hard import of dockerode at the module level.\n */\nexport interface DockerContainer {\n exec(\n options: Record<string, unknown>,\n ): Promise<{ start(opts?: Record<string, unknown>): Promise<NodeJS.ReadableStream>; inspect(): Promise<{ ExitCode: number }> }>;\n}\n\nexport interface DockerComputerOptions {\n /** A dockerode Container instance for the target container. */\n container: DockerContainer;\n /** Default working directory for commands (default: /). */\n defaultCwd?: string;\n /** Default timeout in ms for commands (default: 30000). */\n defaultTimeout?: number;\n}\n\n/**\n * VirtualComputer backed by command execution inside a Docker container.\n *\n * Requires `dockerode` as an optional peer dependency.\n * The user is responsible for container lifecycle (create, start, stop).\n */\nexport class DockerComputer implements VirtualComputer {\n private container: DockerContainer;\n private defaultCwd: string;\n private defaultTimeout: number;\n\n constructor(opts: DockerComputerOptions) {\n this.container = opts.container;\n this.defaultCwd = opts.defaultCwd ?? \"/\";\n this.defaultTimeout = opts.defaultTimeout ?? 30_000;\n }\n\n async executeCommand(\n command: string,\n opts?: ExecOptions,\n ): Promise<CommandResult> {\n const cwd = opts?.cwd ?? this.defaultCwd;\n const timeout = opts?.timeout ?? this.defaultTimeout;\n\n const execOpts: Record<string, unknown> = {\n Cmd: [\"bash\", \"-c\", `cd ${shellEscape(cwd)} && ${command}`],\n AttachStdout: true,\n AttachStderr: true,\n Tty: false,\n };\n if (opts?.env) {\n execOpts.Env = Object.entries(opts.env).map(\n ([k, v]) => `${k}=${v}`,\n );\n }\n\n const exec = await this.container.exec(execOpts);\n const stream = await exec.start({ hijack: true, stdin: false });\n\n const { stdout, stderr } = await collectStream(stream, timeout);\n const inspection = await exec.inspect();\n\n return {\n exitCode: inspection.ExitCode,\n stdout,\n stderr,\n };\n }\n}\n\nfunction shellEscape(s: string): string {\n return `'${s.replace(/'/g, \"'\\\\''\")}'`;\n}\n\nfunction collectStream(\n stream: NodeJS.ReadableStream,\n timeout: number,\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n const stdoutBufs: Buffer[] = [];\n const stderrBufs: Buffer[] = [];\n let pending: Buffer = Buffer.alloc(0);\n\n const timer = setTimeout(() => {\n (stream as unknown as { destroy?: () => void }).destroy?.();\n resolve({\n stdout: Buffer.concat(stdoutBufs).toString(\"utf-8\"),\n stderr: Buffer.concat(stderrBufs).toString(\"utf-8\") +\n \"\\n[timeout after \" + timeout + \"ms]\",\n });\n }, timeout);\n\n stream.on(\"data\", (chunk: Buffer) => {\n let buf = pending.length > 0 ? Buffer.concat([pending, chunk]) : chunk;\n let offset = 0;\n while (offset + 8 <= buf.length) {\n const payloadLen = buf.readUInt32BE(offset + 4);\n if (offset + 8 + payloadLen > buf.length) break;\n const streamType = buf[offset];\n const payload = buf.subarray(offset + 8, offset + 8 + payloadLen);\n if (streamType === 2) {\n stderrBufs.push(payload);\n } else {\n stdoutBufs.push(payload);\n }\n offset += 8 + payloadLen;\n }\n pending = offset < buf.length ? buf.subarray(offset) : Buffer.alloc(0);\n });\n\n stream.on(\"end\", () => {\n clearTimeout(timer);\n resolve({\n stdout: Buffer.concat(stdoutBufs).toString(\"utf-8\"),\n stderr: Buffer.concat(stderrBufs).toString(\"utf-8\"),\n });\n });\n\n stream.on(\"error\", (err: Error) => {\n clearTimeout(timer);\n reject(err);\n });\n });\n}\n","import type { Sandbox } from \"./sandbox.js\";\nimport { DockerFs } from \"./docker-fs.js\";\nimport { DockerComputer, type DockerContainer } from \"./docker-computer.js\";\nimport { createFsProxy, createComputerProxy } from \"./proxy.js\";\n\nexport interface DockerSandboxOptions {\n /**\n * A pre-existing dockerode Container instance. When provided the sandbox\n * attaches to this container directly — no auto-creation occurs and\n * `dispose()` will **not** stop or remove it.\n *\n * When omitted, a new container is created from `image` on the first\n * `init()` call via a dynamic import of `dockerode`. The auto-created\n * container is stopped and removed when `dispose()` is called.\n */\n container?: DockerContainer;\n /**\n * Docker image to use for auto-creation (e.g. `\"ubuntu:22.04\"`).\n * Required when `container` is omitted; ignored when `container` is provided.\n */\n image?: string;\n /** Command to run in the auto-created container (default: `[\"sleep\", \"infinity\"]`). */\n cmd?: string[];\n /** Environment variables for the auto-created container. */\n env?: string[];\n /** Extra options passed to dockerode `createContainer`. */\n dockerOptions?: Record<string, unknown>;\n /** Working directory inside the container. */\n cwd?: string;\n /** Default timeout (ms) for shell commands. */\n defaultTimeout?: number;\n}\n\n/**\n * Create a `Sandbox` backed by a Docker container.\n * Requires `dockerode` as an optional peer dependency.\n *\n * **Auto-creation:** When `container` is omitted and `image` is provided,\n * the container is created and started lazily on the first `init()` call.\n * The container ID is available through `sandboxId()` for session\n * persistence. Pass the stored ID back through `init(storedId)` to\n * reattach to an existing container on resume.\n *\n * **Explicit container:** When `container` is provided, `init()` binds\n * it immediately. `dispose()` is a no-op — the caller owns the\n * container's lifecycle.\n *\n * @example\n * ```ts\n * // Auto-create from image\n * const sandbox = DockerSandbox({ image: \"ubuntu:22.04\", cwd: \"/workspace\" });\n *\n * // Explicit container (lifecycle managed externally)\n * const sandbox = DockerSandbox({ container: myDockerodeContainer });\n * ```\n */\nexport function DockerSandbox(opts: DockerSandboxOptions): Sandbox {\n if (opts.container) {\n const c = opts.container;\n return {\n fs: new DockerFs({ container: c, workingDir: opts.cwd }),\n computer: new DockerComputer({\n container: c,\n defaultCwd: opts.cwd,\n defaultTimeout: opts.defaultTimeout,\n }),\n sandboxId: () => (c as any).id as string | undefined,\n };\n }\n\n if (!opts.image) {\n throw new Error(\"DockerSandbox requires either `container` or `image`\");\n }\n\n const fsProxy = createFsProxy();\n const computerProxy = createComputerProxy();\n let containerId: string | undefined;\n let containerRef: any;\n let autoCreated = false;\n let initPromise: Promise<void> | null = null;\n\n async function doInit(reconnectId?: string): Promise<void> {\n const Docker = (await import(\"dockerode\")).default;\n const docker = new Docker();\n\n let container: any;\n if (reconnectId) {\n container = docker.getContainer(reconnectId);\n try {\n await container.inspect();\n } catch {\n container = await docker.createContainer({\n Image: opts.image!,\n Cmd: opts.cmd ?? [\"sleep\", \"infinity\"],\n Env: opts.env,\n Tty: false,\n ...opts.dockerOptions,\n });\n await container.start();\n autoCreated = true;\n }\n } else {\n container = await docker.createContainer({\n Image: opts.image!,\n Cmd: opts.cmd ?? [\"sleep\", \"infinity\"],\n Env: opts.env,\n Tty: false,\n ...opts.dockerOptions,\n });\n await container.start();\n autoCreated = true;\n }\n\n containerRef = container;\n containerId = container.id;\n fsProxy.setTarget(new DockerFs({ container, workingDir: opts.cwd }));\n computerProxy.setTarget(new DockerComputer({\n container,\n defaultCwd: opts.cwd,\n defaultTimeout: opts.defaultTimeout,\n }));\n }\n\n return {\n fs: fsProxy,\n computer: computerProxy,\n sandboxId: () => containerId,\n\n init(sandboxId?: string): Promise<void> {\n if (!initPromise) {\n initPromise = doInit(sandboxId).catch((err) => {\n initPromise = null;\n throw err;\n });\n }\n return initPromise;\n },\n\n async dispose(): Promise<void> {\n if (initPromise) {\n await initPromise.catch(() => {});\n }\n if (!autoCreated || !containerRef) return;\n try { await containerRef.stop(); } catch { /* may already be stopped */ }\n try { await containerRef.remove(); } catch { /* best-effort */ }\n },\n };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AAG,QAAQ;AAAA,MAA+B;AACxE,UAAI;AAAE,cAAM,aAAa,OAAO;AAAA,MAAG,QAAQ;AAAA,MAAoB;AAAA,IACjE;AAAA,EACF;AACF;","names":["path","resolve","shellEscape","resolve"]}
package/dist/e2b.d.ts ADDED
@@ -0,0 +1,157 @@
1
+ import { S as Sandbox } from './sandbox-9qeMTNrD.js';
2
+ import { V as VirtualComputer, E as ExecOptions, C as CommandResult, a as VirtualFs, R as ReadOptions, F as FileEntry, b as FileStat } from './computer-BPdxSo6X.js';
3
+
4
+ /**
5
+ * Minimal subset of the E2B Sandbox interface used by E2BComputer and E2BFs.
6
+ * Avoids a hard import of `e2b` at the module level.
7
+ */
8
+ interface E2BSandboxInstance {
9
+ commands: {
10
+ run(cmd: string, opts?: {
11
+ cwd?: string;
12
+ timeout?: number;
13
+ envs?: Record<string, string>;
14
+ }): Promise<{
15
+ exitCode: number;
16
+ stdout: string;
17
+ stderr: string;
18
+ }>;
19
+ };
20
+ files: {
21
+ read(path: string, opts?: {
22
+ format?: string;
23
+ }): Promise<string>;
24
+ write(path: string, data: string): Promise<unknown>;
25
+ remove(path: string): Promise<void>;
26
+ makeDir(path: string): Promise<unknown>;
27
+ list(path: string): Promise<Array<{
28
+ name: string;
29
+ path: string;
30
+ type?: string;
31
+ size?: number;
32
+ modifiedTime?: Date;
33
+ }>>;
34
+ exists(path: string): Promise<boolean>;
35
+ getInfo(path: string): Promise<{
36
+ name: string;
37
+ path: string;
38
+ type?: string;
39
+ size?: number;
40
+ modifiedTime?: Date;
41
+ }>;
42
+ };
43
+ }
44
+ interface E2BComputerOptions {
45
+ /** An E2B Sandbox instance created via `Sandbox.create()`. */
46
+ sandbox: E2BSandboxInstance;
47
+ /** Default working directory for commands. */
48
+ defaultCwd?: string;
49
+ /** Default timeout in ms for commands (default: 30000). */
50
+ defaultTimeout?: number;
51
+ }
52
+ /**
53
+ * VirtualComputer backed by command execution in an E2B cloud sandbox.
54
+ *
55
+ * Requires `e2b` as an optional peer dependency.
56
+ * The user is responsible for sandbox lifecycle (create, close).
57
+ */
58
+ declare class E2BComputer implements VirtualComputer {
59
+ private sandbox;
60
+ private defaultCwd;
61
+ private defaultTimeout;
62
+ constructor(opts: E2BComputerOptions);
63
+ executeCommand(command: string, opts?: ExecOptions): Promise<CommandResult>;
64
+ }
65
+
66
+ interface E2BSandboxOptions {
67
+ /**
68
+ * A pre-existing E2B Sandbox instance (e.g. from `Sandbox.create()`).
69
+ * When provided the sandbox attaches to this instance — no auto-creation
70
+ * occurs and `dispose()` will **not** kill it.
71
+ *
72
+ * When omitted, a new E2B sandbox is created on the first `init()` call
73
+ * via a dynamic import of the `e2b` package. The auto-created sandbox
74
+ * is killed when `dispose()` is called.
75
+ */
76
+ sandbox?: E2BSandboxInstance;
77
+ /**
78
+ * E2B template to use for auto-creation (default: `"base"`).
79
+ * Only used when `sandbox` is omitted.
80
+ */
81
+ template?: string;
82
+ /**
83
+ * E2B API key. Falls back to the `E2B_API_KEY` environment variable
84
+ * when omitted. Only used during auto-creation.
85
+ */
86
+ apiKey?: string;
87
+ /** Timeout (ms) for the auto-created E2B sandbox (default: E2B SDK default). */
88
+ timeoutMs?: number;
89
+ /** Working directory inside the sandbox. */
90
+ cwd?: string;
91
+ /** Default timeout (ms) for shell commands. */
92
+ defaultTimeout?: number;
93
+ }
94
+ /**
95
+ * Create a `Sandbox` backed by an E2B cloud sandbox.
96
+ * Requires `e2b` as an optional peer dependency.
97
+ *
98
+ * **Auto-creation:** When `sandbox` is omitted the E2B sandbox is
99
+ * provisioned lazily on the first `init()` call via the E2B SDK.
100
+ * The sandbox ID is available through `sandboxId()` for session
101
+ * persistence. Pass the stored ID back through `init(storedId)` to
102
+ * reconnect to the same sandbox on resume (via `Sandbox.connect()`).
103
+ *
104
+ * **Explicit instance:** When `sandbox` is provided, `init()` binds
105
+ * it immediately. `dispose()` is a no-op — the caller owns the
106
+ * sandbox's lifecycle.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * // Auto-create — sandbox provisioned on first init()
111
+ * const sandbox = E2BSandbox({ template: "base" });
112
+ *
113
+ * // Explicit — attach to pre-existing instance
114
+ * const sandbox = E2BSandbox({ sandbox: await E2BSdk.Sandbox.create() });
115
+ * ```
116
+ */
117
+ declare function E2BSandbox(opts: E2BSandboxOptions): Sandbox;
118
+
119
+ interface E2BFsOptions {
120
+ /** An E2B Sandbox instance created via `Sandbox.create()`. */
121
+ sandbox: E2BSandboxInstance;
122
+ /** Working directory for relative path resolution. */
123
+ workingDir?: string;
124
+ }
125
+ /**
126
+ * VirtualFs backed by the E2B cloud sandbox filesystem.
127
+ *
128
+ * Requires `e2b` as an optional peer dependency.
129
+ * The user is responsible for sandbox lifecycle (create, close).
130
+ */
131
+ declare class E2BFs implements VirtualFs {
132
+ private sandbox;
133
+ private workingDir;
134
+ constructor(opts: E2BFsOptions);
135
+ private resolvePath;
136
+ readFile(path: string, _opts?: ReadOptions): Promise<string>;
137
+ readFileBytes(path: string, maxBytes?: number): Promise<Buffer>;
138
+ writeFile(path: string, content: string): Promise<void>;
139
+ /**
140
+ * @warning Not atomic. Concurrent appends may lose data due to
141
+ * read-then-write TOCTOU. The E2B SDK does not expose an append primitive.
142
+ */
143
+ appendFile(path: string, content: string): Promise<void>;
144
+ deleteFile(path: string, _opts?: {
145
+ recursive?: boolean;
146
+ }): Promise<void>;
147
+ mkdir(path: string, _opts?: {
148
+ recursive?: boolean;
149
+ }): Promise<void>;
150
+ readdir(path: string, _opts?: {
151
+ recursive?: boolean;
152
+ }): Promise<FileEntry[]>;
153
+ exists(path: string): Promise<boolean>;
154
+ stat(path: string): Promise<FileStat>;
155
+ }
156
+
157
+ export { E2BComputer, type E2BComputerOptions, E2BFs, type E2BFsOptions, E2BSandbox, type E2BSandboxInstance, type E2BSandboxOptions };
package/dist/e2b.js ADDED
@@ -0,0 +1,202 @@
1
+ import {
2
+ createComputerProxy,
3
+ createFsProxy
4
+ } from "./chunk-I5SBSOS6.js";
5
+ import "./chunk-DGUM43GV.js";
6
+
7
+ // src/virtual/e2b-fs.ts
8
+ import * as path from "path";
9
+ var E2BFs = class {
10
+ sandbox;
11
+ workingDir;
12
+ constructor(opts) {
13
+ this.sandbox = opts.sandbox;
14
+ this.workingDir = opts.workingDir;
15
+ }
16
+ resolvePath(p) {
17
+ if (!this.workingDir) return p;
18
+ const normalizedBase = this.workingDir.endsWith("/") ? this.workingDir : this.workingDir + "/";
19
+ if (p.startsWith("/")) {
20
+ if (p !== this.workingDir && !p.startsWith(normalizedBase)) {
21
+ throw new Error(`Absolute path "${p}" is outside working directory "${this.workingDir}"`);
22
+ }
23
+ return p;
24
+ }
25
+ const resolved = path.resolve(this.workingDir, p);
26
+ if (resolved !== this.workingDir && !resolved.startsWith(normalizedBase)) {
27
+ throw new Error(`Path "${p}" escapes working directory "${this.workingDir}"`);
28
+ }
29
+ return resolved;
30
+ }
31
+ async readFile(path2, _opts) {
32
+ return this.sandbox.files.read(this.resolvePath(path2), {
33
+ format: "text"
34
+ });
35
+ }
36
+ async readFileBytes(path2, maxBytes) {
37
+ const data = await this.sandbox.files.read(this.resolvePath(path2), {
38
+ format: "bytes"
39
+ });
40
+ const buf = Buffer.from(data);
41
+ if (maxBytes !== void 0 && buf.length > maxBytes) {
42
+ return buf.subarray(0, maxBytes);
43
+ }
44
+ return buf;
45
+ }
46
+ async writeFile(path2, content) {
47
+ await this.sandbox.files.write(this.resolvePath(path2), content);
48
+ }
49
+ /**
50
+ * @warning Not atomic. Concurrent appends may lose data due to
51
+ * read-then-write TOCTOU. The E2B SDK does not expose an append primitive.
52
+ */
53
+ async appendFile(path2, content) {
54
+ let existing = "";
55
+ try {
56
+ existing = await this.readFile(path2);
57
+ } catch {
58
+ }
59
+ await this.writeFile(path2, existing + content);
60
+ }
61
+ async deleteFile(path2, _opts) {
62
+ await this.sandbox.files.remove(this.resolvePath(path2));
63
+ }
64
+ async mkdir(path2, _opts) {
65
+ await this.sandbox.files.makeDir(this.resolvePath(path2));
66
+ }
67
+ async readdir(path2, _opts) {
68
+ const entries = await this.sandbox.files.list(this.resolvePath(path2));
69
+ return entries.map((entry) => ({
70
+ name: entry.name,
71
+ path: entry.path,
72
+ isDirectory: entry.type === "dir",
73
+ isFile: entry.type === "file",
74
+ size: entry.size
75
+ }));
76
+ }
77
+ async exists(path2) {
78
+ return this.sandbox.files.exists(this.resolvePath(path2));
79
+ }
80
+ async stat(path2) {
81
+ const info = await this.sandbox.files.getInfo(this.resolvePath(path2));
82
+ return {
83
+ size: info.size ?? 0,
84
+ isDirectory: info.type === "dir",
85
+ isFile: info.type === "file",
86
+ modifiedAt: info.modifiedTime
87
+ };
88
+ }
89
+ };
90
+
91
+ // src/virtual/e2b-computer.ts
92
+ var E2BComputer = class {
93
+ sandbox;
94
+ defaultCwd;
95
+ defaultTimeout;
96
+ constructor(opts) {
97
+ this.sandbox = opts.sandbox;
98
+ this.defaultCwd = opts.defaultCwd;
99
+ this.defaultTimeout = opts.defaultTimeout ?? 3e4;
100
+ }
101
+ async executeCommand(command, opts) {
102
+ const result = await this.sandbox.commands.run(command, {
103
+ cwd: opts?.cwd ?? this.defaultCwd,
104
+ timeout: opts?.timeout ?? this.defaultTimeout,
105
+ envs: opts?.env
106
+ });
107
+ return {
108
+ exitCode: result.exitCode,
109
+ stdout: result.stdout ?? "",
110
+ stderr: result.stderr ?? ""
111
+ };
112
+ }
113
+ };
114
+
115
+ // src/virtual/e2b-sandbox.ts
116
+ function E2BSandbox(opts) {
117
+ if (opts.sandbox) {
118
+ const s = opts.sandbox;
119
+ return {
120
+ fs: new E2BFs({ sandbox: s, workingDir: opts.cwd }),
121
+ computer: new E2BComputer({
122
+ sandbox: s,
123
+ defaultCwd: opts.cwd,
124
+ defaultTimeout: opts.defaultTimeout
125
+ }),
126
+ sandboxId: () => s.sandboxId
127
+ };
128
+ }
129
+ const fsProxy = createFsProxy();
130
+ const computerProxy = createComputerProxy();
131
+ let resolvedId;
132
+ let sandboxRef;
133
+ let autoCreated = false;
134
+ let initPromise = null;
135
+ async function doInit(reconnectId) {
136
+ const e2b = await import("e2b");
137
+ const SandboxClass = e2b.Sandbox ?? e2b.default?.Sandbox;
138
+ if (!SandboxClass) {
139
+ throw new Error("Could not resolve Sandbox class from 'e2b' package");
140
+ }
141
+ let sandbox;
142
+ if (reconnectId) {
143
+ try {
144
+ sandbox = await SandboxClass.connect(reconnectId, {
145
+ apiKey: opts.apiKey
146
+ });
147
+ } catch {
148
+ sandbox = await SandboxClass.create({
149
+ template: opts.template ?? "base",
150
+ apiKey: opts.apiKey,
151
+ timeoutMs: opts.timeoutMs
152
+ });
153
+ autoCreated = true;
154
+ }
155
+ } else {
156
+ sandbox = await SandboxClass.create({
157
+ template: opts.template ?? "base",
158
+ apiKey: opts.apiKey,
159
+ timeoutMs: opts.timeoutMs
160
+ });
161
+ autoCreated = true;
162
+ }
163
+ sandboxRef = sandbox;
164
+ resolvedId = sandbox.sandboxId ?? reconnectId;
165
+ fsProxy.setTarget(new E2BFs({ sandbox, workingDir: opts.cwd }));
166
+ computerProxy.setTarget(new E2BComputer({
167
+ sandbox,
168
+ defaultCwd: opts.cwd,
169
+ defaultTimeout: opts.defaultTimeout
170
+ }));
171
+ }
172
+ return {
173
+ fs: fsProxy,
174
+ computer: computerProxy,
175
+ sandboxId: () => resolvedId,
176
+ init(sandboxId) {
177
+ if (!initPromise) {
178
+ initPromise = doInit(sandboxId).catch((err) => {
179
+ initPromise = null;
180
+ throw err;
181
+ });
182
+ }
183
+ return initPromise;
184
+ },
185
+ async dispose() {
186
+ if (initPromise) {
187
+ await initPromise.catch(() => {
188
+ });
189
+ }
190
+ if (!autoCreated || !sandboxRef) return;
191
+ if (typeof sandboxRef.kill === "function") {
192
+ await sandboxRef.kill();
193
+ }
194
+ }
195
+ };
196
+ }
197
+ export {
198
+ E2BComputer,
199
+ E2BFs,
200
+ E2BSandbox
201
+ };
202
+ //# sourceMappingURL=e2b.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/virtual/e2b-fs.ts","../src/virtual/e2b-computer.ts","../src/virtual/e2b-sandbox.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport type { VirtualFs, FileEntry, FileStat, ReadOptions } from \"./fs.js\";\nimport type { E2BSandboxInstance } from \"./e2b-computer.js\";\n\nexport interface E2BFsOptions {\n /** An E2B Sandbox instance created via `Sandbox.create()`. */\n sandbox: E2BSandboxInstance;\n /** Working directory for relative path resolution. */\n workingDir?: string;\n}\n\n/**\n * VirtualFs backed by the E2B cloud sandbox filesystem.\n *\n * Requires `e2b` as an optional peer dependency.\n * The user is responsible for sandbox lifecycle (create, close).\n */\nexport class E2BFs implements VirtualFs {\n private sandbox: E2BSandboxInstance;\n private workingDir: string | undefined;\n\n constructor(opts: E2BFsOptions) {\n this.sandbox = opts.sandbox;\n this.workingDir = opts.workingDir;\n }\n\n private resolvePath(p: string): string {\n if (!this.workingDir) return p;\n const normalizedBase = this.workingDir.endsWith(\"/\") ? this.workingDir : this.workingDir + \"/\";\n if (p.startsWith(\"/\")) {\n if (p !== this.workingDir && !p.startsWith(normalizedBase)) {\n throw new Error(`Absolute path \"${p}\" is outside working directory \"${this.workingDir}\"`);\n }\n return p;\n }\n const resolved = path.resolve(this.workingDir, p);\n if (resolved !== this.workingDir && !resolved.startsWith(normalizedBase)) {\n throw new Error(`Path \"${p}\" escapes working directory \"${this.workingDir}\"`);\n }\n return resolved;\n }\n\n async readFile(path: string, _opts?: ReadOptions): Promise<string> {\n return this.sandbox.files.read(this.resolvePath(path), {\n format: \"text\",\n });\n }\n\n async readFileBytes(path: string, maxBytes?: number): Promise<Buffer> {\n const data = await this.sandbox.files.read(this.resolvePath(path), {\n format: \"bytes\",\n } as Record<string, unknown>);\n const buf = Buffer.from(data as unknown as ArrayBuffer);\n if (maxBytes !== undefined && buf.length > maxBytes) {\n return buf.subarray(0, maxBytes);\n }\n return buf;\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n await this.sandbox.files.write(this.resolvePath(path), content);\n }\n\n /**\n * @warning Not atomic. Concurrent appends may lose data due to\n * read-then-write TOCTOU. The E2B SDK does not expose an append primitive.\n */\n async appendFile(path: string, content: string): Promise<void> {\n let existing = \"\";\n try {\n existing = await this.readFile(path);\n } catch {\n // file may not exist yet\n }\n await this.writeFile(path, existing + content);\n }\n\n async deleteFile(\n path: string,\n _opts?: { recursive?: boolean },\n ): Promise<void> {\n await this.sandbox.files.remove(this.resolvePath(path));\n }\n\n async mkdir(path: string, _opts?: { recursive?: boolean }): Promise<void> {\n await this.sandbox.files.makeDir(this.resolvePath(path));\n }\n\n async readdir(\n path: string,\n _opts?: { recursive?: boolean },\n ): Promise<FileEntry[]> {\n const entries = await this.sandbox.files.list(this.resolvePath(path));\n return entries.map((entry) => ({\n name: entry.name,\n path: entry.path,\n isDirectory: entry.type === \"dir\",\n isFile: entry.type === \"file\",\n size: entry.size,\n }));\n }\n\n async exists(path: string): Promise<boolean> {\n return this.sandbox.files.exists(this.resolvePath(path));\n }\n\n async stat(path: string): Promise<FileStat> {\n const info = await this.sandbox.files.getInfo(this.resolvePath(path));\n return {\n size: info.size ?? 0,\n isDirectory: info.type === \"dir\",\n isFile: info.type === \"file\",\n modifiedAt: info.modifiedTime,\n };\n }\n}\n","import type { VirtualComputer, ExecOptions, CommandResult } from \"./computer.js\";\n\n/**\n * Minimal subset of the E2B Sandbox interface used by E2BComputer and E2BFs.\n * Avoids a hard import of `e2b` at the module level.\n */\nexport interface E2BSandboxInstance {\n commands: {\n run(\n cmd: string,\n opts?: {\n cwd?: string;\n timeout?: number;\n envs?: Record<string, string>;\n },\n ): Promise<{\n exitCode: number;\n stdout: string;\n stderr: string;\n }>;\n };\n files: {\n read(path: string, opts?: { format?: string }): Promise<string>;\n write(path: string, data: string): Promise<unknown>;\n remove(path: string): Promise<void>;\n makeDir(path: string): Promise<unknown>;\n list(path: string): Promise<\n Array<{\n name: string;\n path: string;\n type?: string;\n size?: number;\n modifiedTime?: Date;\n }>\n >;\n exists(path: string): Promise<boolean>;\n getInfo(path: string): Promise<{\n name: string;\n path: string;\n type?: string;\n size?: number;\n modifiedTime?: Date;\n }>;\n };\n}\n\nexport interface E2BComputerOptions {\n /** An E2B Sandbox instance created via `Sandbox.create()`. */\n sandbox: E2BSandboxInstance;\n /** Default working directory for commands. */\n defaultCwd?: string;\n /** Default timeout in ms for commands (default: 30000). */\n defaultTimeout?: number;\n}\n\n/**\n * VirtualComputer backed by command execution in an E2B cloud sandbox.\n *\n * Requires `e2b` as an optional peer dependency.\n * The user is responsible for sandbox lifecycle (create, close).\n */\nexport class E2BComputer implements VirtualComputer {\n private sandbox: E2BSandboxInstance;\n private defaultCwd: string | undefined;\n private defaultTimeout: number;\n\n constructor(opts: E2BComputerOptions) {\n this.sandbox = opts.sandbox;\n this.defaultCwd = opts.defaultCwd;\n this.defaultTimeout = opts.defaultTimeout ?? 30_000;\n }\n\n async executeCommand(\n command: string,\n opts?: ExecOptions,\n ): Promise<CommandResult> {\n const result = await this.sandbox.commands.run(command, {\n cwd: opts?.cwd ?? this.defaultCwd,\n timeout: opts?.timeout ?? this.defaultTimeout,\n envs: opts?.env,\n });\n\n return {\n exitCode: result.exitCode,\n stdout: result.stdout ?? \"\",\n stderr: result.stderr ?? \"\",\n };\n }\n}\n","import type { Sandbox } from \"./sandbox.js\";\nimport { E2BFs } from \"./e2b-fs.js\";\nimport { E2BComputer, type E2BSandboxInstance } from \"./e2b-computer.js\";\nimport { createFsProxy, createComputerProxy } from \"./proxy.js\";\n\nexport interface E2BSandboxOptions {\n /**\n * A pre-existing E2B Sandbox instance (e.g. from `Sandbox.create()`).\n * When provided the sandbox attaches to this instance — no auto-creation\n * occurs and `dispose()` will **not** kill it.\n *\n * When omitted, a new E2B sandbox is created on the first `init()` call\n * via a dynamic import of the `e2b` package. The auto-created sandbox\n * is killed when `dispose()` is called.\n */\n sandbox?: E2BSandboxInstance;\n /**\n * E2B template to use for auto-creation (default: `\"base\"`).\n * Only used when `sandbox` is omitted.\n */\n template?: string;\n /**\n * E2B API key. Falls back to the `E2B_API_KEY` environment variable\n * when omitted. Only used during auto-creation.\n */\n apiKey?: string;\n /** Timeout (ms) for the auto-created E2B sandbox (default: E2B SDK default). */\n timeoutMs?: number;\n /** Working directory inside the sandbox. */\n cwd?: string;\n /** Default timeout (ms) for shell commands. */\n defaultTimeout?: number;\n}\n\n/**\n * Create a `Sandbox` backed by an E2B cloud sandbox.\n * Requires `e2b` as an optional peer dependency.\n *\n * **Auto-creation:** When `sandbox` is omitted the E2B sandbox is\n * provisioned lazily on the first `init()` call via the E2B SDK.\n * The sandbox ID is available through `sandboxId()` for session\n * persistence. Pass the stored ID back through `init(storedId)` to\n * reconnect to the same sandbox on resume (via `Sandbox.connect()`).\n *\n * **Explicit instance:** When `sandbox` is provided, `init()` binds\n * it immediately. `dispose()` is a no-op — the caller owns the\n * sandbox's lifecycle.\n *\n * @example\n * ```ts\n * // Auto-create — sandbox provisioned on first init()\n * const sandbox = E2BSandbox({ template: \"base\" });\n *\n * // Explicit — attach to pre-existing instance\n * const sandbox = E2BSandbox({ sandbox: await E2BSdk.Sandbox.create() });\n * ```\n */\nexport function E2BSandbox(opts: E2BSandboxOptions): Sandbox {\n if (opts.sandbox) {\n const s = opts.sandbox;\n return {\n fs: new E2BFs({ sandbox: s, workingDir: opts.cwd }),\n computer: new E2BComputer({\n sandbox: s,\n defaultCwd: opts.cwd,\n defaultTimeout: opts.defaultTimeout,\n }),\n sandboxId: () => (s as any).sandboxId as string | undefined,\n };\n }\n\n const fsProxy = createFsProxy();\n const computerProxy = createComputerProxy();\n let resolvedId: string | undefined;\n let sandboxRef: any;\n let autoCreated = false;\n let initPromise: Promise<void> | null = null;\n\n async function doInit(reconnectId?: string): Promise<void> {\n const e2b = await import(\"e2b\");\n const SandboxClass = (e2b as any).Sandbox ?? (e2b as any).default?.Sandbox;\n if (!SandboxClass) {\n throw new Error(\"Could not resolve Sandbox class from 'e2b' package\");\n }\n\n let sandbox: E2BSandboxInstance;\n if (reconnectId) {\n try {\n sandbox = await SandboxClass.connect(reconnectId, {\n apiKey: opts.apiKey,\n });\n } catch {\n sandbox = await SandboxClass.create({\n template: opts.template ?? \"base\",\n apiKey: opts.apiKey,\n timeoutMs: opts.timeoutMs,\n });\n autoCreated = true;\n }\n } else {\n sandbox = await SandboxClass.create({\n template: opts.template ?? \"base\",\n apiKey: opts.apiKey,\n timeoutMs: opts.timeoutMs,\n });\n autoCreated = true;\n }\n\n sandboxRef = sandbox;\n resolvedId = (sandbox as any).sandboxId ?? reconnectId;\n fsProxy.setTarget(new E2BFs({ sandbox, workingDir: opts.cwd }));\n computerProxy.setTarget(new E2BComputer({\n sandbox,\n defaultCwd: opts.cwd,\n defaultTimeout: opts.defaultTimeout,\n }));\n }\n\n return {\n fs: fsProxy,\n computer: computerProxy,\n sandboxId: () => resolvedId,\n\n init(sandboxId?: string): Promise<void> {\n if (!initPromise) {\n initPromise = doInit(sandboxId).catch((err) => {\n initPromise = null;\n throw err;\n });\n }\n return initPromise;\n },\n\n async dispose(): Promise<void> {\n if (initPromise) {\n await initPromise.catch(() => {});\n }\n if (!autoCreated || !sandboxRef) return;\n if (typeof sandboxRef.kill === \"function\") {\n await sandboxRef.kill();\n }\n },\n };\n}\n"],"mappings":";;;;;;;AAAA,YAAY,UAAU;AAiBf,IAAM,QAAN,MAAiC;AAAA,EAC9B;AAAA,EACA;AAAA,EAER,YAAY,MAAoB;AAC9B,SAAK,UAAU,KAAK;AACpB,SAAK,aAAa,KAAK;AAAA,EACzB;AAAA,EAEQ,YAAY,GAAmB;AACrC,QAAI,CAAC,KAAK,WAAY,QAAO;AAC7B,UAAM,iBAAiB,KAAK,WAAW,SAAS,GAAG,IAAI,KAAK,aAAa,KAAK,aAAa;AAC3F,QAAI,EAAE,WAAW,GAAG,GAAG;AACrB,UAAI,MAAM,KAAK,cAAc,CAAC,EAAE,WAAW,cAAc,GAAG;AAC1D,cAAM,IAAI,MAAM,kBAAkB,CAAC,mCAAmC,KAAK,UAAU,GAAG;AAAA,MAC1F;AACA,aAAO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,KAAK;AAAA,IACvB,CAAC,CAAC;AAAA,EACJ;AAEA,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,UAAU;AAAA,IACV,WAAW,MAAM;AAAA,IAEjB,KAAK,WAAmC;AACtC,UAAI,CAAC,aAAa;AAChB,sBAAc,OAAO,SAAS,EAAE,MAAM,CAAC,QAAQ;AAC7C,wBAAc;AACd,gBAAM;AAAA,QACR,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAAA,IAEA,MAAM,UAAyB;AAC7B,UAAI,aAAa;AACf,cAAM,YAAY,MAAM,MAAM;AAAA,QAAC,CAAC;AAAA,MAClC;AACA,UAAI,CAAC,eAAe,CAAC,WAAY;AACjC,UAAI,OAAO,WAAW,SAAS,YAAY;AACzC,cAAM,WAAW,KAAK;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF;","names":["path"]}
@@ -0,0 +1,174 @@
1
+ import { S as Sandbox } from './sandbox-9qeMTNrD.js';
2
+ import { V as VirtualComputer, E as ExecOptions, C as CommandResult, a as VirtualFs, R as ReadOptions, F as FileEntry, b as FileStat } from './computer-BPdxSo6X.js';
3
+
4
+ /**
5
+ * Minimal subset of the Freestyle VM interface used by FreestyleComputer and
6
+ * FreestyleFs. Avoids a hard import of `freestyle-sandboxes` at the module
7
+ * level — the real SDK is only loaded dynamically during `FreestyleSandbox`
8
+ * auto-creation.
9
+ */
10
+ interface FreestyleVmInstance {
11
+ exec(command: string, opts?: {
12
+ cwd?: string;
13
+ timeout?: number;
14
+ }): Promise<{
15
+ stdout: string | null;
16
+ stderr: string | null;
17
+ statusCode: number | null;
18
+ }>;
19
+ fs: {
20
+ readTextFile(path: string): Promise<string>;
21
+ writeTextFile(path: string, content: string): Promise<void>;
22
+ readDir(path: string): Promise<Array<{
23
+ name: string;
24
+ kind: string;
25
+ }>>;
26
+ };
27
+ suspend(): Promise<unknown>;
28
+ start(): Promise<unknown>;
29
+ }
30
+ interface FreestyleComputerOptions {
31
+ /** A Freestyle VM instance. */
32
+ vm: FreestyleVmInstance;
33
+ /** Default working directory for commands. */
34
+ defaultCwd?: string;
35
+ /** Default timeout in ms for commands (default: 30000). */
36
+ defaultTimeout?: number;
37
+ }
38
+ /**
39
+ * VirtualComputer backed by command execution in a Freestyle VM.
40
+ *
41
+ * Requires `freestyle-sandboxes` as an optional peer dependency.
42
+ * The user is responsible for VM lifecycle when using explicit mode.
43
+ */
44
+ declare class FreestyleComputer implements VirtualComputer {
45
+ private vm;
46
+ private defaultCwd;
47
+ private defaultTimeout;
48
+ constructor(opts: FreestyleComputerOptions);
49
+ executeCommand(command: string, opts?: ExecOptions): Promise<CommandResult>;
50
+ }
51
+
52
+ interface FreestyleSandboxOptions {
53
+ /**
54
+ * A pre-existing Freestyle VM instance. When provided the sandbox
55
+ * attaches to this VM directly — no auto-creation occurs and
56
+ * `dispose()` will **not** suspend or delete it.
57
+ *
58
+ * When omitted, a new VM is created on the first `init()` call via
59
+ * a dynamic import of the `freestyle-sandboxes` package.
60
+ */
61
+ vm?: FreestyleVmInstance;
62
+ /**
63
+ * Freestyle API key. Falls back to the `FREESTYLE_API_KEY` environment
64
+ * variable when omitted. Only used during auto-creation.
65
+ */
66
+ apiKey?: string;
67
+ /** Snapshot ID to create the VM from. Only used during auto-creation. */
68
+ snapshotId?: string;
69
+ /**
70
+ * A `VmSpec` instance or configuration object passed through to
71
+ * `freestyle.vms.create()`. Only used during auto-creation.
72
+ */
73
+ spec?: unknown;
74
+ /**
75
+ * Idle timeout in seconds for the auto-created VM (default: 600).
76
+ * The VM auto-suspends after this many seconds of network inactivity.
77
+ */
78
+ idleTimeoutSeconds?: number;
79
+ /** Working directory inside the VM. */
80
+ cwd?: string;
81
+ /** Default timeout (ms) for shell commands. */
82
+ defaultTimeout?: number;
83
+ /** Files to provision at creation time. */
84
+ additionalFiles?: Record<string, {
85
+ content: string;
86
+ encoding?: string;
87
+ }>;
88
+ /** Git repos to clone at creation time. */
89
+ gitRepos?: Array<{
90
+ repo: string;
91
+ path: string;
92
+ rev?: string;
93
+ }>;
94
+ /**
95
+ * What to do with auto-created VMs on `dispose()`:
96
+ * - `"suspend"` (default) — suspends the VM, preserving full memory
97
+ * state for near-instant resume on reconnect.
98
+ * - `"delete"` — permanently deletes the VM and frees all resources.
99
+ */
100
+ disposeStrategy?: "suspend" | "delete";
101
+ }
102
+ /**
103
+ * Create a `Sandbox` backed by a Freestyle VM.
104
+ * Requires `freestyle-sandboxes` as an optional peer dependency.
105
+ *
106
+ * **Auto-creation:** When `vm` is omitted a new Freestyle VM is
107
+ * provisioned lazily on the first `init()` call. The VM ID is available
108
+ * through `sandboxId()` for session persistence. Pass the stored ID back
109
+ * through `init(storedId)` to reconnect (this also wakes suspended VMs).
110
+ *
111
+ * By default, auto-created VMs are **suspended** on `dispose()` rather
112
+ * than deleted. This preserves full memory state and allows near-instant
113
+ * resume. Set `disposeStrategy: "delete"` for full cleanup.
114
+ *
115
+ * **Explicit instance:** When `vm` is provided, `init()` binds it
116
+ * immediately. `dispose()` is a no-op — the caller owns the VM's
117
+ * lifecycle.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * // Auto-create — VM provisioned on first init()
122
+ * const sandbox = FreestyleSandbox({ cwd: "/workspace" });
123
+ *
124
+ * // Auto-create from a snapshot
125
+ * const sandbox = FreestyleSandbox({
126
+ * snapshotId: "abc123",
127
+ * cwd: "/workspace",
128
+ * });
129
+ *
130
+ * // Explicit — attach to pre-existing VM
131
+ * const sandbox = FreestyleSandbox({ vm: existingVm });
132
+ * ```
133
+ */
134
+ declare function FreestyleSandbox(opts: FreestyleSandboxOptions): Sandbox;
135
+
136
+ interface FreestyleFsOptions {
137
+ /** A Freestyle VM instance. */
138
+ vm: FreestyleVmInstance;
139
+ /** Working directory for relative path resolution. */
140
+ workingDir?: string;
141
+ }
142
+ /**
143
+ * VirtualFs backed by a Freestyle VM.
144
+ *
145
+ * Uses `vm.fs.*` for operations with native SDK support (readTextFile,
146
+ * writeTextFile, readDir) and falls back to `vm.exec()` for the rest
147
+ * (stat, exists, mkdir, deleteFile, appendFile, readFileBytes).
148
+ *
149
+ * Requires `freestyle-sandboxes` as an optional peer dependency.
150
+ * The user is responsible for VM lifecycle when using explicit mode.
151
+ */
152
+ declare class FreestyleFs implements VirtualFs {
153
+ private vm;
154
+ private workingDir;
155
+ constructor(opts: FreestyleFsOptions);
156
+ private resolvePath;
157
+ readFile(filePath: string, _opts?: ReadOptions): Promise<string>;
158
+ readFileBytes(filePath: string, maxBytes?: number): Promise<Buffer>;
159
+ writeFile(filePath: string, content: string): Promise<void>;
160
+ appendFile(filePath: string, content: string): Promise<void>;
161
+ deleteFile(filePath: string, opts?: {
162
+ recursive?: boolean;
163
+ }): Promise<void>;
164
+ mkdir(filePath: string, opts?: {
165
+ recursive?: boolean;
166
+ }): Promise<void>;
167
+ readdir(dirPath: string, _opts?: {
168
+ recursive?: boolean;
169
+ }): Promise<FileEntry[]>;
170
+ exists(filePath: string): Promise<boolean>;
171
+ stat(filePath: string): Promise<FileStat>;
172
+ }
173
+
174
+ export { FreestyleComputer, type FreestyleComputerOptions, FreestyleFs, type FreestyleFsOptions, FreestyleSandbox, type FreestyleSandboxOptions, type FreestyleVmInstance };