withruntime 0.4.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 (87) hide show
  1. package/DAYTONA.md +129 -0
  2. package/E2B.md +2 -2
  3. package/README.md +47 -9
  4. package/VERCEL.md +127 -0
  5. package/dist/ai/index.d.ts +33 -0
  6. package/dist/ai/index.js +38 -0
  7. package/dist/claude-agent-sdk/index.d.ts +7 -0
  8. package/dist/claude-agent-sdk/index.js +65 -0
  9. package/dist/cli.d.ts +6 -0
  10. package/dist/cli.js +939 -102
  11. package/dist/client.d.ts +25 -2
  12. package/dist/client.js +14 -1
  13. package/dist/credentials.d.ts +10 -0
  14. package/dist/credentials.js +56 -1
  15. package/dist/daytona/client.d.ts +44 -0
  16. package/dist/daytona/client.js +40 -0
  17. package/dist/daytona/context.d.ts +26 -0
  18. package/dist/daytona/context.js +22 -0
  19. package/dist/daytona/daytona.d.ts +185 -0
  20. package/dist/daytona/daytona.js +416 -0
  21. package/dist/daytona/errors.d.ts +106 -0
  22. package/dist/daytona/errors.js +182 -0
  23. package/dist/daytona/filesystem.d.ts +84 -0
  24. package/dist/daytona/filesystem.js +206 -0
  25. package/dist/daytona/git.d.ts +33 -0
  26. package/dist/daytona/git.js +128 -0
  27. package/dist/daytona/image.d.ts +45 -0
  28. package/dist/daytona/image.js +140 -0
  29. package/dist/daytona/index.d.ts +50 -0
  30. package/dist/daytona/index.js +50 -0
  31. package/dist/daytona/process.d.ts +86 -0
  32. package/dist/daytona/process.js +339 -0
  33. package/dist/daytona/sandbox.d.ts +196 -0
  34. package/dist/daytona/sandbox.js +448 -0
  35. package/dist/e2b/sandbox.d.ts +22 -2
  36. package/dist/e2b/sandbox.js +39 -7
  37. package/dist/errors.d.ts +10 -4
  38. package/dist/errors.js +26 -6
  39. package/dist/image-context.d.ts +39 -0
  40. package/dist/image-context.js +176 -0
  41. package/dist/index.d.ts +19 -2
  42. package/dist/index.js +17 -2
  43. package/dist/keys.d.ts +43 -0
  44. package/dist/keys.js +196 -0
  45. package/dist/login.js +14 -2
  46. package/dist/openai-agents/index.d.ts +132 -0
  47. package/dist/openai-agents/index.js +791 -0
  48. package/dist/products/audit.d.ts +48 -0
  49. package/dist/products/audit.js +10 -0
  50. package/dist/products/images.d.ts +113 -7
  51. package/dist/products/images.js +186 -27
  52. package/dist/products/index.d.ts +11 -0
  53. package/dist/products/index.js +17 -1
  54. package/dist/products/observability.d.ts +186 -0
  55. package/dist/products/observability.js +117 -0
  56. package/dist/products/secrets.d.ts +40 -0
  57. package/dist/products/secrets.js +24 -0
  58. package/dist/products/switching.d.ts +89 -0
  59. package/dist/products/switching.js +25 -0
  60. package/dist/sandbox.d.ts +26 -1
  61. package/dist/sandbox.js +101 -1
  62. package/dist/ssh.d.ts +21 -0
  63. package/dist/ssh.js +312 -0
  64. package/dist/tar.d.ts +1 -0
  65. package/dist/tar.js +4 -4
  66. package/dist/tools/index.d.ts +62 -0
  67. package/dist/tools/index.js +180 -0
  68. package/dist/transport.d.ts +12 -2
  69. package/dist/transport.js +31 -4
  70. package/dist/tunnel.d.ts +67 -0
  71. package/dist/tunnel.js +311 -0
  72. package/dist/types.d.ts +57 -1
  73. package/dist/vercel/client.d.ts +40 -0
  74. package/dist/vercel/client.js +39 -0
  75. package/dist/vercel/command.d.ts +70 -0
  76. package/dist/vercel/command.js +148 -0
  77. package/dist/vercel/errors.d.ts +53 -0
  78. package/dist/vercel/errors.js +113 -0
  79. package/dist/vercel/filesystem.d.ts +150 -0
  80. package/dist/vercel/filesystem.js +248 -0
  81. package/dist/vercel/index.d.ts +30 -0
  82. package/dist/vercel/index.js +38 -0
  83. package/dist/vercel/sandbox.d.ts +317 -0
  84. package/dist/vercel/sandbox.js +726 -0
  85. package/dist/vercel/snapshot.d.ts +93 -0
  86. package/dist/vercel/snapshot.js +123 -0
  87. package/package.json +56 -4
