withruntime 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/E2B.md +32 -32
- package/README.md +8 -5
- package/dist/ai/index.d.ts +21 -5
- package/dist/ai/index.js +14 -21
- package/dist/ai-harness/index.d.ts +194 -0
- package/dist/ai-harness/index.js +517 -0
- package/dist/billing-cli.d.ts +21 -0
- package/dist/billing-cli.js +158 -0
- package/dist/cli-extras.d.ts +15 -0
- package/dist/cli-extras.js +60 -4
- package/dist/cli-name.d.ts +6 -0
- package/dist/cli-name.js +8 -0
- package/dist/cli.d.ts +17 -1
- package/dist/cli.js +537 -130
- package/dist/client.d.ts +35 -6
- package/dist/client.js +23 -0
- package/dist/credentials.js +1 -2
- package/dist/daytona/filesystem.d.ts +2 -0
- package/dist/daytona/filesystem.js +9 -7
- package/dist/e2b/filesystem.js +3 -2
- package/dist/e2b/sandbox.d.ts +9 -6
- package/dist/e2b/sandbox.js +31 -7
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +7 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.js +1 -0
- package/dist/keys.js +1 -1
- package/dist/login.d.ts +2 -6
- package/dist/login.js +3 -8
- package/dist/network-cli.d.ts +1 -1
- package/dist/network-cli.js +64 -2
- package/dist/products/billing.d.ts +35 -0
- package/dist/products/billing.js +13 -0
- package/dist/products/index.d.ts +4 -1
- package/dist/products/index.js +4 -1
- package/dist/products/network-products.d.ts +45 -0
- package/dist/products/network-products.js +27 -0
- package/dist/products/previews.d.ts +1 -2
- package/dist/products/secrets.d.ts +14 -0
- package/dist/sandbox.d.ts +17 -3
- package/dist/sandbox.js +233 -62
- package/dist/transport.d.ts +17 -1
- package/dist/transport.js +124 -7
- package/dist/types.d.ts +0 -2
- package/dist/wallet.d.ts +30 -0
- package/dist/wallet.js +48 -0
- package/package.json +44 -17
package/E2B.md
CHANGED
|
@@ -50,38 +50,38 @@ machine. An E2B key (`e2b_...`) is never sent anywhere. If one is passed as
|
|
|
50
50
|
|
|
51
51
|
## Mapping
|
|
52
52
|
|
|
53
|
-
| E2B | On Runtime
|
|
54
|
-
| ---------------------------------------------------------------------------------------- |
|
|
55
|
-
| `Sandbox.create()`, `Sandbox.create(template, opts)` | `sandboxes.create`. `base` and `code-interpreter-v1` are Runtime's stock image. Any other name must be a ready Runtime image with that name. A UUID is an image or a snapshot.
|
|
56
|
-
| `timeoutMs` (Python `timeout`, seconds) | `timeoutSeconds`, rounded up. Under 60 s becomes 60 s, with a warning. Over an hour is refused.
|
|
57
|
-
| `metadata` | labels (at most 32).
|
|
58
|
-
| `envs` | Given to every command and code run through this object.
|
|
59
|
-
| `allowInternetAccess: false` | `network: { internet: false }`.
|
|
60
|
-
| `lifecycle.onTimeout` | `onLeaseEnd`: `kill` is `stop`, `pause` is `pause`.
|
|
61
|
-
| `commands.run(cmd, { cwd, envs, timeoutMs, onStdout, onStderr })` | `exec`, streamed, so the whole output comes back however large. Default timeout 60 s. `0` means no limit (Runtime's longest, 24 hours).
|
|
62
|
-
| Non-zero exit | Throws `CommandExitError` with `exitCode`, `stdout`, `stderr` and `error` (`exit status N`). A command killed by a signal has `exitCode` -1.
|
|
63
|
-
| Command past its timeout | Throws `TimeoutError`.
|
|
64
|
-
| `commands.run(cmd, { background: true })` | `spawn`. Returns a `CommandHandle` with `pid`, `wait()`, `kill()` (SIGKILL), `sendStdin`, `closeStdin`, `disconnect`, `stdout`, `stderr`, `exitCode`.
|
|
65
|
-
| `commands.list`, `kill(pid)`, `sendStdin(pid)`, `closeStdin(pid)`, `connect(pid)` | Runtime's processes. A pid is a number derived from Runtime's process id, not the Linux pid.
|
|
66
|
-
| `files.read(path, { format })` | `files.read`. `text`, `bytes`, `blob` and `stream` (Python: `text`, `bytes`, `stream`).
|
|
67
|
-
| `files.write(path, data)`, `write([...])`, `writeFiles` | `files.write`. Parent directories are made, and a file that exists is replaced.
|
|
68
|
-
| `files.list(path, { depth })` | `files.list`, hidden files included. `owner` and `group` are always `""`.
|
|
69
|
-
| `files.makeDir`, `exists`, `getInfo`, `rename`, `remove` | `files.stat`, `mkdir`, `rename` (replacing a file that exists) and `remove` (recursive). A missing file throws `FileNotFoundError`.
|
|
70
|
-
| Relative paths | Resolved against the home directory, `/workspace` on Runtime.
|
|
71
|
-
| `/home/user` (E2B's home) | The first time a path, `cwd` or command names it, it becomes a link to `/workspace`, unless something is already there.
|
|
72
|
-
| `sandbox.kill()`, `Sandbox.kill(id)` | `stop`, without waiting. `false` when the sandbox was not found or had already ended.
|
|
73
|
-
| `sandbox.setTimeout(ms)`, `Sandbox.setTimeout(id, ms)` | `extend`: the end moves to now + ms. Moving it earlier is refused.
|
|
74
|
-
| `Sandbox.connect(id, { timeoutMs })`, `sandbox.connect()` | `get`. A paused sandbox is woken. A running one's end moves later, never earlier. An ended one throws `SandboxNotFoundError`.
|
|
75
|
-
| `sandbox.pause()`, `betaPause`, `Sandbox.pause(id)` | `pause`, keeping memory and files. `false` when it was already paused.
|
|
76
|
-
| `getInfo`, `isRunning` | `get`. `templateId` is `base` or the image or snapshot id. `envdVersion` is `runtime`.
|
|
77
|
-
| `Sandbox.list({ query: { metadata, state }, limit })` | `sandboxes.list` by labels and state, oldest first, with E2B's paginator (`hasNext`, `nextItems()`).
|
|
78
|
-
| `fork`, `createSnapshot`, `deleteSnapshot` | Runtime's forks and snapshots. While Runtime has them switched off, they throw `NotSupportedError` with Runtime's own message.
|
|
79
|
-
| `getHost(port)` |
|
|
80
|
-
| `runCode(code, { language, context, onStdout, onStderr, onResult, onError, timeoutMs })` | Runtime's interpreter, Python and JavaScript. The sandbox's `envs` reach code through a context made once for them. `onResult` is called after the run ends.
|
|
81
|
-
| `Execution`, `Result`, `Logs`, `ExecutionError`, `OutputMessage` | The same shapes. Results that are too large to send inline are fetched and inlined. `logs.stdout` has one entry per line.
|
|
82
|
-
| `createCodeContext`, `listCodeContexts`, `restartCodeContext`, `removeCodeContext` | Runtime's interpreter contexts.
|
|
83
|
-
| `getMetrics({ start, end })`, `Sandbox.getMetrics(id)` | Runtime's measured CPU and memory, one entry per host reading (every minute by default). `diskUsed` is null: Runtime does not read disk use inside the sandbox.
|
|
84
|
-
| Error classes | E2B's names and parents. Each also carries Runtime's `code`, `hint` and `requestId`, with the original error as `cause`.
|
|
53
|
+
| E2B | On Runtime |
|
|
54
|
+
| ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
55
|
+
| `Sandbox.create()`, `Sandbox.create(template, opts)` | `sandboxes.create`. `base` and `code-interpreter-v1` are Runtime's stock image. Any other name must be a ready Runtime image with that name. A UUID is an image or a snapshot. |
|
|
56
|
+
| `timeoutMs` (Python `timeout`, seconds) | `timeoutSeconds`, rounded up. Under 60 s becomes 60 s, with a warning. Over an hour is refused. |
|
|
57
|
+
| `metadata` | labels (at most 32). |
|
|
58
|
+
| `envs` | Given to every command and code run through this object. |
|
|
59
|
+
| `allowInternetAccess: false` | `network: { internet: false }`. |
|
|
60
|
+
| `lifecycle.onTimeout` | `onLeaseEnd`: `kill` is `stop`, `pause` is `pause`. |
|
|
61
|
+
| `commands.run(cmd, { cwd, envs, timeoutMs, onStdout, onStderr })` | `exec`, streamed, so the whole output comes back however large. Default timeout 60 s. `0` means no limit (Runtime's longest, 24 hours). |
|
|
62
|
+
| Non-zero exit | Throws `CommandExitError` with `exitCode`, `stdout`, `stderr` and `error` (`exit status N`). A command killed by a signal has `exitCode` -1. |
|
|
63
|
+
| Command past its timeout | Throws `TimeoutError`. |
|
|
64
|
+
| `commands.run(cmd, { background: true })` | `spawn`. Returns a `CommandHandle` with `pid`, `wait()`, `kill()` (SIGKILL), `sendStdin`, `closeStdin`, `disconnect`, `stdout`, `stderr`, `exitCode`. |
|
|
65
|
+
| `commands.list`, `kill(pid)`, `sendStdin(pid)`, `closeStdin(pid)`, `connect(pid)` | Runtime's processes. A pid is a number derived from Runtime's process id, not the Linux pid. |
|
|
66
|
+
| `files.read(path, { format })` | `files.read`. `text`, `bytes`, `blob` and `stream` (Python: `text`, `bytes`, `stream`). |
|
|
67
|
+
| `files.write(path, data)`, `write([...])`, `writeFiles` | `files.write`. Parent directories are made, and a file that exists is replaced. |
|
|
68
|
+
| `files.list(path, { depth })` | `files.list`, hidden files included. `owner` and `group` are always `""`. |
|
|
69
|
+
| `files.makeDir`, `exists`, `getInfo`, `rename`, `remove` | `files.stat`, `mkdir`, `rename` (replacing a file that exists) and `remove` (recursive). A missing file throws `FileNotFoundError`. |
|
|
70
|
+
| Relative paths | Resolved against the home directory, `/workspace` on Runtime. |
|
|
71
|
+
| `/home/user` (E2B's home) | The first time a path, `cwd` or command names it, it becomes a link to `/workspace`, unless something is already there. |
|
|
72
|
+
| `sandbox.kill()`, `Sandbox.kill(id)` | `stop`, without waiting. `false` when the sandbox was not found or had already ended. |
|
|
73
|
+
| `sandbox.setTimeout(ms)`, `Sandbox.setTimeout(id, ms)` | `extend`: the end moves to now + ms. Moving it earlier is refused. |
|
|
74
|
+
| `Sandbox.connect(id, { timeoutMs })`, `sandbox.connect()` | `get`. A paused sandbox is woken. A running one's end moves later, never earlier. An ended one throws `SandboxNotFoundError`. |
|
|
75
|
+
| `sandbox.pause()`, `betaPause`, `Sandbox.pause(id)` | `pause`, keeping memory and files. `false` when it was already paused. |
|
|
76
|
+
| `getInfo`, `isRunning` | `get`. `templateId` is `base` or the image or snapshot id. `envdVersion` is `runtime`. |
|
|
77
|
+
| `Sandbox.list({ query: { metadata, state }, limit })` | `sandboxes.list` by labels and state, oldest first, with E2B's paginator (`hasNext`, `nextItems()`). |
|
|
78
|
+
| `fork`, `createSnapshot`, `deleteSnapshot` | Runtime's forks and snapshots. While Runtime has them switched off, they throw `NotSupportedError` with Runtime's own message. |
|
|
79
|
+
| `getHost(port)` | `<port>-<id>.runtimehost.com` at once, as E2B answers it, and the port is shared as a public Runtime preview beside the caller (the sync Python sandbox shares it before returning). `await sandbox.getPublicHost(port)` returns once the share has landed. |
|
|
80
|
+
| `runCode(code, { language, context, onStdout, onStderr, onResult, onError, timeoutMs })` | Runtime's interpreter, Python and JavaScript. The sandbox's `envs` reach code through a context made once for them. `onResult` is called after the run ends. |
|
|
81
|
+
| `Execution`, `Result`, `Logs`, `ExecutionError`, `OutputMessage` | The same shapes. Results that are too large to send inline are fetched and inlined. `logs.stdout` has one entry per line. |
|
|
82
|
+
| `createCodeContext`, `listCodeContexts`, `restartCodeContext`, `removeCodeContext` | Runtime's interpreter contexts. |
|
|
83
|
+
| `getMetrics({ start, end })`, `Sandbox.getMetrics(id)` | Runtime's measured CPU and memory, one entry per host reading (every minute by default). `diskUsed` is null: Runtime does not read disk use inside the sandbox. |
|
|
84
|
+
| Error classes | E2B's names and parents. Each also carries Runtime's `code`, `hint` and `requestId`, with the original error as `cause`. |
|
|
85
85
|
|
|
86
86
|
## Gaps
|
|
87
87
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Runtime Cloud SDK and CLI
|
|
2
2
|
|
|
3
|
-
One client for every Runtime Cloud product, and the `runtime` CLI. Node.js
|
|
4
|
-
or later, or Bun. Its one dependency, undici (Node's own HTTP client), is
|
|
3
|
+
One client for every Runtime Cloud product, and the `runtime` CLI. Node.js
|
|
4
|
+
22.12 or later, or Bun. Its one dependency, undici (Node's own HTTP client), is
|
|
5
5
|
loaded only behind a proxy.
|
|
6
6
|
|
|
7
7
|
```bash no-run
|
|
@@ -27,7 +27,7 @@ console.log(result.exitCode, result.stdout);
|
|
|
27
27
|
`Sandbox.create()` needs no arguments and returns once the sandbox is running;
|
|
28
28
|
`await using` stops it when the block ends (Node 24, Bun or TypeScript; on
|
|
29
29
|
Node 22 call `await sbx.stop()`). With no arguments you get the free
|
|
30
|
-
trial while it lasts (
|
|
30
|
+
trial while it lasts (100 free hours, up to eight sandboxes running at once), 2 vCPU, 4 GiB of
|
|
31
31
|
memory and a 4 GiB disk. The current default image includes NumPy, pandas and
|
|
32
32
|
matplotlib; see the [sandbox environment](https://withruntime.com/docs/sandbox-environment).
|
|
33
33
|
|
|
@@ -110,7 +110,9 @@ package list every mapping and gap.
|
|
|
110
110
|
## Agent frameworks
|
|
111
111
|
|
|
112
112
|
`withruntime/openai-agents` is a sandbox client for the OpenAI Agents SDK's
|
|
113
|
-
`SandboxAgent`. `withruntime/ai`
|
|
113
|
+
`SandboxAgent`. `withruntime/ai-harness` is a sandbox provider for the Vercel
|
|
114
|
+
AI SDK's `HarnessAgent` (Claude Code, Codex, OpenCode, Pi and the rest).
|
|
115
|
+
`withruntime/ai` gives Vercel AI SDK and Mastra agents four
|
|
114
116
|
sandbox tools, `withruntime/claude-agent-sdk` gives them to the Claude Agent
|
|
115
117
|
SDK as an MCP server, and `withruntime/tools` gives them in no framework's
|
|
116
118
|
format. Each needs its framework installed beside this package. See
|
|
@@ -143,4 +145,5 @@ the browser, or send a bearer key.
|
|
|
143
145
|
Docs: https://withruntime.com/docs/javascript and https://withruntime.com/docs/cli.
|
|
144
146
|
|
|
145
147
|
The package was called `@withruntime/cloud` until 0.3.0. That name, and
|
|
146
|
-
`runtime-cloud` and `withruntime-cloud`,
|
|
148
|
+
`runtime-cloud` and `withruntime-cloud`, stopped at 0.5.1 and get no new
|
|
149
|
+
releases.
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -9,21 +9,37 @@
|
|
|
9
9
|
* await generateText({ model, tools: runtimeTools(sbx), stopWhen: stepCountIs(10), prompt });
|
|
10
10
|
*
|
|
11
11
|
* Needs the `ai` package (version 5 or newer) beside this one. */
|
|
12
|
-
import { type
|
|
12
|
+
import { type Schema } from "ai";
|
|
13
13
|
import type { Sandbox } from "../sandbox.js";
|
|
14
14
|
import { type ExecInput, type ExecOutput, type ListEntry, type SandboxToolOptions } from "../tools/index.js";
|
|
15
15
|
export type { SandboxToolOptions } from "../tools/index.js";
|
|
16
|
+
/** One tool, typed so that both the AI SDK's `tools` and Mastra's accept it.
|
|
17
|
+
*
|
|
18
|
+
* ai 7's own `Tool` type is not assignable to Mastra's `tools` (checked with
|
|
19
|
+
* @mastra/core 1.71.0): ai 7 lets a description be a function, forbids an `id`
|
|
20
|
+
* and wants `context` in the call options, and Mastra wants a string
|
|
21
|
+
* description, an `id` or the older `parameters` field, and passes no
|
|
22
|
+
* `context`. This shape is the part both agree on. `parameters` is the same
|
|
23
|
+
* schema object as `inputSchema`: Mastra reads whichever it finds and the AI
|
|
24
|
+
* SDK reads only `inputSchema`. */
|
|
25
|
+
export type RuntimeTool<I, O> = {
|
|
26
|
+
type?: undefined;
|
|
27
|
+
description: string;
|
|
28
|
+
inputSchema: Schema<I>;
|
|
29
|
+
parameters: Schema<I>;
|
|
30
|
+
execute: (input: I, options?: unknown) => Promise<O>;
|
|
31
|
+
};
|
|
16
32
|
/** `{ runtime_exec, runtime_read_file, runtime_write_file, runtime_list_files }`, bound to `sandbox`. */
|
|
17
33
|
export type RuntimeTools = {
|
|
18
|
-
runtime_exec:
|
|
19
|
-
runtime_read_file:
|
|
34
|
+
runtime_exec: RuntimeTool<ExecInput, ExecOutput>;
|
|
35
|
+
runtime_read_file: RuntimeTool<{
|
|
20
36
|
path: string;
|
|
21
37
|
}, string>;
|
|
22
|
-
runtime_write_file:
|
|
38
|
+
runtime_write_file: RuntimeTool<{
|
|
23
39
|
path: string;
|
|
24
40
|
content: string;
|
|
25
41
|
}, string>;
|
|
26
|
-
runtime_list_files:
|
|
42
|
+
runtime_list_files: RuntimeTool<{
|
|
27
43
|
path?: string;
|
|
28
44
|
depth?: number;
|
|
29
45
|
}, ListEntry[] | {
|
package/dist/ai/index.js
CHANGED
|
@@ -9,30 +9,23 @@
|
|
|
9
9
|
* await generateText({ model, tools: runtimeTools(sbx), stopWhen: stepCountIs(10), prompt });
|
|
10
10
|
*
|
|
11
11
|
* Needs the `ai` package (version 5 or newer) beside this one. */
|
|
12
|
-
import { jsonSchema
|
|
12
|
+
import { jsonSchema } from "ai";
|
|
13
13
|
import { sandboxTools, } from "../tools/index.js";
|
|
14
|
+
function aiTool(source) {
|
|
15
|
+
const schema = jsonSchema(source.inputSchema);
|
|
16
|
+
return {
|
|
17
|
+
description: source.description,
|
|
18
|
+
inputSchema: schema,
|
|
19
|
+
parameters: schema,
|
|
20
|
+
execute: (input) => source.execute(input),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
14
23
|
export function runtimeTools(sandbox, options = {}) {
|
|
15
24
|
const [exec, read, write, list] = sandboxTools(sandbox, options);
|
|
16
25
|
return {
|
|
17
|
-
runtime_exec:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}),
|
|
22
|
-
runtime_read_file: tool({
|
|
23
|
-
description: read.description,
|
|
24
|
-
inputSchema: jsonSchema(read.inputSchema),
|
|
25
|
-
execute: (input) => read.execute(input),
|
|
26
|
-
}),
|
|
27
|
-
runtime_write_file: tool({
|
|
28
|
-
description: write.description,
|
|
29
|
-
inputSchema: jsonSchema(write.inputSchema),
|
|
30
|
-
execute: (input) => write.execute(input),
|
|
31
|
-
}),
|
|
32
|
-
runtime_list_files: tool({
|
|
33
|
-
description: list.description,
|
|
34
|
-
inputSchema: jsonSchema(list.inputSchema),
|
|
35
|
-
execute: (input) => list.execute(input),
|
|
36
|
-
}),
|
|
26
|
+
runtime_exec: aiTool(exec),
|
|
27
|
+
runtime_read_file: aiTool(read),
|
|
28
|
+
runtime_write_file: aiTool(write),
|
|
29
|
+
runtime_list_files: aiTool(list),
|
|
37
30
|
};
|
|
38
31
|
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/** Runtime Cloud sandboxes for the Vercel AI SDK's harnesses (`@ai-sdk/harness`).
|
|
2
|
+
*
|
|
3
|
+
* `createRuntimeSandbox()` is a `HarnessV1SandboxProvider`, like
|
|
4
|
+
* `@ai-sdk/sandbox-vercel`'s `createVercelSandbox()`: a `HarnessAgent` runs its
|
|
5
|
+
* harness (Claude Code, Codex, OpenCode, Pi, ...) in a Runtime microVM, and
|
|
6
|
+
* the agent definition does not change:
|
|
7
|
+
*
|
|
8
|
+
* import { HarnessAgent } from "@ai-sdk/harness/agent";
|
|
9
|
+
* import { claudeCode } from "@ai-sdk/harness-claude-code";
|
|
10
|
+
* import { createRuntimeSandbox } from "withruntime/ai-harness";
|
|
11
|
+
*
|
|
12
|
+
* const agent = new HarnessAgent({
|
|
13
|
+
* harness: claudeCode,
|
|
14
|
+
* sandbox: createRuntimeSandbox({ ports: [4000], create: { funding: "trial" } }),
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* Commands run under `bash -c` as the sandbox user, streamed. Exposed ports
|
|
18
|
+
* are Runtime previews, private by default: the endpoint carries the preview
|
|
19
|
+
* token. The key comes from RUNTIME_API_KEY or this machine's `runtime login`.
|
|
20
|
+
* Needs `@ai-sdk/harness` 1.x beside this package. */
|
|
21
|
+
import { type HarnessV1NetworkPolicy, type HarnessV1NetworkSandboxSession, type HarnessV1PortEndpoint, type HarnessV1SandboxProvider } from "@ai-sdk/harness";
|
|
22
|
+
import { Runtime } from "../client.js";
|
|
23
|
+
import type { NetworkRules } from "../products/network.js";
|
|
24
|
+
import type { Sandbox } from "../sandbox.js";
|
|
25
|
+
import type { CreateSandbox } from "../types.js";
|
|
26
|
+
/** The AI SDK's plain sandbox session (files, `run`, `spawn`), as the harness
|
|
27
|
+
* package declares it. */
|
|
28
|
+
export type SandboxSession = ReturnType<HarnessV1NetworkSandboxSession["restricted"]>;
|
|
29
|
+
export type SandboxProcess = Awaited<ReturnType<SandboxSession["spawn"]>>;
|
|
30
|
+
type ProcessOptions = Parameters<SandboxSession["run"]>[0];
|
|
31
|
+
/** What `run` and `spawn` take beyond the AI SDK's options. The harness never
|
|
32
|
+
* passes these; code that holds the session may. */
|
|
33
|
+
export type RuntimeProcessOptions = ProcessOptions & {
|
|
34
|
+
/** Given to standard input, then closed. `spawn` takes text only. */
|
|
35
|
+
stdin?: string | Uint8Array;
|
|
36
|
+
/** The longest the command may run; this session's `commandTimeoutMs` when left out. */
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
};
|
|
39
|
+
export declare const PROVIDER_ID = "runtime-sandbox";
|
|
40
|
+
/** The preview token's header. The edge also takes it as `runtime_preview_token` in the query. */
|
|
41
|
+
export declare const PREVIEW_TOKEN_HEADER = "x-runtime-preview-token";
|
|
42
|
+
export type RuntimeSandboxSettings = {
|
|
43
|
+
/** The client to use. Default: one from RUNTIME_API_KEY or this machine's `runtime login`. */
|
|
44
|
+
runtime?: Runtime;
|
|
45
|
+
/** Wrap a sandbox you created. You own it: the session's `stop()` and
|
|
46
|
+
* `destroy()` leave it running, and `create` is not used. */
|
|
47
|
+
sandbox?: Sandbox;
|
|
48
|
+
/** How to create each session's sandbox: `funding`, `image`, `snapshot`,
|
|
49
|
+
* `region`, `vcpu`, `memoryMiB`, `timeoutSeconds`, `network`, `labels`, ...
|
|
50
|
+
* With a harness session id the sandbox is named after it (for
|
|
51
|
+
* `resumeSession`), and that name wins over `create.name`. */
|
|
52
|
+
create?: CreateSandbox;
|
|
53
|
+
/** Set for every command, under the command's own `env`. Runtime's create
|
|
54
|
+
* takes no environment, so the provider holds it. */
|
|
55
|
+
env?: Record<string, string>;
|
|
56
|
+
/** Ports to share as previews. Bridge harnesses (Claude Code, Codex,
|
|
57
|
+
* OpenCode, Deep Agents) use the first one. */
|
|
58
|
+
ports?: number[];
|
|
59
|
+
/** `private` (default): the endpoint carries a preview token. `public`:
|
|
60
|
+
* anyone with the address; a browser sees a one-time warning page. */
|
|
61
|
+
previewVisibility?: "private" | "public";
|
|
62
|
+
/** How long each endpoint's token lasts, 60 s to 7 days. Default: the API's (1 day). */
|
|
63
|
+
previewTtlSeconds?: number;
|
|
64
|
+
/** The longest a `run` command may take. Default one hour; 24 hours at most. */
|
|
65
|
+
commandTimeoutMs?: number;
|
|
66
|
+
/** `stop()` pauses the sandbox instead of stopping it, so `resumeSession`
|
|
67
|
+
* wakes the same machine with its files, memory and processes. A paused
|
|
68
|
+
* sandbox is billed as paused storage until it is woken or stopped.
|
|
69
|
+
* Default false. `destroy()` always stops. */
|
|
70
|
+
pauseOnStop?: boolean;
|
|
71
|
+
};
|
|
72
|
+
/** A harness sandbox provider backed by Runtime Cloud. Construct it once, at
|
|
73
|
+
* module scope; nothing is created until a session is. */
|
|
74
|
+
export declare function createRuntimeSandbox(settings?: RuntimeSandboxSettings): RuntimeSandboxProvider;
|
|
75
|
+
/** The sandbox name a harness session id maps to: `ai-harness-<id>`, or a
|
|
76
|
+
* digest of the id when it would not make a valid name. */
|
|
77
|
+
export declare function sessionSandboxName(sessionId: string): Promise<string>;
|
|
78
|
+
export declare class RuntimeSandboxProvider implements HarnessV1SandboxProvider {
|
|
79
|
+
#private;
|
|
80
|
+
private readonly settings;
|
|
81
|
+
readonly specificationVersion: "harness-sandbox-v1";
|
|
82
|
+
readonly providerId = "runtime-sandbox";
|
|
83
|
+
constructor(settings?: RuntimeSandboxSettings);
|
|
84
|
+
get runtime(): Runtime;
|
|
85
|
+
/** A new sandbox (named after `sessionId` when given), or the wrapped one.
|
|
86
|
+
* `onFirstCreate` runs on a new sandbox before this returns; Runtime keeps
|
|
87
|
+
* no template for `identity`, so it runs for every new sandbox. */
|
|
88
|
+
createSession: (options?: {
|
|
89
|
+
sessionId?: string;
|
|
90
|
+
abortSignal?: AbortSignal;
|
|
91
|
+
identity?: string;
|
|
92
|
+
onFirstCreate?: (session: SandboxSession, opts: {
|
|
93
|
+
abortSignal?: AbortSignal;
|
|
94
|
+
}) => Promise<void>;
|
|
95
|
+
}) => Promise<RuntimeNetworkSandboxSession>;
|
|
96
|
+
/** The sandbox `createSession` made for `sessionId`, woken if it is paused.
|
|
97
|
+
* A stopped one cannot be resumed: its memory and disk are gone. */
|
|
98
|
+
resumeSession: (options: {
|
|
99
|
+
sessionId: string;
|
|
100
|
+
abortSignal?: AbortSignal;
|
|
101
|
+
}) => Promise<RuntimeNetworkSandboxSession>;
|
|
102
|
+
}
|
|
103
|
+
/** Files and processes in one Runtime sandbox: what `restricted()` hands to
|
|
104
|
+
* tools, with nothing that stops the sandbox or changes its network. */
|
|
105
|
+
export declare class RuntimeSandboxSession implements SandboxSession {
|
|
106
|
+
#private;
|
|
107
|
+
readonly sandbox: Sandbox;
|
|
108
|
+
protected readonly settings: Pick<RuntimeSandboxSettings, "env" | "commandTimeoutMs">;
|
|
109
|
+
/** Where relative paths and commands without a `workingDirectory` start. */
|
|
110
|
+
defaultWorkingDirectory: string;
|
|
111
|
+
constructor(sandbox: Sandbox, settings?: Pick<RuntimeSandboxSettings, "env" | "commandTimeoutMs">);
|
|
112
|
+
get description(): string;
|
|
113
|
+
/** Runs `command` under `bash -c` and returns once it exits, with all of
|
|
114
|
+
* its output. A timeout exits 124, with a note on standard error. */
|
|
115
|
+
run: (options: RuntimeProcessOptions) => Promise<{
|
|
116
|
+
exitCode: number;
|
|
117
|
+
stdout: string;
|
|
118
|
+
stderr: string;
|
|
119
|
+
}>;
|
|
120
|
+
/** Starts `command` and returns at once, with its output as streams. */
|
|
121
|
+
spawn: (options: RuntimeProcessOptions) => Promise<SandboxProcess>;
|
|
122
|
+
readBinaryFile: (options: {
|
|
123
|
+
path: string;
|
|
124
|
+
abortSignal?: AbortSignal;
|
|
125
|
+
}) => Promise<Uint8Array | null>;
|
|
126
|
+
readFile: (options: {
|
|
127
|
+
path: string;
|
|
128
|
+
abortSignal?: AbortSignal;
|
|
129
|
+
}) => Promise<ReadableStream<Uint8Array> | null>;
|
|
130
|
+
readTextFile: (options: {
|
|
131
|
+
path: string;
|
|
132
|
+
encoding?: string;
|
|
133
|
+
startLine?: number;
|
|
134
|
+
endLine?: number;
|
|
135
|
+
abortSignal?: AbortSignal;
|
|
136
|
+
}) => Promise<string | null>;
|
|
137
|
+
/** Writes atomically, making parent directories. Past 1 MiB a file must be under /workspace. */
|
|
138
|
+
writeBinaryFile: (options: {
|
|
139
|
+
path: string;
|
|
140
|
+
content: Uint8Array;
|
|
141
|
+
abortSignal?: AbortSignal;
|
|
142
|
+
}) => Promise<void>;
|
|
143
|
+
writeFile: (options: {
|
|
144
|
+
path: string;
|
|
145
|
+
content: ReadableStream<Uint8Array>;
|
|
146
|
+
abortSignal?: AbortSignal;
|
|
147
|
+
}) => Promise<void>;
|
|
148
|
+
writeTextFile: (options: {
|
|
149
|
+
path: string;
|
|
150
|
+
content: string;
|
|
151
|
+
encoding?: string;
|
|
152
|
+
abortSignal?: AbortSignal;
|
|
153
|
+
}) => Promise<void>;
|
|
154
|
+
}
|
|
155
|
+
/** The session a harness keeps: files and processes, plus ports as previews,
|
|
156
|
+
* network rules, and stopping. */
|
|
157
|
+
export declare class RuntimeNetworkSandboxSession extends RuntimeSandboxSession implements HarnessV1NetworkSandboxSession {
|
|
158
|
+
#private;
|
|
159
|
+
protected readonly settings: RuntimeSandboxSettings;
|
|
160
|
+
readonly ownsLifecycle: boolean;
|
|
161
|
+
constructor(sandbox: Sandbox, settings: RuntimeSandboxSettings, ownsLifecycle: boolean);
|
|
162
|
+
/** The sandbox's id: `resumeSession` finds it again by the name it was given. */
|
|
163
|
+
get id(): string;
|
|
164
|
+
get ports(): ReadonlyArray<number>;
|
|
165
|
+
get description(): string;
|
|
166
|
+
restricted: () => SandboxSession;
|
|
167
|
+
/** Where to reach `port`. A private preview's token is in the URL's query and
|
|
168
|
+
* in `headers`. For `ws` the URL has no token: the preview edge answers a GET
|
|
169
|
+
* whose query carries one with a redirect that sets a cookie, which a
|
|
170
|
+
* WebSocket client does not follow, so the header carries it. */
|
|
171
|
+
getPortEndpoint: (options: {
|
|
172
|
+
port: number;
|
|
173
|
+
protocol?: "http" | "https" | "ws";
|
|
174
|
+
}) => Promise<HarnessV1PortEndpoint>;
|
|
175
|
+
/** @deprecated As the AI SDK's: use `getPortEndpoint`. The URL carries the token in its query. */
|
|
176
|
+
getPortUrl: (options: {
|
|
177
|
+
port: number;
|
|
178
|
+
protocol?: "http" | "https" | "ws";
|
|
179
|
+
}) => Promise<string>;
|
|
180
|
+
/** Shares exactly `ports`: new ones become previews, dropped ones stop being shared. */
|
|
181
|
+
setPorts: (ports: ReadonlyArray<number>, options?: {
|
|
182
|
+
abortSignal?: AbortSignal;
|
|
183
|
+
}) => Promise<void>;
|
|
184
|
+
/** Outbound rules: `allow-all` is the public web, `deny-all` nothing, and
|
|
185
|
+
* `custom` only the listed hosts and ranges, with `deniedCIDRs` refused. */
|
|
186
|
+
setNetworkPolicy: (policy: HarnessV1NetworkPolicy) => Promise<void>;
|
|
187
|
+
/** Stops the sandbox (or pauses it, with `pauseOnStop`). A wrapped sandbox is left alone. */
|
|
188
|
+
stop: () => Promise<void>;
|
|
189
|
+
/** Stops the sandbox, whatever `pauseOnStop` says: its files and memory are gone. */
|
|
190
|
+
destroy: () => Promise<void>;
|
|
191
|
+
}
|
|
192
|
+
/** The harness's network policy as a Runtime sandbox's network rules. */
|
|
193
|
+
export declare function networkRules(policy: HarnessV1NetworkPolicy): NetworkRules;
|
|
194
|
+
export {};
|