package/DAYTONA.md ADDED
@@ -0,0 +1,129 @@
1
+ # Code written for Daytona, on Runtime
2
+
3
+ Run code written for [Daytona](https://www.daytona.io)'s SDK on Runtime Cloud
4
+ by changing one import. It is part of Runtime's SDK (`withruntime`), built on
5
+ the same client, so it gets that SDK's retries, idempotency keys and errors.
6
+ Importing `withruntime` alone does not load it.
7
+
8
+ ```ts no-run
9
+ import { Daytona } from "withruntime/daytona"; // was: from "@daytona/sdk" or "@daytonaio/sdk"
10
+ ```
11
+
12
+ Python has the same, in `pip install withruntime`:
13
+
14
+ ```python no-run
15
+ from withruntime.daytona import Daytona # was: from daytona import Daytona
16
+ from withruntime.daytona import AsyncDaytona # was: from daytona import AsyncDaytona
17
+ ```
18
+
19
+ The mapping was written against `@daytona/sdk` 0.216.1 and `daytona` 0.216.1
20
+ on PyPI, checked 23 September 2026.
21
+
22
+ ## Keys
23
+
24
+ The package uses, in order: a Runtime key (`rtcloud_...`) passed as `apiKey`,
25
+ `RUNTIME_API_KEY`, a Runtime key left in `DAYTONA_API_KEY`, and the key
26
+ `npx withruntime login` saved on this machine. A Daytona key is never sent
27
+ anywhere. If one is passed as `apiKey` and `RUNTIME_API_KEY` is not set, the
28
+ constructor throws `DaytonaAuthenticationError`. `apiUrl` is ignored: the
29
+ package talks only to Runtime.
30
+
31
+ ## What a sandbox gets
32
+
33
+ - **Machine:** Daytona's default, 1 vCPU, 1 GiB memory and 3 GiB disk.
34
+ `resources: { cpu, memory, disk }` (GiB) sets another.
35
+ - **Stopping:** `stop()` pauses the sandbox, keeping its files and its memory,
36
+ and `start()` carries on with processes still running. A stopped sandbox is
37
+ kept for Runtime's retention: 30 days on credit, 7 on the trial, or
38
+ `autoDeleteInterval` minutes rounded up to whole days. `delete()` ends it.
39
+ An `ephemeral` sandbox (or `autoDeleteInterval: 0`) ends on `stop()`.
40
+ - **Auto-stop:** Runtime runs a sandbox on a lease of up to an hour. The lease
41
+ is `autoStopInterval` minutes (default 15; `0` is an hour), and every call
42
+ through the adapter moves it on once less than half is left, so a sandbox
43
+ pauses after that long without calls, as Daytona's does. `ttlMinutes` caps
44
+ the renewals and ends the sandbox at the deadline.
45
+ - **Funding:** left to Runtime, as `withruntime`'s own `create()` does: the free
46
+ trial while the account has trial time, then prepaid credit. Pass
47
+ `withruntime: { create: { funding: "trial" } }` to `new Daytona(...)` or to
48
+ `create` (Python: `runtime_create={"funding": "trial"}`) to use only the
49
+ trial.
50
+ - **Anything else Runtime offers:** `withruntime: { create: { ... } }` sends
51
+ Runtime's create fields as they are. `sandbox.withruntime` is the Runtime
52
+ sandbox underneath, with previews, network rules, snapshots, the desktop and
53
+ terminals.
54
+
55
+ ## Mapping
56
+
57
+ | Daytona | On Runtime |
58
+ | ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
59
+ | `daytona.create()`, `create({ snapshot })` | `sandboxes.create`. Daytona's own snapshots (`daytona-*`) are Runtime's stock image. Any other name is a ready Runtime image of that name, then a Runtime snapshot of that name. |
60
+ | `create({ image: "python:3.12" })` | Built once as a Runtime image from the registry reference (named after it), then reused. `onSnapshotCreateLogs` receives the build log. |
61
+ | `create({ image: Image.debianSlim(...).pipInstall(...)... })` | The Dockerfile Daytona's `Image` stands for, with its local files, built as a Runtime image named after its content and reused. |
62
+ | `resources`, `envVars`, `labels`, `name`, `volumes` | `vcpu`, `memoryMiB`, `diskMiB`; environment given to every command; labels; name; Runtime volumes by id or by name. |
63
+ | `networkBlockAll`, `networkAllowList`, `domainAllowList`, `outboundProxyUrl` | Runtime network rules (`internet: false`, or an `allow` list); the proxy as `HTTP_PROXY` and `HTTPS_PROXY` for commands. |
64
+ | `public: true` | `getPreviewLink(port)` shares the port publicly; without it, privately with a token. |
65
+ | `language` | The language of `codeRun`, kept in Daytona's `code-toolbox-language` label so a sandbox found later keeps it. |
66
+ | `daytona.get(idOrName)`, `daytona.list({ labels, states, name })` | `sandboxes.get`, or the newest live sandbox with that name; `sandboxes.list`. Awaiting `list()` gives the older `{ items, total }` shape. |
67
+ | `process.executeCommand(cmd, cwd, env, timeout)` | `exec` under bash with stderr joined to stdout, as Daytona's `result`. A non-zero exit is a result. Past `timeout` (seconds): `DaytonaProcessExecutionTimeoutError`. |
68
+ | `process.codeRun(code, { argv, env })` | `python3 -c`, `node -e` or `bun -e` by the sandbox's language. `artifacts.charts` is always empty. |
69
+ | `createSession`, `executeSessionCommand`, `getSessionCommandLogs` | One bash per session, kept running: directory, variables and functions carry from one command to the next. `runAsync` returns at once; logs stream to callbacks. |
70
+ | `sendSessionCommandInput`, `getSession`, `getSessionCommand`, `deleteSession` | Input to the session's shell, which the running command reads; the commands sent through this object; killing the shell. |
71
+ | `fs.uploadFile(s)`, `downloadFile(s)`, `listFiles`, `getFileDetails` | Runtime's files API. Relative paths resolve from `/workspace`. `owner` and `group` are always `""`. |
72
+ | `fs.createFolder`, `deleteFile`, `moveFiles`, `setFilePermissions` | `mkdir -m`, `files.remove`, `files.rename`, `chmod` and `sudo chown`. |
73
+ | `fs.findFiles`, `searchFiles`, `replaceInFiles` | `grep -rn`, a files glob, and a read and write of each file. |
74
+ | `git.clone`, `status`, `add`, `commit`, `push`, `pull`, branches | The sandbox's git. Credentials reach git through the environment, never the command line. |
75
+ | `codeInterpreter.runCode`, contexts | Runtime's Python interpreter. The sandbox's `envVars` reach code through a context made once for them. |
76
+ | `start`, `stop`, `pause`, `archive`, `delete`, `fork`, `createSnapshot` | `wake`, `pause` (or `stop` when ephemeral), `pause`, `pause`, `stop`, Runtime's fork with memory, a Runtime snapshot with that name. |
77
+ | `getPreviewLink(port)` | A Runtime preview. Send its token as `x-runtime-preview-token`; Daytona's header is `x-daytona-preview-token`. |
78
+ | `getUserHomeDir`, `getWorkDir`, `user` | `/workspace`, and `daytona`, so `/home/daytona` (linked to `/workspace` the first time something names it) works. |
79
+ | `daytona.snapshot.create`, `get`, `list`, `delete` | Runtime images built, found, listed and deleted by name. |
80
+ | `daytona.volume.get`, `list`, `delete` | Runtime volumes by name. |
81
+ | Error classes | Daytona's names and parents, by HTTP status. Each also carries Runtime's `code`, `hint` and `requestId`, with the original error as `cause`. |
82
+
83
+ ## Gaps
84
+
85
+ Each of these throws `NotSupportedError` before anything happens. Its
86
+ `feature` names the gap and its `alternative` says what to use.
87
+
88
+ | Daytona | Use instead |
89
+ | --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
90
+ | A snapshot name with no Runtime image or snapshot | `daytona.snapshot.create({ name, image })` here, or `npx withruntime image build`. This throws `DaytonaNotFoundError`. |
91
+ | GPUs, `spot`, `linkedSandbox`, `secrets`, `otelEndpointOverride` | Runtime runs Linux on CPUs; pass credentials as `envVars`. |
92
+ | A `target` other than `us`, `jwtToken` | Runtime runs in one US region and signs in with keys. |
93
+ | `user` other than `daytona` | Commands run as the sandbox owner with passwordless `sudo`. |
94
+ | PTY sessions, the entrypoint session, language servers | `sandbox.withruntime.terminal(...)`, and sessions with `runAsync`. |
95
+ | `computerUse` | Runtime's desktop, `sandbox.withruntime.desktop`. |
96
+ | `setLabels`, `resize`, `recover` | Set labels and resources at create; create a new sandbox. |
97
+ | Signed preview URLs, signed upload and download URLs, SSH access | `getPreviewLink`, `fs.uploadFile` and `downloadFile`, `npx withruntime sandbox shell <id>`. |
98
+ | `getMetrics` | `npx withruntime usage`. |
99
+ | `Image.pipInstallFromPyproject`, snapshot `resources` or `entrypoint` | `pipInstallFromRequirements`; resources at create; a session after create. |
100
+ | `volume.create(name)` | Runtime volumes have a size: `runtime.volumes.create({ name, sizeMiB })`. |
101
+ | `secret`, `warmPool` | Credentials as `envVars`; Runtime starts from warm templates already. |
102
+ | `runCode(code, { envs })` | `envVars` at create, or `os.environ` in the code. |
103
+ | Listing by anything but name, labels and states | Filter the result yourself. |
104
+
105
+ Some differences are not refusals:
106
+
107
+ - Sandbox `envVars` live in the object that created the sandbox;
108
+ `daytona.get(id)` from another process does not know them.
109
+ - A session runs one command at a time. A command sent while another runs
110
+ waits for it, as it would typed into a shell. Sessions made by another
111
+ client are found by name, but only their output from then on is known.
112
+ - `autoArchiveInterval` is recorded only: Runtime has no archive tier.
113
+ - Runtime's stock image is Ubuntu 24.04 with Python 3.12, Node.js 24 and Bun.
114
+
115
+ ## Tests
116
+
117
+ `bun run test` in `packages/cloud-sdk` runs the unit tests of both languages
118
+ against fakes of Runtime's SDKs: `tests/daytona` here and
119
+ `sdks/python/tests/test_daytona.py`.
120
+
121
+ The end-to-end tests run Daytona's quickstart and guides, unmodified but for
122
+ the import, against the real API. They refuse to start unless the free trial
123
+ has an hour left, create one sandbox per language and end it. They are not part
124
+ of `bun run test`.
125
+
126
+ ```bash no-run
127
+ bun packages/cloud-sdk/scripts/dropin-e2e.ts # JavaScript, with the Vercel eval
128
+ python3 sdks/python/scripts/dropin_e2e.py # Python, with the Vercel sample
129
+ ```
package/E2B.md CHANGED
@@ -80,6 +80,7 @@ machine. An E2B key (`e2b_...`) is never sent anywhere. If one is passed as
80
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
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
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. |
83
84
  | Error classes | E2B's names and parents. Each also carries Runtime's `code`, `hint` and `requestId`, with the original error as `cause`. |
84
85
 
85
86
  ## Gaps
@@ -94,7 +95,7 @@ before anything happens. The error's `feature` names the gap and its
94
95
  | `Template`, `waitForPort` and the other ready checks | `runtime.images.build(...)` |
95
96
  | `timeoutMs` over one hour | Create with up to an hour, then call `setTimeout` before it ends, as often as needed. |
96
97
  | `setTimeout` to an earlier time | `kill()` when the work is done. |
97
- | `lifecycle.autoResume`, `keepMemory: false` | `Sandbox.connect(id)` wakes a paused sandbox. Runtime's pause keeps memory. |
98
+ | `keepMemory: false` | Runtime's pause keeps memory. |
98
99
  | `onResume: "reboot"` | Stop the sandbox and create a new one. |
99
100
  | `fork({ timeoutMs })` | Fork without it, then call `setTimeout` on each fork. |
100
101
  | `user: "root"` (commands and files) | Prefix the command with `sudo`, which needs no password. |
@@ -106,7 +107,6 @@ before anything happens. The error's `feature` names the gap and its
106
107
  | `git` | `commands.run("git ...")`. E2B has deprecated its git module too. |
107
108
  | `files.watchDir` | Poll with `files.list`. |
108
109
  | File `metadata` | Keep it in a file beside the data. |
109
- | `getMetrics` | `npx withruntime usage`. |
110
110
  | `uploadUrl`, `downloadUrl` | `files.write` and `files.read`. |
111
111
  | `Sandbox.list` by `template` or `startedAfter`, `order: "desc"`, or from a saved `nextToken` | Filter by metadata, and keep the paginator. |
112
112
  | `runCode` in `bash`, `r`, `java` or `typescript` | `commands.run(...)`. |
package/README.md CHANGED
@@ -10,9 +10,11 @@ npm install withruntime
10
10
 
11
11
  The client uses `RUNTIME_API_KEY` when it is set, and otherwise the connection
12
12
  this machine saved when the CLI connected it (one browser approval, no key to
13
- copy). On a server, set `RUNTIME_API_KEY` from your secret manager (create a key
14
- at https://withruntime.com/account/keys). Never put a key in browser code, a URL
15
- or a command-line argument.
13
+ copy). On a server or a CI runner, set `RUNTIME_API_KEY` from your secret
14
+ manager: `npx withruntime keys create` prints a new key once after an account
15
+ owner approves it in the browser, or create one at
16
+ https://withruntime.com/account/keys. Never put a key in browser code, a URL or
17
+ a command-line argument.
16
18
 
17
19
  ```ts
18
20
  import { Sandbox } from "withruntime";
@@ -25,7 +27,7 @@ console.log(result.exitCode, result.stdout);
25
27
  `Sandbox.create()` needs no arguments and returns once the sandbox is running;
26
28
  `await using` stops it when the block ends (Node 24, Bun or TypeScript; on
27
29
  Node 22 call `await sbx.stop()`). With no arguments you get the free
28
- trial while it lasts (20 hours, up to eight sandboxes running at once), 2 vCPU, 4 GiB of
30
+ trial while it lasts (50 free hours, up to eight sandboxes running at once), 2 vCPU, 4 GiB of
29
31
  memory and a 4 GiB disk.
30
32
 
31
33
  The sandbox object does the rest:
@@ -33,11 +35,18 @@ The sandbox object does the rest:
33
35
  - `exec`, `execStream`, `spawn` and `processes` for commands and background
34
36
  work, with `cwd`, `env` (the place for secrets), `stdin` and `timeoutMs`;
35
37
  - `terminal()` for an interactive terminal over a WebSocket;
38
+ - `forwardPort(5432)` to reach any TCP port in the sandbox from this machine, and
39
+ `tunnel()` for single connections and SSH logins (`runtime sandbox ssh` uses it);
36
40
  - `files` to read, write, list, glob, stat, move and remove, and to copy whole
37
41
  directories with `upload` and `download`;
38
- - `pause`, `wake`, `extend`, `fork` and `snapshot`;
42
+ - `pause`, `wake`, `extend`, `fork` and `snapshot` (a paused sandbox also wakes
43
+ by itself on the next call), `update` for its name, automatic wake, idle pause
44
+ and persistence, and `keepAlive` to extend its lease while your process runs;
39
45
  - `interpreter`, `network`, `previews` and `desktop` for the other products.
40
46
 
47
+ `Sandbox.getOrCreate(name)` returns the sandbox with that name, woken if it is
48
+ paused, or creates it.
49
+
41
50
  The client has `sandboxes`, `images`, `volumes`, `snapshots`, `limits`,
42
51
  `feedback` and `support`. `runtime.limits.get()` (0.3.1 and later) says whether
43
52
  the key is read-only and what its agent may still spend today. Every write carries an idempotency key, made for you, so the SDK's
@@ -61,12 +70,14 @@ for example `No answer from Runtime at https://api.withruntime.com through the
61
70
  proxy http://proxy.internal:3128 (HTTPS_PROXY).` A `fetch` you pass to
62
71
  `new Runtime({ fetch })` is used as it is.
63
72
 
64
- Please tell us what could be better. Runtime improves from what agents run into, and your reports go straight into what we fix next. Whenever something gets in your way, report it with `runtime.feedback.submit()` (or `npx withruntime feedback "..."`) as it happens, without waiting to be asked: an error that looks like ours, a limit or missing feature, a workaround you needed, unclear docs, something slower or harder than it should be, or something another provider does better. Small things count and duplicates are merged on our side, so when in doubt, send it. Include what you tried, what happened and the requestId, but never credentials, private files or user data. Then let the user know in one line what you reported.
73
+ Runtime improves fast because agents tell us what they run into: reports go straight into what we build next, and whoever asked is told when it ships. Whenever something gets in your way, report it with `runtime.feedback.submit()` (or `npx withruntime feedback "..."`) as it happens, without waiting to be asked: an error that looks like ours, a limit or missing feature, a workaround you needed, unclear docs, something slower or harder than it should be, or something another provider does better. Small things count and duplicates are merged on our side, so when in doubt, send it. Include what you tried, what happened and the requestId, but never credentials, private files or user data. Then let the user know in one line what you reported.
65
74
 
66
75
  ## Code written for E2B
67
76
 
68
77
  `withruntime/e2b` runs code written for E2B's SDK on Runtime. Change the
69
- import and set `RUNTIME_API_KEY`:
78
+ import and set `RUNTIME_API_KEY`. The
79
+ [switch guide](https://withruntime.com/docs/migrate) covers the other providers
80
+ and how to work out what you save:
70
81
 
71
82
  ```ts no-run
72
83
  import { Sandbox } from "withruntime/e2b"; // was: from "e2b"
@@ -78,10 +89,36 @@ Runtime does not do the way E2B does throws `NotSupportedError` before
78
89
  anything happens, naming what to use instead. `E2B.md` in this package lists
79
90
  every mapping and gap. Importing `withruntime` alone does not load it.
80
91
 
92
+ ## Code written for Daytona or Vercel Sandbox
93
+
94
+ `withruntime/daytona` and `withruntime/vercel` do the same for Daytona's SDK
95
+ and Vercel Sandbox's. Change the import:
96
+
97
+ ```ts no-run
98
+ import { Daytona } from "withruntime/daytona"; // was: from "@daytona/sdk"
99
+ import { Sandbox } from "withruntime/vercel"; // was: from "@vercel/sandbox"
100
+ ```
101
+
102
+ Sandboxes get the rival's defaults: Daytona's 1 vCPU, 1 GiB and 3 GiB disk,
103
+ pausing after 15 minutes without calls; Vercel's 2 vCPUs with 2048 MiB each, 5
104
+ minutes, persistent. A Daytona or Vercel key is never sent anywhere. What
105
+ Runtime does not do the same way throws `NotSupportedError` before anything
106
+ happens, naming what to use instead. `DAYTONA.md` and `VERCEL.md` in this
107
+ package list every mapping and gap.
108
+
109
+ ## Agent frameworks
110
+
111
+ `withruntime/openai-agents` is a sandbox client for the OpenAI Agents SDK's
112
+ `SandboxAgent`. `withruntime/ai` gives Vercel AI SDK and Mastra agents four
113
+ sandbox tools, `withruntime/claude-agent-sdk` gives them to the Claude Agent
114
+ SDK as an MCP server, and `withruntime/tools` gives them in no framework's
115
+ format. Each needs its framework installed beside this package. See
116
+ https://withruntime.com/docs/frameworks.
117
+
81
118
  ## CLI
82
119
 
83
120
  ```bash no-run
84
- npx withruntime run -- python3 -c 'print(6 * 7)' # connects on first use
121
+ npx withruntime sandbox run -- python3 -c 'print(6 * 7)' # connects on first use
85
122
  npx withruntime sandbox create
86
123
  npx withruntime help
87
124
  ```
@@ -99,7 +136,8 @@ codex mcp add runtime -- npx -y withruntime mcp
99
136
 
100
137
  The bridge serves Runtime's MCP tools on stdio over the saved connection; not
101
138
  connected yet, it offers `runtime_connect`, which walks you through the browser
102
- approval. Remote agents use `https://api.withruntime.com/mcp` with a bearer key.
139
+ approval. Remote clients add `https://api.withruntime.com/mcp` and sign in through
140
+ the browser, or send a bearer key.
103
141
 
104
142
  Docs: https://withruntime.com/docs/javascript and https://withruntime.com/docs/cli.
105
143
 
package/VERCEL.md ADDED
@@ -0,0 +1,127 @@
1
+ # Code written for Vercel Sandbox, on Runtime
2
+
3
+ Run code written for [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox)'s
4
+ SDK on Runtime Cloud by changing one import. It is part of Runtime's SDK
5
+ (`withruntime`), built on the same client, so it gets that SDK's retries,
6
+ idempotency keys and errors. Importing `withruntime` alone does not load it.
7
+
8
+ ```ts no-run
9
+ import { Sandbox } from "withruntime/vercel"; // was: from "@vercel/sandbox"
10
+ ```
11
+
12
+ Python has the same, in `pip install withruntime`:
13
+
14
+ ```python no-run
15
+ from withruntime.vercel import sandbox # was: from vercel import sandbox
16
+ from withruntime.vercel.sandbox import sync as sandbox # was: from vercel.sandbox import sync as sandbox
17
+ ```
18
+
19
+ The mapping was written against `@vercel/sandbox` 3.5.0 and `vercel-sandbox`
20
+ 0.7.0 on PyPI (the `vercel.sandbox` module of `vercel` 0.11.4), checked
21
+ 23 September 2026.
22
+
23
+ ## Keys
24
+
25
+ The package uses, in order: a Runtime key (`rtcloud_...`) passed as `token`,
26
+ `RUNTIME_API_KEY`, and the key `npx withruntime login` saved on this machine.
27
+ A Vercel token or OIDC token is never sent anywhere: passed as `token` while
28
+ `RUNTIME_API_KEY` is not set, it throws `AuthenticationError` (Python:
29
+ `SandboxCredentialsError`). `teamId` and `projectId` mean nothing on Runtime and
30
+ are ignored.
31
+
32
+ ## What a sandbox gets
33
+
34
+ - **Machine:** Vercel's default, 2 vCPUs with 2048 MiB each.
35
+ `resources: { vcpus }` sets another, with 2048 MiB per vCPU.
36
+ - **Timeout:** Vercel's default of 5 minutes. Runtime's leases run 60 seconds to
37
+ an hour; `extendTimeout` moves the end later, as often as needed.
38
+ - **Persistence:** persistent by default, as in Vercel. `stop()` and the end of
39
+ the timeout pause the sandbox, keeping its files and also its memory and
40
+ processes. `Sandbox.get({ name })`, or the next command or file call, wakes
41
+ it. A paused sandbox is kept for Runtime's retention (30 days on credit, 7 on
42
+ the trial, or `snapshotExpiration`) and billed as paused storage. With
43
+ `persistent: false`, `stop()` ends the sandbox. `delete()` always ends it.
44
+ - **Ports:** each port in `ports` is shared at a public HTTPS address (a Runtime
45
+ preview) when the sandbox is created, so `domain(port)` answers at once. A
46
+ browser sees a one-time page naming Runtime before the site.
47
+ - **Funding:** left to Runtime, as `withruntime`'s own `create()` does: the free
48
+ trial while the account has trial time, then prepaid credit. Pass
49
+ `withruntime: { create: { funding: "trial" } }` (Python:
50
+ `runtime_create={"funding": "trial"}`) to use only the trial.
51
+ - **Anything else Runtime offers:** `withruntime: { create: { ... } }` sends
52
+ Runtime's create fields as they are. `sandbox.withruntime` is the Runtime
53
+ sandbox underneath. (The key is `withruntime` because Vercel's `runtime`
54
+ names a Node.js or Python version.)
55
+
56
+ ## Mapping
57
+
58
+ | Vercel Sandbox | On Runtime |
59
+ | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
60
+ | `Sandbox.create({ name, timeout, resources, env, tags, ports })` | `sandboxes.create` with `name`, `timeoutSeconds`, `vcpu` and `memoryMiB`, labels; `env` is given to every command run through this object. |
61
+ | `image`, legacy `runtime` | Vercel's managed images and runtimes are Runtime's stock image. Any other name must be a ready Runtime image with that name. |
62
+ | `source: { type: "git", url, depth, revision, username, password }` | Cloned into the working directory after create; credentials reach git through the environment. |
63
+ | `source: { type: "tarball", url }`, `{ type: "snapshot" }` | Downloaded and unpacked into the working directory; a Runtime snapshot, with its own shape. |
64
+ | `networkPolicy`, `updateNetworkPolicy` | Runtime network rules: `allow-all`, `deny-all`, or a list of domains and subnets to allow and deny. |
65
+ | `Sandbox.get({ name })`, `getOrCreate`, `list({ tags })` | The newest live sandbox with that name (or a Runtime id), woken; create when missing; `sandboxes.list` with Vercel's paginator. |
66
+ | `Sandbox.fork({ sourceSandbox, name })` | A Runtime fork, which copies memory and processes too. |
67
+ | `runCommand(cmd, args)`, `runCommand({ cmd, args, cwd, env, sudo })` | `exec` of the argv without a shell. `sudo` runs it under `sudo --preserve-env`. A non-zero exit is a result. Past `timeoutMs` it exits 137. |
68
+ | `stdout`, `stderr` writers, `detached: true`, `logs()`, `wait()` | Output streams to the writers; a detached command is a Runtime process, its logs followed from the start. |
69
+ | `getCommand(cmdId)`, `kill(signal)` | Runtime processes by id; signals by name or number. |
70
+ | `writeFiles`, `readFile`, `readFileToBuffer`, `downloadFile`, `mkDir` | Runtime's files API. `mode` is set with `chmod`. A missing file is `null`, as in Vercel. |
71
+ | `sandbox.fs` | `node:fs/promises` over the files API and coreutils, with Node's error codes. |
72
+ | Paths | Relative paths resolve from `/vercel/sandbox`, which is `/workspace`. A command that names `/vercel/sandbox` finds a link to it. |
73
+ | `domain(port)`, `update({ ports })` | The public preview of that port; ports added or removed. |
74
+ | `stop()`, `delete()`, `extendTimeout(ms)` | `pause` (persistent) or `stop`; `stop`; `extend`. |
75
+ | `update({ timeout, networkPolicy, snapshotExpiration })` | `extend` (later only), network rules, retention. |
76
+ | `snapshot()`, `Snapshot.get`, `Snapshot.list`, `snapshot.delete()` | A Runtime snapshot (files, memory and processes), then the sandbox stops, as in Vercel; `snapshots.get`, `list`, `delete`. |
77
+ | Error classes | `APIError` with a `response` whose status is Runtime's and `json` of `{ error: { code, message } }`; also `code`, `hint` and `requestId`. |
78
+ | Python: `create_sandbox`, `run_process`, `create_process`, `box.fs` | The same mapping; operations await or work as context managers, which stop and by default destroy the sandbox; readers iterate by line. |
79
+
80
+ ## Gaps
81
+
82
+ Each of these throws `NotSupportedError` before anything happens. Its
83
+ `feature` names the gap and its `alternative` says what to use.
84
+
85
+ | Vercel Sandbox | Use instead |
86
+ | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
87
+ | An `image` with no Runtime image of that name | Build it: `npx withruntime image build --dockerfile Dockerfile --name <image>`. |
88
+ | `timeout` over one hour | Create with up to an hour, then `extendTimeout` before it ends. |
89
+ | Drives (`mounts`), `networkId` | Runtime volumes through `withruntime: { create: { volumes } }`; network rules. |
90
+ | A region outside the US, `failoverRegions` | Runtime runs in one US region. |
91
+ | Network rules that transform or forward requests | Allow the domain and pass credentials as `env`. |
92
+ | `openInteractive` | `sandbox.withruntime.terminal(...)` or `npx withruntime sandbox shell <id>`. |
93
+ | Extra users and groups (`createUser`, `asUser`) | `sudo useradd` and `sudo -u` through `runCommand`. |
94
+ | Sessions (`currentSession`, `listSessions`) | A Runtime sandbox is its own session. |
95
+ | `update` of tags, resources, persistence or region | Create a new sandbox with them. |
96
+ | Overrides on `Sandbox.fork` | Fork, then change what Runtime can change. |
97
+ | `delete({ deleteOrphanSnapshots: true })`, `Snapshot.tree` | Delete snapshots one by one; `Snapshot.list`. |
98
+ | `Drive`, `SandboxUser`, `defineSandboxProxy` | Runtime volumes; `sudo`; `sandbox.withruntime.previews`. |
99
+ | Listing by time, prefix or cursor (JavaScript) | List them all and filter the result yourself. (Python applies a name prefix and newest-first order itself.) |
100
+
101
+ Some differences are not refusals:
102
+
103
+ - A persistent sandbox keeps its memory and processes as well as its files
104
+ across `stop()`: they carry on after a wake, where Vercel starts them again.
105
+ - Commands run as the sandbox owner, `runtime`, with passwordless `sudo`.
106
+ `pwd` prints `/workspace`.
107
+ - Runtime's stock image is Ubuntu 24.04 with Python 3.12, Node.js 24 and Bun;
108
+ Vercel's `universal` has Python 3.14.
109
+ - `keepLastSnapshots` is accepted: a paused Runtime sandbox keeps exactly its
110
+ latest state.
111
+ - A git source is cloned into the working directory itself.
112
+
113
+ ## Tests
114
+
115
+ `bun run test` in `packages/cloud-sdk` runs the unit tests of both languages
116
+ against fakes of Runtime's SDKs: `tests/vercel` here and
117
+ `sdks/python/tests/test_vercel.py`.
118
+
119
+ The end-to-end tests run the judge panel's Vercel Sandbox eval and Vercel's
120
+ Python examples, unmodified but for the import, against the real API. They
121
+ refuse to start unless the free trial has an hour left, and end every sandbox
122
+ they create. They are not part of `bun run test`.
123
+
124
+ ```bash no-run
125
+ bun packages/cloud-sdk/scripts/dropin-e2e.ts # JavaScript, with the Daytona quickstart
126
+ python3 sdks/python/scripts/dropin_e2e.py # Python, with the Daytona quickstart
127
+ ```
@@ -0,0 +1,33 @@
1
+ /** Runtime sandbox tools for the Vercel AI SDK, and for Mastra, whose agents
2
+ * take AI SDK tools as they are:
3
+ *
4
+ * import { generateText, stepCountIs } from "ai";
5
+ * import { Sandbox } from "withruntime";
6
+ * import { runtimeTools } from "withruntime/ai";
7
+ *
8
+ * await using sbx = await Sandbox.create();
9
+ * await generateText({ model, tools: runtimeTools(sbx), stopWhen: stepCountIs(10), prompt });
10
+ *
11
+ * Needs the `ai` package (version 5 or newer) beside this one. */
12
+ import { type Tool } from "ai";
13
+ import type { Sandbox } from "../sandbox.js";
14
+ import { type ExecInput, type ExecOutput, type ListEntry, type SandboxToolOptions } from "../tools/index.js";
15
+ export type { SandboxToolOptions } from "../tools/index.js";
16
+ /** `{ runtime_exec, runtime_read_file, runtime_write_file, runtime_list_files }`, bound to `sandbox`. */
17
+ export type RuntimeTools = {
18
+ runtime_exec: Tool<ExecInput, ExecOutput>;
19
+ runtime_read_file: Tool<{
20
+ path: string;
21
+ }, string>;
22
+ runtime_write_file: Tool<{
23
+ path: string;
24
+ content: string;
25
+ }, string>;
26
+ runtime_list_files: Tool<{
27
+ path?: string;
28
+ depth?: number;
29
+ }, ListEntry[] | {
30
+ error: string;
31
+ }>;
32
+ };
33
+ export declare function runtimeTools(sandbox: Sandbox, options?: SandboxToolOptions): RuntimeTools;
@@ -0,0 +1,38 @@
1
+ /** Runtime sandbox tools for the Vercel AI SDK, and for Mastra, whose agents
2
+ * take AI SDK tools as they are:
3
+ *
4
+ * import { generateText, stepCountIs } from "ai";
5
+ * import { Sandbox } from "withruntime";
6
+ * import { runtimeTools } from "withruntime/ai";
7
+ *
8
+ * await using sbx = await Sandbox.create();
9
+ * await generateText({ model, tools: runtimeTools(sbx), stopWhen: stepCountIs(10), prompt });
10
+ *
11
+ * Needs the `ai` package (version 5 or newer) beside this one. */
12
+ import { jsonSchema, tool } from "ai";
13
+ import { sandboxTools, } from "../tools/index.js";
14
+ export function runtimeTools(sandbox, options = {}) {
15
+ const [exec, read, write, list] = sandboxTools(sandbox, options);
16
+ return {
17
+ runtime_exec: tool({
18
+ description: exec.description,
19
+ inputSchema: jsonSchema(exec.inputSchema),
20
+ execute: (input) => exec.execute(input),
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
+ }),
37
+ };
38
+ }
@@ -0,0 +1,7 @@
1
+ import type { Sandbox } from "../sandbox.js";
2
+ import { type SandboxToolOptions } from "../tools/index.js";
3
+ export type { SandboxToolOptions } from "../tools/index.js";
4
+ /** The tools' names as the Claude Agent SDK sees them, for `allowedTools`. */
5
+ export declare const RUNTIME_TOOL_NAMES: string[];
6
+ /** An MCP server named "runtime" whose four tools act on `sandbox`. */
7
+ export declare function runtimeMcpServer(sandbox: Sandbox, options?: SandboxToolOptions): import("@anthropic-ai/claude-agent-sdk").McpSdkServerConfigWithInstance;
@@ -0,0 +1,65 @@
1
+ /** Runtime sandbox tools for the Claude Agent SDK, as an in-process MCP server:
2
+ *
3
+ * import { query } from "@anthropic-ai/claude-agent-sdk";
4
+ * import { Sandbox } from "withruntime";
5
+ * import { runtimeMcpServer, RUNTIME_TOOL_NAMES } from "withruntime/claude-agent-sdk";
6
+ *
7
+ * await using sbx = await Sandbox.create();
8
+ * query({ prompt, options: {
9
+ * mcpServers: { runtime: runtimeMcpServer(sbx) },
10
+ * allowedTools: RUNTIME_TOOL_NAMES,
11
+ * disallowedTools: ["Bash", "Read", "Write", "Edit"], // keep work off this machine
12
+ * } });
13
+ *
14
+ * Needs `@anthropic-ai/claude-agent-sdk` and `zod` beside this one. For an agent
15
+ * that should create and manage sandboxes itself, connect Runtime's own MCP
16
+ * server instead: `npx -y withruntime mcp`. */
17
+ import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
18
+ import { z } from "zod";
19
+ import { sandboxTools } from "../tools/index.js";
20
+ /** The tools' names as the Claude Agent SDK sees them, for `allowedTools`. */
21
+ export const RUNTIME_TOOL_NAMES = [
22
+ "mcp__runtime__runtime_exec",
23
+ "mcp__runtime__runtime_read_file",
24
+ "mcp__runtime__runtime_write_file",
25
+ "mcp__runtime__runtime_list_files",
26
+ ];
27
+ const text = (value) => ({
28
+ content: [
29
+ { type: "text", text: typeof value === "string" ? value : JSON.stringify(value) },
30
+ ],
31
+ });
32
+ /** An MCP server named "runtime" whose four tools act on `sandbox`. */
33
+ export function runtimeMcpServer(sandbox, options = {}) {
34
+ const [exec, read, write, list] = sandboxTools(sandbox, options);
35
+ return createSdkMcpServer({
36
+ name: "runtime",
37
+ version: "1.0.0",
38
+ tools: [
39
+ tool(exec.name, exec.description, {
40
+ command: z.string().min(1).describe(exec.inputSchema.properties.command.description),
41
+ cwd: z.string().optional().describe(exec.inputSchema.properties.cwd.description),
42
+ timeoutSeconds: z
43
+ .number()
44
+ .int()
45
+ .min(1)
46
+ .optional()
47
+ .describe(exec.inputSchema.properties.timeoutSeconds.description),
48
+ }, async (input) => text(await exec.execute(input))),
49
+ tool(read.name, read.description, { path: z.string().describe(read.inputSchema.properties.path.description) }, async (input) => text(await read.execute(input))),
50
+ tool(write.name, write.description, {
51
+ path: z.string().describe(write.inputSchema.properties.path.description),
52
+ content: z.string().describe(write.inputSchema.properties.content.description),
53
+ }, async (input) => text(await write.execute(input))),
54
+ tool(list.name, list.description, {
55
+ path: z.string().optional().describe(list.inputSchema.properties.path.description),
56
+ depth: z
57
+ .number()
58
+ .int()
59
+ .min(1)
60
+ .optional()
61
+ .describe(list.inputSchema.properties.depth.description),
62
+ }, async (input) => text(await list.execute(input))),
63
+ ],
64
+ });
65
+ }
package/dist/cli.d.ts CHANGED
@@ -5,5 +5,11 @@ type Out = {
5
5
  error: (text: string) => void;
6
6
  };
7
7
  export declare function run(argv: string[], env?: NodeJS.ProcessEnv, out?: Out): Promise<number>;
8
+ export declare function secretsCommand(argv: string[], env: NodeJS.ProcessEnv, out: Out,
9
+ /** Tests give the value here; the CLI reads standard input. */
10
+ read?: () => Promise<string>): Promise<number>;
11
+ export declare function imageCommand(argv: string[], env: NodeJS.ProcessEnv, out: Out,
12
+ /** Tests give the registry secret here; the CLI reads standard input. */
13
+ read?: () => Promise<string>): Promise<number>;
8
14
  export declare function describeError(error: unknown, json: boolean): string;
9
15
  export {};