eve 0.58.0 → 0.59.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 (196) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +1 -0
  3. package/dist/src/channel/session.d.ts +2 -0
  4. package/dist/src/channel/session.js +1 -1
  5. package/dist/src/channel/types.d.ts +8 -1
  6. package/dist/src/chunks/{use-eve-agent-X0asmJg-.js → use-eve-agent-Dmc6sX4d.js} +558 -233
  7. package/dist/src/chunks/{use-eve-agent-CxWcZCsU.js → use-eve-agent-jSR8P4nK.js} +565 -235
  8. package/dist/src/cli/dev/tui/runner.d.ts +4 -0
  9. package/dist/src/cli/dev/tui/runner.js +1 -1
  10. package/dist/src/cli/dev/tui/setup-issues.js +1 -1
  11. package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
  12. package/dist/src/client/eve-agent-projection.d.ts +10 -0
  13. package/dist/src/client/eve-agent-projection.js +1 -0
  14. package/dist/src/client/eve-agent-store-helpers.d.ts +6 -2
  15. package/dist/src/client/eve-agent-store-helpers.js +2 -2
  16. package/dist/src/client/eve-agent-store-state.d.ts +54 -1
  17. package/dist/src/client/eve-agent-store.d.ts +12 -82
  18. package/dist/src/client/eve-agent-store.js +1 -1
  19. package/dist/src/client/index.d.ts +2 -2
  20. package/dist/src/client/index.js +1 -1
  21. package/dist/src/client/message-response.d.ts +5 -1
  22. package/dist/src/client/message-response.js +1 -1
  23. package/dist/src/client/ndjson.d.ts +1 -0
  24. package/dist/src/client/ndjson.js +2 -2
  25. package/dist/src/client/open-stream.d.ts +4 -1
  26. package/dist/src/client/open-stream.js +1 -1
  27. package/dist/src/client/session-event-stream.d.ts +30 -0
  28. package/dist/src/client/session-event-stream.js +1 -0
  29. package/dist/src/client/session-utils.d.ts +2 -1
  30. package/dist/src/client/session-utils.js +1 -1
  31. package/dist/src/client/session.d.ts +14 -1
  32. package/dist/src/client/session.js +1 -1
  33. package/dist/src/client/sessions.d.ts +8 -2
  34. package/dist/src/client/sessions.js +1 -1
  35. package/dist/src/client/types.d.ts +7 -0
  36. package/dist/src/compiled/.vendor-stamp.json +2 -3
  37. package/dist/src/compiled/@vercel/sandbox/api-client/api-client.d.ts +88 -1
  38. package/dist/src/compiled/@vercel/sandbox/api-client/index.d.ts +1 -1
  39. package/dist/src/compiled/@vercel/sandbox/api-client/validators.d.ts +41 -1
  40. package/dist/src/compiled/@vercel/sandbox/constants.d.ts +3 -3
  41. package/dist/src/compiled/@vercel/{sandbox-drives → sandbox}/drive.d.ts +13 -2
  42. package/dist/src/compiled/@vercel/sandbox/index.d.ts +3 -2
  43. package/dist/src/compiled/@vercel/sandbox/index.js +15 -9
  44. package/dist/src/compiled/@vercel/sandbox/sandbox.d.ts +40 -5
  45. package/dist/src/compiled/_chunks/node/auth-DDrvYko5.js +2 -0
  46. package/dist/src/compiled/_chunks/node/version-C__MqbLM.js +1 -0
  47. package/dist/src/compiler/extension-compatibility.d.ts +14 -14
  48. package/dist/src/compiler/extension-compatibility.js +1 -1
  49. package/dist/src/context/build-dynamic-tools.js +1 -1
  50. package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
  51. package/dist/src/context/memory-tools.js +1 -1
  52. package/dist/src/evals/context.d.ts +1 -1
  53. package/dist/src/evals/context.js +1 -1
  54. package/dist/src/evals/define-eval.d.ts +1 -1
  55. package/dist/src/evals/define-eval.js +1 -1
  56. package/dist/src/evals/index.js +1 -1
  57. package/dist/src/evals/judge.d.ts +1 -1
  58. package/dist/src/evals/runner/execute-task.d.ts +1 -1
  59. package/dist/src/evals/runner/execute-task.js +1 -1
  60. package/dist/src/evals/session-manager.d.ts +27 -0
  61. package/dist/src/evals/session-manager.js +1 -0
  62. package/dist/src/evals/session.d.ts +8 -28
  63. package/dist/src/evals/session.js +2 -1
  64. package/dist/src/evals/target.d.ts +1 -1
  65. package/dist/src/evals/target.js +1 -1
  66. package/dist/src/evals/types.d.ts +19 -15
  67. package/dist/src/eve-channel/create-request.d.ts +24 -0
  68. package/dist/src/eve-channel/create-request.js +1 -0
  69. package/dist/src/eve-channel/index.js +1 -1
  70. package/dist/src/eve-channel/request.d.ts +3 -12
  71. package/dist/src/eve-channel/request.js +2 -2
  72. package/dist/src/eve-channel/types.d.ts +4 -2
  73. package/dist/src/execution/dynamic-workflow/tool.js +1 -1
  74. package/dist/src/execution/legacy-session/turn-workflow.js +1 -1
  75. package/dist/src/execution/runtime-context.js +1 -1
  76. package/dist/src/execution/sandbox/bindings/vercel-lifecycle.d.ts +3 -3
  77. package/dist/src/execution/sandbox/bindings/vercel-lifecycle.js +1 -1
  78. package/dist/src/execution/sandbox/bindings/vercel-sdk-types.d.ts +1 -4
  79. package/dist/src/execution/sandbox/bindings/vercel.d.ts +1 -2
  80. package/dist/src/execution/sandbox/bindings/vercel.js +1 -1
  81. package/dist/src/execution/session/entry.js +1 -1
  82. package/dist/src/execution/session/handoff-steps.js +1 -1
  83. package/dist/src/execution/session/program.d.ts +2 -0
  84. package/dist/src/execution/session/program.js +1 -1
  85. package/dist/src/execution/session/turn-step.js +1 -1
  86. package/dist/src/execution/session/turn.js +1 -1
  87. package/dist/src/execution/session-inbox/protocol.js +1 -1
  88. package/dist/src/execution/tools/connection-search.js +1 -1
  89. package/dist/src/execution/tools/sleep-workflow.js +1 -1
  90. package/dist/src/execution/workflow-runtime.js +1 -1
  91. package/dist/src/experimental/evaluate/auto-model.js +2 -2
  92. package/dist/src/experimental/evaluate/evaluate.d.ts +7 -0
  93. package/dist/src/experimental/evaluate/evaluate.js +1 -0
  94. package/dist/src/harness/compaction.d.ts +3 -3
  95. package/dist/src/harness/compaction.js +1 -1
  96. package/dist/src/harness/request-envelope.d.ts +11 -0
  97. package/dist/src/harness/request-envelope.js +1 -0
  98. package/dist/src/harness/tool-loop.js +2 -2
  99. package/dist/src/instrumentation/prepare-trace-context.d.ts +2 -1
  100. package/dist/src/instrumentation/prepare-trace-context.js +1 -1
  101. package/dist/src/internal/application/package.js +1 -1
  102. package/dist/src/internal/authored-module-loader.d.ts +4 -1
  103. package/dist/src/internal/authored-module-loader.js +1 -1
  104. package/dist/src/internal/bundler/nitro-rolldown.d.ts +2 -0
  105. package/dist/src/internal/model-auth/transport.d.ts +3 -1
  106. package/dist/src/internal/model-auth/transport.js +1 -1
  107. package/dist/src/internal/nitro/host/build-extension.js +1 -1
  108. package/dist/src/internal/nitro/host/extension-capability-requirements.d.ts +1 -0
  109. package/dist/src/internal/nitro/host/extension-capability-requirements.js +1 -1
  110. package/dist/src/internal/nitro/host/extension-distribution.d.ts +1 -1
  111. package/dist/src/internal/nitro/host/extension-distribution.js +1 -1
  112. package/dist/src/internal/workflow-bundle/dynamic-tool-transform.js +1 -1
  113. package/dist/src/public/experimental/evaluate/index.d.ts +1 -0
  114. package/dist/src/public/experimental/evaluate/index.js +1 -1
  115. package/dist/src/public/models/anthropic/index.js +1 -1
  116. package/dist/src/public/sandbox/vercel-sandbox.d.ts +1 -1
  117. package/dist/src/public/sandbox/vercel.d.ts +1 -1
  118. package/dist/src/public/sandbox/vercel.js +1 -1
  119. package/dist/src/public/tools/index.d.ts +1 -0
  120. package/dist/src/public/tools/index.js +1 -1
  121. package/dist/src/react/use-eve-agent.d.ts +4 -0
  122. package/dist/src/react/use-eve-agent.js +1 -1
  123. package/dist/src/runtime/agent/resolve-model.js +1 -1
  124. package/dist/src/setup/flows/model-login-connection.js +1 -1
  125. package/dist/src/setup/scaffold/create/project.js +1 -1
  126. package/dist/src/subagents/handle-dispatch.js +1 -1
  127. package/dist/src/svelte/index.js +1 -1
  128. package/dist/src/svelte/use-eve-agent.d.ts +4 -0
  129. package/dist/src/svelte/use-eve-agent.js +1 -1
  130. package/dist/src/tools/definition.d.ts +2 -0
  131. package/dist/src/tools/definition.js +1 -1
  132. package/dist/src/tools/durable-callbacks.d.ts +8 -2
  133. package/dist/src/tools/durable-callbacks.js +1 -1
  134. package/dist/src/tools/durable-schema.d.ts +16 -0
  135. package/dist/src/tools/durable-schema.js +1 -0
  136. package/dist/src/vue/index.js +1 -1
  137. package/dist/src/vue/use-eve-agent.d.ts +4 -0
  138. package/dist/src/vue/use-eve-agent.js +1 -1
  139. package/docs/README.md +1 -0
  140. package/docs/channels/eve.mdx +20 -10
  141. package/docs/concepts/context-control.md +4 -0
  142. package/docs/concepts/sessions-runs-and-streaming.md +18 -3
  143. package/docs/evals/assertions.mdx +6 -6
  144. package/docs/evals/cases.mdx +59 -23
  145. package/docs/evals/judge.mdx +10 -8
  146. package/docs/evals/overview.mdx +6 -6
  147. package/docs/evals/reporters.mdx +1 -1
  148. package/docs/evals/targets.mdx +5 -0
  149. package/docs/guides/client/messages.mdx +5 -5
  150. package/docs/guides/client/overview.mdx +15 -1
  151. package/docs/guides/dynamic-capabilities.md +22 -0
  152. package/docs/guides/evaluate.md +58 -4
  153. package/docs/guides/frontend/overview.mdx +54 -5
  154. package/docs/guides/frontend/use-eve-agent-svelte.mdx +13 -8
  155. package/docs/guides/frontend/use-eve-agent-vue.mdx +13 -8
  156. package/docs/reference/typescript-api.md +38 -36
  157. package/package.json +2 -3
  158. package/dist/src/compiled/@vercel/sandbox-drives/LICENSE +0 -201
  159. package/dist/src/compiled/@vercel/sandbox-drives/_async-retry.d.ts +0 -8
  160. package/dist/src/compiled/@vercel/sandbox-drives/_workflow-serde.d.ts +0 -5
  161. package/dist/src/compiled/@vercel/sandbox-drives/api-client/api-client.d.ts +0 -1815
  162. package/dist/src/compiled/@vercel/sandbox-drives/api-client/api-error.d.ts +0 -29
  163. package/dist/src/compiled/@vercel/sandbox-drives/api-client/base-client.d.ts +0 -39
  164. package/dist/src/compiled/@vercel/sandbox-drives/api-client/file-writer.d.ts +0 -66
  165. package/dist/src/compiled/@vercel/sandbox-drives/api-client/index.d.ts +0 -2
  166. package/dist/src/compiled/@vercel/sandbox-drives/api-client/validators.d.ts +0 -932
  167. package/dist/src/compiled/@vercel/sandbox-drives/api-client/with-retry.d.ts +0 -10
  168. package/dist/src/compiled/@vercel/sandbox-drives/auth/error.d.ts +0 -15
  169. package/dist/src/compiled/@vercel/sandbox-drives/auth/file.d.ts +0 -18
  170. package/dist/src/compiled/@vercel/sandbox-drives/auth/index.d.ts +0 -6
  171. package/dist/src/compiled/@vercel/sandbox-drives/auth/oauth.d.ts +0 -111
  172. package/dist/src/compiled/@vercel/sandbox-drives/auth/poll-for-token.d.ts +0 -28
  173. package/dist/src/compiled/@vercel/sandbox-drives/auth/project.d.ts +0 -40
  174. package/dist/src/compiled/@vercel/sandbox-drives/command.d.ts +0 -292
  175. package/dist/src/compiled/@vercel/sandbox-drives/constants.d.ts +0 -15
  176. package/dist/src/compiled/@vercel/sandbox-drives/execution-context.d.ts +0 -116
  177. package/dist/src/compiled/@vercel/sandbox-drives/filesystem.d.ts +0 -258
  178. package/dist/src/compiled/@vercel/sandbox-drives/index.d.ts +0 -14
  179. package/dist/src/compiled/@vercel/sandbox-drives/index.js +0 -9
  180. package/dist/src/compiled/@vercel/sandbox-drives/network-policy.d.ts +0 -169
  181. package/dist/src/compiled/@vercel/sandbox-drives/proxy.d.ts +0 -55
  182. package/dist/src/compiled/@vercel/sandbox-drives/sandbox-user.d.ts +0 -211
  183. package/dist/src/compiled/@vercel/sandbox-drives/sandbox.d.ts +0 -1287
  184. package/dist/src/compiled/@vercel/sandbox-drives/session.d.ts +0 -435
  185. package/dist/src/compiled/@vercel/sandbox-drives/snapshot.d.ts +0 -238
  186. package/dist/src/compiled/@vercel/sandbox-drives/utils/get-credentials.d.ts +0 -21
  187. package/dist/src/compiled/@vercel/sandbox-drives/utils/paginator.d.ts +0 -16
  188. package/dist/src/compiled/@vercel/sandbox-drives/utils/resolveSignal.d.ts +0 -15
  189. package/dist/src/compiled/@vercel/sandbox-drives/utils/sandbox-snapshot.d.ts +0 -11
  190. package/dist/src/compiled/@vercel/sandbox-drives/utils/types.d.ts +0 -11
  191. package/dist/src/compiled/_chunks/node/auth-8aQozzfi.js +0 -2
  192. package/dist/src/compiled/_chunks/node/auth-Bvv0xGTY.js +0 -2
  193. package/dist/src/compiled/_chunks/node/esm-Fqlolk7e.js +0 -7
  194. package/dist/src/compiled/_chunks/node/version-BC6t2Txc.js +0 -1
  195. package/dist/src/compiled/_chunks/node/version-DSQqVZ5T.js +0 -1
  196. package/dist/src/compiled/_chunks/node/xdg-app-paths-F-QHrdza.js +0 -1
@@ -1,1287 +0,0 @@
1
- import { Paginator } from "./utils/paginator.js";
2
- import { SandboxMetaData, SandboxRouteData, SessionMetaData, SnapshotMetadata } from "./api-client/validators.js";
3
- import { NetworkPolicy, NetworkPolicyKeyValueMatcher, NetworkPolicyMatch, NetworkPolicyMatcher } from "./network-policy.js";
4
- import { WithPrivate } from "./utils/types.js";
5
- import { ManagedImage, RUNTIMES, SandboxRegion } from "./constants.js";
6
- import { APIClient, WithFetchOptions } from "./api-client/api-client.js";
7
- import "./api-client/index.js";
8
- import { Credentials } from "./utils/get-credentials.js";
9
- import { Command, CommandFinished } from "./command.js";
10
- import { Snapshot } from "./snapshot.js";
11
- import { SandboxSnapshot } from "./utils/sandbox-snapshot.js";
12
- import { ExecutionContext } from "./execution-context.js";
13
- import { RunCommandParams, Session } from "./session.js";
14
- import { FileSystem } from "./filesystem.js";
15
- import { SandboxUser } from "./sandbox-user.js";
16
- import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "./_workflow-serde.js";
17
-
18
- //#region src/sandbox.d.ts
19
- /** @inline */
20
- interface BaseCreateSandboxParams {
21
- /**
22
- * The name of the sandbox. If omitted, a random name will be generated.
23
- */
24
- name?: string;
25
- /**
26
- * The source of the sandbox.
27
- *
28
- * Omit this parameter start a sandbox without a source.
29
- *
30
- * For git sources:
31
- * - `depth`: Creates shallow clones with limited commit history (minimum: 1)
32
- * - `revision`: Clones and checks out a specific commit, branch, or tag
33
- */
34
- source?: {
35
- type: "git";
36
- url: string;
37
- depth?: number;
38
- revision?: string;
39
- } | {
40
- type: "git";
41
- url: string;
42
- username: string;
43
- password: string;
44
- depth?: number;
45
- revision?: string;
46
- } | {
47
- type: "tarball";
48
- url: string;
49
- };
50
- /**
51
- * Array of port numbers to expose from the sandbox. Sandboxes can
52
- * expose up to 15 ports.
53
- */
54
- ports?: number[];
55
- /**
56
- * Timeout in milliseconds before the sandbox auto-terminates.
57
- */
58
- timeout?: number;
59
- /**
60
- * Resources to allocate to the sandbox.
61
- *
62
- * Your sandbox will get the amount of vCPUs you specify here and
63
- * 2048 MB of memory per vCPU.
64
- */
65
- resources?: {
66
- vcpus: number;
67
- };
68
- /**
69
- * Network policy to define network restrictions for the sandbox.
70
- * Defaults to full internet access if not specified.
71
- */
72
- networkPolicy?: NetworkPolicy;
73
- /**
74
- * Default environment variables for the sandbox.
75
- * These are inherited by all commands unless overridden with
76
- * the `env` option in `runCommand`.
77
- *
78
- * @example
79
- * const sandbox = await Sandbox.create({
80
- * env: { NODE_ENV: "production", API_KEY: "secret" },
81
- * });
82
- * // All commands will have NODE_ENV and API_KEY set
83
- * await sandbox.runCommand("node", ["app.js"]);
84
- */
85
- env?: Record<string, string>;
86
- /**
87
- * Key-value tags to associate with the sandbox. Maximum 5 tags.
88
- * @example { env: "staging", team: "infra" }
89
- */
90
- tags?: Record<string, string>;
91
- /**
92
- * The region to create the sandbox in. Defaults to `iad1`.
93
- * See the Vercel documentation for the available regions.
94
- */
95
- region?: SandboxRegion;
96
- /**
97
- * Additional regions the sandbox can fail over to. Must not include
98
- * `region`.
99
- */
100
- failoverRegions?: SandboxRegion[];
101
- /**
102
- * List of drives to attach to the sandbox, keyed by the desired mount path.
103
- * The drive must be created beforehand with `Drive.getOrCreate`.
104
- *
105
- * The mount paths must be absolute and cannot overlap with each other.
106
- *
107
- * @example
108
- * const drive = await Drive.getOrCreate({ name: "my-drive" });
109
- * const sandbox = await Sandbox.create({
110
- * mounts: {
111
- * "/data": { drive: drive.name, mode: "read-write" },
112
- * },
113
- * });
114
- */
115
- mounts?: Record<string, {
116
- /**
117
- * The drive name to mount.
118
- */
119
- drive: string;
120
- /**
121
- * Mount mode. Defaults to `read-write` if unspecified.
122
- */
123
- mode?: "read-only" | "read-write";
124
- }>;
125
- /**
126
- * An AbortSignal to cancel sandbox creation.
127
- */
128
- signal?: AbortSignal;
129
- /**
130
- * Enable or disable automatic restore of the filesystem between sessions.
131
- */
132
- persistent?: boolean;
133
- /**
134
- * Default snapshot expiration in milliseconds.
135
- * When set, snapshots created for this sandbox will expire after this duration.
136
- * Use `0` for no expiration.
137
- */
138
- snapshotExpiration?: number;
139
- /**
140
- * Retention policy that keeps only the N most recent snapshots of this
141
- * sandbox. Older snapshots are evicted when a new one is created.
142
- */
143
- keepLastSnapshots?: {
144
- /**
145
- * Number of snapshots to keep (1-10).
146
- */
147
- count: number;
148
- /**
149
- * Expiration in milliseconds applied to kept snapshots.
150
- * Use `0` for no expiration. Falls back to `snapshotExpiration` when omitted.
151
- */
152
- expiration?: number;
153
- /**
154
- * When `true` (the default), evicted snapshots are deleted immediately;
155
- * when `false`, they keep the default expiration.
156
- */
157
- deleteEvicted?: boolean;
158
- };
159
- /**
160
- * Called when the sandbox session is resumed (e.g., after a snapshot restore).
161
- * Use this to re-warm caches, restore transient state, or run other setup logic.
162
- */
163
- onResume?: (sandbox: Sandbox) => Promise<void>;
164
- }
165
- type SandboxMounts = NonNullable<BaseCreateSandboxParams["mounts"]>;
166
- type SandboxMountMode = NonNullable<SandboxMounts[string]["mode"]>;
167
- /**
168
- * A VCR image reference.
169
- */
170
- type SandboxImage = `vercel/sandbox/${ManagedImage}` | (string & {});
171
- /**
172
- * Sandbox environment selection options.
173
- * @inline
174
- */
175
- type RuntimeOrImage = {
176
- /**
177
- * A legacy Vercel-managed runtime.
178
- *
179
- * @deprecated Use `image` instead.
180
- */
181
- runtime?: RUNTIMES | (string & {});
182
- image?: never;
183
- } | {
184
- runtime?: never;
185
- /**
186
- * A Vercel Container Registry (VCR) image to start the sandbox from,
187
- * scoped to the sandbox's project or a shared image from any project. Accepts a repository name, an
188
- * optional tag or digest, or a fully-qualified VCR URL. A bare
189
- * repository name resolves to the `latest` tag. If omitted, the sandbox
190
- * uses `vercel/sandbox/universal:latest`.
191
- *
192
- * @example "vercel/sandbox/universal" // Vercel managed image, latest tag
193
- * @example "my-repo" // latest tag
194
- * @example "my-repo:v1" // specific tag
195
- * @example "my-repo@sha256:..." // specific digest
196
- * @example "other-team/other-project/repo:v1" // Shared image from another team
197
- * @example "vcr.vercel.com/my-team/my-project/repo:v1" // fully-qualified
198
- */
199
- image?: SandboxImage;
200
- };
201
- type CreateSandboxParams = (BaseCreateSandboxParams & RuntimeOrImage) | (Omit<BaseCreateSandboxParams, "source"> & {
202
- source: {
203
- type: "snapshot";
204
- snapshotId: string;
205
- };
206
- runtime?: never;
207
- image?: never;
208
- });
209
- /**
210
- * Parameters for {@link Sandbox.fork}.
211
- *
212
- * The fork inherits the source sandbox's current filesystem snapshot and the
213
- * server copies its config — resources, timeout, ports, tags, network policy,
214
- * image, persistence, snapshot settings, and environment variables. Any field
215
- * set here acts as an override of the copied value. When the source has no
216
- * snapshot, its base environment is copied.
217
- * @inline
218
- */
219
- type ForkSandboxParams = Omit<BaseCreateSandboxParams, "source"> & {
220
- /**
221
- * Name of the source sandbox to fork from.
222
- */
223
- sourceSandbox: string;
224
- /**
225
- * A Vercel Container Registry (VCR) image to start the fork from, overriding
226
- * the image copied from the source.
227
- */
228
- image?: SandboxImage;
229
- };
230
- /** @inline */
231
- interface GetSandboxParams {
232
- /**
233
- * The name of the sandbox.
234
- */
235
- name: string;
236
- /**
237
- * Whether to resume an existing session immediately. Defaults to false;
238
- * a persistent sandbox still auto-resumes on the first SDK call that
239
- * needs a running session (such as `runCommand`).
240
- */
241
- resume?: boolean;
242
- /**
243
- * An AbortSignal to cancel the operation.
244
- */
245
- signal?: AbortSignal;
246
- /**
247
- * Called when the sandbox session is resumed (e.g., after a snapshot restore).
248
- * Use this to re-warm caches, restore transient state, or run other setup logic.
249
- */
250
- onResume?: (sandbox: Sandbox) => Promise<void>;
251
- }
252
- /**
253
- * Combines {@link CreateSandboxParams} with get-specific options so that any
254
- * new parameter added to either flow is picked up automatically.
255
- * @inline
256
- */
257
- type GetOrCreateSandboxParams = CreateSandboxParams & {
258
- /**
259
- * Whether to resume an existing session immediately. Defaults to false;
260
- * a persistent sandbox still auto-resumes on the first SDK call that
261
- * needs a running session (such as `runCommand`).
262
- */
263
- resume?: boolean;
264
- /**
265
- * Called once after a sandbox is freshly created (not when an existing
266
- * sandbox is retrieved). Use this for one-time setup such as seeding
267
- * files or warming caches. The returned promise is awaited before
268
- * {@link Sandbox.getOrCreate} resolves.
269
- */
270
- onCreate?: (sandbox: Sandbox) => Promise<void>;
271
- };
272
- /**
273
- * Serialized representation of a Sandbox for @workflow/serde.
274
- * Fields `metadata` and `routes` are the original wire format from main.
275
- * Fields `sandboxMetadata` and `projectId` are added for named-sandboxes.
276
- */
277
- interface SerializedSandbox {
278
- metadata: SandboxSnapshot;
279
- routes: SandboxRouteData[];
280
- sandboxMetadata?: SandboxMetaData;
281
- projectId?: string;
282
- }
283
- /**
284
- * A Sandbox is a persistent, isolated Linux MicroVMs to run commands in.
285
- * Use {@link Sandbox.create} or {@link Sandbox.get} to construct.
286
- * @hideconstructor
287
- */
288
- declare class Sandbox implements ExecutionContext {
289
- private _client;
290
- private readonly projectId;
291
- /**
292
- * In-flight resume promise, used to deduplicate concurrent resume calls.
293
- */
294
- private resumePromise;
295
- /**
296
- * Internal Session instance for the current VM.
297
- */
298
- private session;
299
- /**
300
- * Internal metadata about the sandbox.
301
- */
302
- private sandbox;
303
- /**
304
- * Hook that will be executed when a new session is created during resume.
305
- */
306
- private readonly onResume?;
307
- /**
308
- * Memoized lookup of the sandbox's default user and its primary group.
309
- * See {@link Sandbox.getDefaultUser}.
310
- */
311
- private defaultUserPromise?;
312
- /**
313
- * A `node:fs/promises`-compatible API for interacting with the sandbox filesystem.
314
- *
315
- * @example
316
- * const content = await sandbox.fs.readFile('/etc/hostname', 'utf8');
317
- * await sandbox.fs.writeFile('/tmp/hello.txt', 'Hello, world!');
318
- * const files = await sandbox.fs.readdir('/tmp');
319
- * const stats = await sandbox.fs.stat('/tmp/hello.txt');
320
- */
321
- readonly fs: FileSystem;
322
- /**
323
- * Lazily resolve credentials and construct an API client.
324
- * @internal
325
- */
326
- private ensureClient;
327
- /**
328
- * The name of this sandbox.
329
- */
330
- get name(): string;
331
- /**
332
- * Routes from ports to subdomains.
333
- * @hidden
334
- */
335
- get routes(): SandboxRouteData[];
336
- /**
337
- * Whether the sandbox persists the state.
338
- */
339
- get persistent(): boolean;
340
- /**
341
- * The region this sandbox is configured to run in. Where the running session
342
- * actually landed is reported by {@link Session.region}.
343
- */
344
- get region(): string;
345
- /**
346
- * The additional regions this sandbox can fail over to, in order. Empty when
347
- * it does not fail over.
348
- */
349
- get failoverRegions(): string[];
350
- /**
351
- * Number of virtual CPUs allocated.
352
- */
353
- get vcpus(): number | undefined;
354
- /**
355
- * Memory allocated in MB.
356
- */
357
- get memory(): number | undefined;
358
- /**
359
- * Legacy runtime identifier, when the sandbox was created with `runtime`.
360
- *
361
- * @deprecated Use {@link Sandbox.image} for image-backed sandboxes.
362
- */
363
- get runtime(): string | undefined;
364
- /**
365
- * Digest-pinned reference of the container image the sandbox was created
366
- * from, when it was created from an image (`"{repository}@{manifestDigest}"`).
367
- */
368
- get image(): string | undefined;
369
- /**
370
- * Cumulative egress bytes across all sessions.
371
- */
372
- get totalEgressBytes(): number | undefined;
373
- /**
374
- * Cumulative ingress bytes across all sessions.
375
- */
376
- get totalIngressBytes(): number | undefined;
377
- /**
378
- * Cumulative active CPU duration in milliseconds across all sessions.
379
- */
380
- get totalActiveCpuDurationMs(): number | undefined;
381
- /**
382
- * Cumulative wall-clock duration in milliseconds across all sessions.
383
- */
384
- get totalDurationMs(): number | undefined;
385
- /**
386
- * When this sandbox was last updated.
387
- */
388
- get updatedAt(): Date;
389
- /**
390
- * When the sandbox status was last updated.
391
- */
392
- get statusUpdatedAt(): Date | undefined;
393
- /**
394
- * When this sandbox was created.
395
- */
396
- get createdAt(): Date;
397
- /**
398
- * Interactive port.
399
- */
400
- get interactivePort(): number | undefined;
401
- /**
402
- * The default working directory of the current session (e.g.
403
- * `/vercel/sandbox`).
404
- */
405
- get cwd(): string;
406
- /**
407
- * The status of the current session.
408
- */
409
- get status(): SessionMetaData["status"];
410
- /**
411
- * The default timeout of this sandbox in milliseconds.
412
- */
413
- get timeout(): number | undefined;
414
- /**
415
- * When the currently running session will time out.
416
- */
417
- get expiresAt(): Date | undefined;
418
- /**
419
- * Key-value tags attached to the sandbox.
420
- */
421
- get tags(): Record<string, string> | undefined;
422
- /**
423
- * Drives mounted on the sandbox, keyed by mount path.
424
- */
425
- get mounts(): SandboxMounts | undefined;
426
- /**
427
- * The default network policy of this sandbox.
428
- */
429
- get networkPolicy(): NetworkPolicy | undefined;
430
- /**
431
- * If the session was created from a snapshot, the ID of that snapshot.
432
- */
433
- get sourceSnapshotId(): string | undefined;
434
- /**
435
- * The current snapshot ID of this sandbox, if any.
436
- */
437
- get currentSnapshotId(): string | undefined;
438
- /**
439
- * The default snapshot expiration in milliseconds, if set.
440
- */
441
- get snapshotExpiration(): number | undefined;
442
- /**
443
- * The snapshot retention policy (`keep-last-snapshots`) currently configured
444
- * on this sandbox, if any.
445
- */
446
- get keepLastSnapshots(): {
447
- count: number;
448
- expiration?: number;
449
- deleteEvicted?: boolean;
450
- } | undefined;
451
- /**
452
- * The amount of CPU used by the session. Only reported once the VM is stopped.
453
- */
454
- get activeCpuUsageMs(): number | undefined;
455
- /**
456
- * The amount of network data used by the session. Only reported once the VM is stopped.
457
- */
458
- get networkTransfer(): {
459
- ingress: number;
460
- egress: number;
461
- } | undefined;
462
- /**
463
- * Allow to get a list of sandboxes for a team narrowed to the given params.
464
- * It returns both the sandboxes and the pagination metadata to allow getting
465
- * the next page of results.
466
- *
467
- * The returned object is async-iterable to auto-paginate through all pages:
468
- *
469
- * ```ts
470
- * const result = await Sandbox.list({ namePrefix: "ci-" });
471
- * for await (const sandbox of result) { ... }
472
- * // or: await result.toArray();
473
- * // or: for await (const page of result.pages()) { ... }
474
- * ```
475
- */
476
- static list(params?: Partial<Parameters<APIClient["listSandboxes"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<Paginator<{
477
- sandboxes: {
478
- name: string;
479
- persistent: boolean;
480
- createdAt: number;
481
- updatedAt: number;
482
- currentSessionId: string;
483
- status: "pending" | "running" | "stopping" | "stopped" | "failed" | "aborted" | "snapshotting";
484
- region?: string | undefined;
485
- failoverRegions?: string[] | undefined;
486
- vcpus?: number | undefined;
487
- memory?: number | undefined;
488
- runtime?: string | undefined;
489
- image?: string | undefined;
490
- timeout?: number | undefined;
491
- networkPolicy?: {
492
- [x: string]: unknown;
493
- mode: "allow-all";
494
- } | {
495
- [x: string]: unknown;
496
- mode: "deny-all";
497
- } | {
498
- [x: string]: unknown;
499
- mode: "custom";
500
- allowedDomains?: string[] | undefined;
501
- allowedCIDRs?: string[] | undefined;
502
- deniedCIDRs?: string[] | undefined;
503
- injectionRules?: {
504
- domain: string;
505
- headers?: Record<string, string> | undefined;
506
- headerNames?: string[] | undefined;
507
- match?: {
508
- path?: {
509
- exact?: string | undefined;
510
- startsWith?: string | undefined;
511
- regex?: string | undefined;
512
- } | undefined;
513
- method?: string[] | undefined;
514
- queryString?: {
515
- key?: {
516
- exact?: string | undefined;
517
- startsWith?: string | undefined;
518
- regex?: string | undefined;
519
- } | undefined;
520
- value?: {
521
- exact?: string | undefined;
522
- startsWith?: string | undefined;
523
- regex?: string | undefined;
524
- } | undefined;
525
- }[] | undefined;
526
- headers?: {
527
- key?: {
528
- exact?: string | undefined;
529
- startsWith?: string | undefined;
530
- regex?: string | undefined;
531
- } | undefined;
532
- value?: {
533
- exact?: string | undefined;
534
- startsWith?: string | undefined;
535
- regex?: string | undefined;
536
- } | undefined;
537
- }[] | undefined;
538
- } | undefined;
539
- }[] | undefined;
540
- forwardRules?: {
541
- domain: string;
542
- forwardURL: string;
543
- match?: {
544
- path?: {
545
- exact?: string | undefined;
546
- startsWith?: string | undefined;
547
- regex?: string | undefined;
548
- } | undefined;
549
- method?: string[] | undefined;
550
- queryString?: {
551
- key?: {
552
- exact?: string | undefined;
553
- startsWith?: string | undefined;
554
- regex?: string | undefined;
555
- } | undefined;
556
- value?: {
557
- exact?: string | undefined;
558
- startsWith?: string | undefined;
559
- regex?: string | undefined;
560
- } | undefined;
561
- }[] | undefined;
562
- headers?: {
563
- key?: {
564
- exact?: string | undefined;
565
- startsWith?: string | undefined;
566
- regex?: string | undefined;
567
- } | undefined;
568
- value?: {
569
- exact?: string | undefined;
570
- startsWith?: string | undefined;
571
- regex?: string | undefined;
572
- } | undefined;
573
- }[] | undefined;
574
- } | undefined;
575
- }[] | undefined;
576
- } | undefined;
577
- totalEgressBytes?: number | undefined;
578
- totalIngressBytes?: number | undefined;
579
- totalActiveCpuDurationMs?: number | undefined;
580
- totalDurationMs?: number | undefined;
581
- expiresAt?: number | undefined;
582
- currentSnapshotId?: string | undefined;
583
- statusUpdatedAt?: number | undefined;
584
- cwd?: string | undefined;
585
- tags?: Record<string, string> | undefined;
586
- mounts?: Record<string, {
587
- drive: string;
588
- mode?: "read-only" | "read-write" | undefined;
589
- }> | undefined;
590
- snapshotExpiration?: number | undefined;
591
- keepLastSnapshots?: {
592
- count: number;
593
- expiration?: number | undefined;
594
- deleteEvicted?: boolean | undefined;
595
- } | undefined;
596
- }[];
597
- pagination: {
598
- count: number;
599
- next: string | null;
600
- };
601
- }, "sandboxes">>;
602
- /**
603
- * Serialize a Sandbox instance to plain data for @workflow/serde.
604
- *
605
- * @param instance - The Sandbox instance to serialize
606
- * @returns A plain object containing sandbox metadata and routes
607
- */
608
- static [WORKFLOW_SERIALIZE](instance: Sandbox): SerializedSandbox;
609
- /**
610
- * Deserialize a Sandbox from serialized snapshot data.
611
- *
612
- * The deserialized instance uses the serialized metadata synchronously and
613
- * lazily creates an API client only when methods perform API requests.
614
- *
615
- * @param data - The serialized sandbox data
616
- * @returns The reconstructed Sandbox instance
617
- */
618
- static [WORKFLOW_DESERIALIZE](data: SerializedSandbox): Sandbox;
619
- /**
620
- * Create a new sandbox.
621
- *
622
- * By default, the sandbox uses `vercel/sandbox/universal:latest`, an
623
- * Ubuntu-based image with Node.js 24, Bun, Python 3.14, coding agents, and
624
- * common development utilities.
625
- *
626
- * @param params - Creation parameters and optional credentials.
627
- * @returns A promise resolving to the created {@link Sandbox}.
628
- * @example
629
- * <caption>Create a sandbox with default options</caption>
630
- * const sandbox = await Sandbox.create();
631
- *
632
- * @example
633
- * <caption>Create a sandbox and drop it in the end of the block</caption>
634
- * async function fn() {
635
- * await using const sandbox = await Sandbox.create();
636
- * // Sandbox automatically stopped at the end of the lexical scope
637
- * }
638
- */
639
- static create(params?: WithPrivate<CreateSandboxParams | (CreateSandboxParams & Credentials)> & WithFetchOptions): Promise<Sandbox & AsyncDisposable>;
640
- /**
641
- * Fork an existing sandbox into a new one.
642
- *
643
- * The server restores the fork from the source's current snapshot (or its
644
- * base environment when it has none) and copies its config — resources,
645
- * timeout, ports, tags, network policy, image, persistence, snapshot
646
- * settings, and environment variables. Any field passed in `params` overrides
647
- * the copied value.
648
- *
649
- * @param params - Fork parameters and optional credentials.
650
- * `sourceSandbox` is the name of the source sandbox; everything else
651
- * acts as an override.
652
- * @returns A promise resolving to the new {@link Sandbox}.
653
- *
654
- * @example
655
- * <caption>Fork with all config copied from the source</caption>
656
- * const fork = await Sandbox.fork({ sourceSandbox: "prod-agent" });
657
- *
658
- * @example
659
- * <caption>Fork with an explicit new name and overridden vcpus</caption>
660
- * const fork = await Sandbox.fork({
661
- * sourceSandbox: "prod-agent",
662
- * name: "forked-prod-agent",
663
- * resources: { vcpus: 4 },
664
- * });
665
- */
666
- static fork(params: WithPrivate<ForkSandboxParams | (ForkSandboxParams & Credentials)> & WithFetchOptions): Promise<Sandbox & AsyncDisposable>;
667
- /**
668
- * Retrieve an existing sandbox and resume its session.
669
- *
670
- * @param params - Get parameters and optional credentials.
671
- * @returns A promise resolving to the {@link Sandbox}.
672
- */
673
- static get(params: WithPrivate<GetSandboxParams | (GetSandboxParams & Credentials)> & WithFetchOptions): Promise<Sandbox>;
674
- /**
675
- * Retrieve an existing named sandbox, or create a new one if none exists.
676
- *
677
- * If `name` is omitted, this always creates a new sandbox and fires
678
- * `onCreate`. If `name` is provided, it first tries {@link Sandbox.get};
679
- * on `not_found` it creates a new sandbox with that name; on
680
- * `snapshot_not_found` it deletes the stale named sandbox and creates
681
- * a fresh one with the same name.
682
- *
683
- * @param params - Get/create parameters plus an optional `onCreate` hook.
684
- * @returns A promise resolving to the {@link Sandbox}.
685
- *
686
- * @example
687
- * <caption>Idempotent named sandbox with one-time setup</caption>
688
- * const sandbox = await Sandbox.getOrCreate({
689
- * name: "my-workspace",
690
- * onCreate: async (sbx) => {
691
- * await sbx.writeFiles([
692
- * { path: "README.md", content: Buffer.from("# Hello") },
693
- * ]);
694
- * },
695
- * });
696
- *
697
- * @example
698
- * <caption>Unnamed — always creates</caption>
699
- * const sandbox = await Sandbox.getOrCreate({
700
- * onCreate: async (sbx) => {
701
- * await sbx.runCommand("npm", ["install"]);
702
- * },
703
- * });
704
- */
705
- static getOrCreate(params?: WithPrivate<GetOrCreateSandboxParams | (GetOrCreateSandboxParams & Credentials)> & WithFetchOptions): Promise<Sandbox>;
706
- /**
707
- * Create a new Sandbox instance.
708
- *
709
- * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.
710
- * @param params.routes - Port-to-subdomain mappings for exposed ports
711
- * @param params.sandbox - Sandbox snapshot metadata
712
- */
713
- constructor({
714
- client,
715
- routes,
716
- session,
717
- sandbox,
718
- projectId,
719
- onResume
720
- }: {
721
- client?: APIClient;
722
- routes: SandboxRouteData[];
723
- session?: SessionMetaData;
724
- sandbox: SandboxMetaData;
725
- projectId?: string;
726
- onResume?: (sandbox: Sandbox) => Promise<void>;
727
- });
728
- /**
729
- * Get the current session (the running VM) for this sandbox.
730
- *
731
- * @returns The {@link Session} instance.
732
- */
733
- currentSession(): Session;
734
- /**
735
- * Resume this sandbox by creating a new session via `getSandbox`.
736
- */
737
- private resume;
738
- private doResume;
739
- /**
740
- * Poll until the current session reaches a terminal state, then resume.
741
- */
742
- private waitForStopAndResume;
743
- /**
744
- * Execute `fn`, and if the session is stopped/stopping/snapshotting, resume and retry.
745
- */
746
- private withResume;
747
- /**
748
- * Start executing a command in this sandbox.
749
- *
750
- * @param command - The command to execute.
751
- * @param args - Arguments to pass to the command.
752
- * @param opts - Optional parameters.
753
- * @param opts.signal - An AbortSignal to cancel the command execution.
754
- * @param opts.timeoutMs - Maximum time in milliseconds to wait for the
755
- * command to complete. On expiry the process is killed with SIGKILL.
756
- * @returns A {@link CommandFinished} result once execution is done.
757
- */
758
- runCommand(command: string, args?: string[], opts?: {
759
- signal?: AbortSignal;
760
- timeoutMs?: number;
761
- }): Promise<CommandFinished>;
762
- /**
763
- * Start executing a command in detached mode.
764
- *
765
- * @param params - The command parameters.
766
- * @returns A {@link Command} instance for the running command.
767
- */
768
- runCommand(params: RunCommandParams & {
769
- detached: true;
770
- }): Promise<Command>;
771
- /**
772
- * Start executing a command in this sandbox.
773
- *
774
- * @param params - The command parameters.
775
- * @returns A {@link CommandFinished} result once execution is done.
776
- */
777
- runCommand(params: RunCommandParams): Promise<CommandFinished>;
778
- /**
779
- * Internal helper to start a command in the sandbox.
780
- *
781
- * @param params - Command execution parameters.
782
- * @returns A {@link Command} or {@link CommandFinished}, depending on `detached`.
783
- * @internal
784
- */
785
- getCommand(cmdId: string, opts?: {
786
- signal?: AbortSignal;
787
- }): Promise<Command>;
788
- /**
789
- * Create a directory in the filesystem of this sandbox.
790
- *
791
- * @param path - Path of the directory to create
792
- * @param opts - Optional parameters.
793
- * @param opts.signal - An AbortSignal to cancel the operation.
794
- */
795
- mkDir(path: string, opts?: {
796
- signal?: AbortSignal;
797
- }): Promise<void>;
798
- /**
799
- * Open an interactive shell session, resuming the sandbox if needed.
800
- *
801
- * @param opts - Optional parameters.
802
- * @param opts.signal - An AbortSignal to cancel the operation.
803
- * @returns The WebSocket URL and token used to connect to the PTY.
804
- */
805
- openInteractive(opts?: {
806
- signal?: AbortSignal;
807
- }): Promise<{
808
- url: string;
809
- token: string;
810
- }>;
811
- /**
812
- * Read a file from the filesystem of this sandbox as a stream.
813
- *
814
- * @param file - File to read, with path and optional cwd
815
- * @param opts - Optional parameters.
816
- * @param opts.signal - An AbortSignal to cancel the operation.
817
- * @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found
818
- */
819
- readFile(file: {
820
- path: string;
821
- cwd?: string;
822
- }, opts?: {
823
- signal?: AbortSignal;
824
- }): Promise<NodeJS.ReadableStream | null>;
825
- /**
826
- * Read a file from the filesystem of this sandbox as a Buffer.
827
- *
828
- * @param file - File to read, with path and optional cwd
829
- * @param opts - Optional parameters.
830
- * @param opts.signal - An AbortSignal to cancel the operation.
831
- * @returns A promise that resolves to the file contents as a Buffer, or null if file not found
832
- */
833
- readFileToBuffer(file: {
834
- path: string;
835
- cwd?: string;
836
- }, opts?: {
837
- signal?: AbortSignal;
838
- }): Promise<Buffer | null>;
839
- /**
840
- * Download a file from the sandbox to the local filesystem.
841
- *
842
- * @param src - Source file on the sandbox, with path and optional cwd
843
- * @param dst - Destination file on the local machine, with path and optional cwd
844
- * @param opts - Optional parameters.
845
- * @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.
846
- * @param opts.signal - An AbortSignal to cancel the operation.
847
- * @returns The absolute path to the written file, or null if the source file was not found
848
- */
849
- downloadFile(src: {
850
- path: string;
851
- cwd?: string;
852
- }, dst: {
853
- path: string;
854
- cwd?: string;
855
- }, opts?: {
856
- mkdirRecursive?: boolean;
857
- signal?: AbortSignal;
858
- }): Promise<string | null>;
859
- /**
860
- * Write files to the filesystem of this sandbox.
861
- * Defaults to writing to /vercel/sandbox unless an absolute path is specified.
862
- * Writes files using the sandbox's default user.
863
- *
864
- * @param files - Array of files with path, content, and optional mode (permissions)
865
- * @param opts - Optional parameters.
866
- * @param opts.signal - An AbortSignal to cancel the operation.
867
- * @returns A promise that resolves when the files are written
868
- *
869
- * @example
870
- * // Write an executable script
871
- * await sandbox.writeFiles([
872
- * { path: "/usr/local/bin/myscript", content: "#!/bin/bash\necho hello", mode: 0o755 }
873
- * ]);
874
- */
875
- writeFiles(files: {
876
- path: string;
877
- content: string | Uint8Array;
878
- mode?: number;
879
- }[], opts?: {
880
- signal?: AbortSignal;
881
- }): Promise<void>;
882
- /**
883
- * Get the public domain of a port of this sandbox.
884
- *
885
- * @param p - Port number to resolve
886
- * @returns A full domain (e.g. `https://subdomain.vercel.run`)
887
- * @throws If the port has no associated route
888
- */
889
- domain(p: number): string;
890
- /**
891
- * Stop the sandbox.
892
- *
893
- * @param opts - Optional parameters.
894
- * @param opts.signal - An AbortSignal to cancel the operation.
895
- * @returns The final session state after stopping, with optional snapshot metadata.
896
- */
897
- stop(opts?: {
898
- signal?: AbortSignal;
899
- }): Promise<SandboxSnapshot & {
900
- snapshot?: SnapshotMetadata;
901
- }>;
902
- /**
903
- * Update the network policy for this sandbox.
904
- *
905
- * @deprecated Use {@link Sandbox.update} instead.
906
- *
907
- * @param networkPolicy - The new network policy to apply.
908
- * @param opts - Optional parameters.
909
- * @param opts.signal - An AbortSignal to cancel the operation.
910
- * @returns A promise that resolves when the network policy is updated.
911
- *
912
- * @example
913
- * // Restrict to specific domains
914
- * await sandbox.updateNetworkPolicy({
915
- * allow: ["*.npmjs.org", "github.com"],
916
- * });
917
- *
918
- * @example
919
- * // Inject credentials with per-domain transformers
920
- * await sandbox.updateNetworkPolicy({
921
- * allow: {
922
- * "ai-gateway.vercel.sh": [{
923
- * transform: [{
924
- * headers: { authorization: "Bearer ..." }
925
- * }]
926
- * }],
927
- * "*": []
928
- * }
929
- * });
930
- *
931
- * @example
932
- * // Deny all network access
933
- * await sandbox.updateNetworkPolicy("deny-all");
934
- */
935
- updateNetworkPolicy(networkPolicy: NetworkPolicy, opts?: {
936
- signal?: AbortSignal;
937
- }): Promise<NetworkPolicy>;
938
- /**
939
- * Extend the timeout of the sandbox by the specified duration.
940
- *
941
- * This allows you to extend the lifetime of a sandbox up until the maximum
942
- * execution timeout for your plan.
943
- *
944
- * @param duration - The duration in milliseconds to extend the timeout by
945
- * @param opts - Optional parameters.
946
- * @param opts.signal - An AbortSignal to cancel the operation.
947
- * @returns A promise that resolves when the timeout is extended
948
- *
949
- * @example
950
- * const sandbox = await Sandbox.create({ timeout: ms('10m') });
951
- * // Extends timeout by 5 minutes, to a total of 15 minutes.
952
- * await sandbox.extendTimeout(ms('5m'));
953
- */
954
- extendTimeout(duration: number, opts?: {
955
- signal?: AbortSignal;
956
- }): Promise<void>;
957
- /**
958
- * The user that non-`sudo` commands and the HTTP file API run as, together
959
- * with that user's primary group. This depends on the sandbox image. The
960
- * multi-user helpers group-own home and shared directories by this user's
961
- * group so the file API can traverse them, so we resolve it from the running
962
- * sandbox rather than assuming a fixed name.
963
- *
964
- * The result is memoized for the lifetime of this instance.
965
- *
966
- * @internal
967
- */
968
- getDefaultUser(opts?: {
969
- signal?: AbortSignal;
970
- }): Promise<{
971
- username: string;
972
- group: string;
973
- }>;
974
- private resolveDefaultUser;
975
- /**
976
- * Create a new Linux user in this sandbox with an isolated home directory.
977
- *
978
- * The home directory is group-owned by the sandbox's default user group with
979
- * `770` permissions, so the SDK's HTTP file API can read/write directly.
980
- * Other users cannot access this user's home directory since they are not in
981
- * that group.
982
- *
983
- * @param username - Linux username (lowercase letters, digits, hyphens, underscores)
984
- * @param opts - Optional parameters.
985
- * @param opts.signal - An AbortSignal to cancel the operation.
986
- * @returns A {@link SandboxUser} instance for the created user.
987
- *
988
- * @example
989
- * const alice = await sandbox.createUser("alice");
990
- * await alice.runCommand("whoami"); // "alice"
991
- * await alice.writeFiles([{ path: "hello.txt", content: Buffer.from("hi") }]);
992
- */
993
- createUser(username: string, opts?: {
994
- signal?: AbortSignal;
995
- }): Promise<SandboxUser>;
996
- /**
997
- * Get a user handle without creating the user.
998
- * Assumes the user already exists in the sandbox.
999
- *
1000
- * @param username - Linux username
1001
- * @returns A {@link SandboxUser} instance.
1002
- *
1003
- * @example
1004
- * const root = sandbox.asUser("root");
1005
- * await root.runCommand("whoami"); // "root"
1006
- */
1007
- asUser(username: "root" | (string & {})): SandboxUser;
1008
- /**
1009
- * Create a new Linux group with a shared directory.
1010
- *
1011
- * Creates a shared directory at `/shared/<groupname>` with setgid permissions
1012
- * (`2770`), so files created inside it automatically inherit the group.
1013
- * All group members can read and write files in the shared directory.
1014
- *
1015
- * @param groupname - Group name (lowercase letters, digits, hyphens, underscores)
1016
- * @param opts - Optional parameters.
1017
- * @param opts.signal - An AbortSignal to cancel the operation.
1018
- * @returns An object with the group name and shared directory path.
1019
- *
1020
- * @example
1021
- * const devs = await sandbox.createGroup("devs");
1022
- * console.log(devs.sharedDir); // "/shared/devs"
1023
- * await sandbox.addUserToGroup("alice", "devs");
1024
- */
1025
- createGroup(groupname: string, opts?: {
1026
- signal?: AbortSignal;
1027
- }): Promise<{
1028
- groupname: string;
1029
- sharedDir: string;
1030
- }>;
1031
- /**
1032
- * Add a user to a group.
1033
- *
1034
- * After joining, the user can read and write files in the group's
1035
- * shared directory at `/shared/<groupname>`.
1036
- *
1037
- * @param username - The user to add
1038
- * @param groupname - The group to add the user to
1039
- * @param opts - Optional parameters.
1040
- * @param opts.signal - An AbortSignal to cancel the operation.
1041
- *
1042
- * @example
1043
- * await sandbox.addUserToGroup("alice", "devs");
1044
- */
1045
- addUserToGroup(username: string, groupname: string, opts?: {
1046
- signal?: AbortSignal;
1047
- }): Promise<void>;
1048
- /**
1049
- * Remove a user from a group.
1050
- *
1051
- * @param username - The user to remove
1052
- * @param groupname - The group to remove the user from
1053
- * @param opts - Optional parameters.
1054
- * @param opts.signal - An AbortSignal to cancel the operation.
1055
- *
1056
- * @example
1057
- * await sandbox.removeUserFromGroup("alice", "devs");
1058
- */
1059
- removeUserFromGroup(username: string, groupname: string, opts?: {
1060
- signal?: AbortSignal;
1061
- }): Promise<void>;
1062
- /**
1063
- * Create a snapshot from this currently running sandbox. New sandboxes can
1064
- * then be created from this snapshot using {@link Sandbox.createFromSnapshot}.
1065
- *
1066
- * Note: this sandbox will be stopped as part of the snapshot creation process.
1067
- *
1068
- * @param opts - Optional parameters.
1069
- * @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.
1070
- * @param opts.signal - An AbortSignal to cancel the operation.
1071
- * @returns A promise that resolves to the Snapshot instance
1072
- */
1073
- snapshot(opts?: {
1074
- expiration?: number;
1075
- signal?: AbortSignal;
1076
- }): Promise<Snapshot>;
1077
- /**
1078
- * Update the sandbox configuration.
1079
- *
1080
- * When `ports` is provided, it is treated as the full desired port list:
1081
- * any currently exposed port omitted from the array will be deregistered.
1082
- *
1083
- * When `timeout` is increased and a session is currently running, the running
1084
- * session's deadline is also extended.
1085
- *
1086
- * `region` and `failoverRegions` apply to the next session; the currently
1087
- * running session keeps the region it started in. Pass an empty
1088
- * `failoverRegions` array to remove all failover regions.
1089
- *
1090
- * @param params - Fields to update.
1091
- * @param opts - Optional abort signal.
1092
- */
1093
- update(params: {
1094
- persistent?: boolean;
1095
- resources?: {
1096
- vcpus?: number;
1097
- };
1098
- timeout?: number;
1099
- networkPolicy?: NetworkPolicy;
1100
- tags?: Record<string, string>;
1101
- ports?: number[];
1102
- snapshotExpiration?: number;
1103
- keepLastSnapshots?: {
1104
- count: number;
1105
- expiration?: number;
1106
- deleteEvicted?: boolean;
1107
- } | null;
1108
- currentSnapshotId?: string;
1109
- region?: SandboxRegion;
1110
- failoverRegions?: SandboxRegion[];
1111
- }, opts?: {
1112
- signal?: AbortSignal;
1113
- }): Promise<void>;
1114
- /**
1115
- * Delete this sandbox.
1116
- *
1117
- * After deletion the instance becomes inert — all further API calls will
1118
- * throw immediately.
1119
- */
1120
- delete(opts?: {
1121
- signal?: AbortSignal;
1122
- }): Promise<void>;
1123
- /**
1124
- * List sessions (VMs) that have been created for this sandbox.
1125
- *
1126
- * @param params - Optional pagination parameters.
1127
- * @returns The list of sessions and pagination metadata.
1128
- */
1129
- listSessions(params?: {
1130
- limit?: number;
1131
- cursor?: string;
1132
- sortOrder?: "asc" | "desc";
1133
- signal?: AbortSignal;
1134
- }): Promise<Paginator<{
1135
- sessions: {
1136
- [x: string]: unknown;
1137
- id: string;
1138
- memory: number;
1139
- vcpus: number;
1140
- region: string;
1141
- timeout: number;
1142
- status: "pending" | "running" | "stopping" | "stopped" | "failed" | "aborted" | "snapshotting";
1143
- requestedAt: number;
1144
- createdAt: number;
1145
- cwd: string;
1146
- updatedAt: number;
1147
- runtime?: string | undefined;
1148
- startedAt?: number | undefined;
1149
- requestedStopAt?: number | undefined;
1150
- stoppedAt?: number | undefined;
1151
- abortedAt?: number | undefined;
1152
- duration?: number | undefined;
1153
- sourceSnapshotId?: string | undefined;
1154
- snapshottedAt?: number | undefined;
1155
- interactivePort?: number | undefined;
1156
- networkPolicy?: {
1157
- [x: string]: unknown;
1158
- mode: "allow-all";
1159
- } | {
1160
- [x: string]: unknown;
1161
- mode: "deny-all";
1162
- } | {
1163
- [x: string]: unknown;
1164
- mode: "custom";
1165
- allowedDomains?: string[] | undefined;
1166
- allowedCIDRs?: string[] | undefined;
1167
- deniedCIDRs?: string[] | undefined;
1168
- injectionRules?: {
1169
- domain: string;
1170
- headers?: Record<string, string> | undefined;
1171
- headerNames?: string[] | undefined;
1172
- match?: {
1173
- path?: {
1174
- exact?: string | undefined;
1175
- startsWith?: string | undefined;
1176
- regex?: string | undefined;
1177
- } | undefined;
1178
- method?: string[] | undefined;
1179
- queryString?: {
1180
- key?: {
1181
- exact?: string | undefined;
1182
- startsWith?: string | undefined;
1183
- regex?: string | undefined;
1184
- } | undefined;
1185
- value?: {
1186
- exact?: string | undefined;
1187
- startsWith?: string | undefined;
1188
- regex?: string | undefined;
1189
- } | undefined;
1190
- }[] | undefined;
1191
- headers?: {
1192
- key?: {
1193
- exact?: string | undefined;
1194
- startsWith?: string | undefined;
1195
- regex?: string | undefined;
1196
- } | undefined;
1197
- value?: {
1198
- exact?: string | undefined;
1199
- startsWith?: string | undefined;
1200
- regex?: string | undefined;
1201
- } | undefined;
1202
- }[] | undefined;
1203
- } | undefined;
1204
- }[] | undefined;
1205
- forwardRules?: {
1206
- domain: string;
1207
- forwardURL: string;
1208
- match?: {
1209
- path?: {
1210
- exact?: string | undefined;
1211
- startsWith?: string | undefined;
1212
- regex?: string | undefined;
1213
- } | undefined;
1214
- method?: string[] | undefined;
1215
- queryString?: {
1216
- key?: {
1217
- exact?: string | undefined;
1218
- startsWith?: string | undefined;
1219
- regex?: string | undefined;
1220
- } | undefined;
1221
- value?: {
1222
- exact?: string | undefined;
1223
- startsWith?: string | undefined;
1224
- regex?: string | undefined;
1225
- } | undefined;
1226
- }[] | undefined;
1227
- headers?: {
1228
- key?: {
1229
- exact?: string | undefined;
1230
- startsWith?: string | undefined;
1231
- regex?: string | undefined;
1232
- } | undefined;
1233
- value?: {
1234
- exact?: string | undefined;
1235
- startsWith?: string | undefined;
1236
- regex?: string | undefined;
1237
- } | undefined;
1238
- }[] | undefined;
1239
- } | undefined;
1240
- }[] | undefined;
1241
- } | undefined;
1242
- activeCpuDurationMs?: number | undefined;
1243
- networkTransfer?: {
1244
- ingress: number;
1245
- egress: number;
1246
- } | undefined;
1247
- }[];
1248
- pagination: {
1249
- count: number;
1250
- next: string | null;
1251
- };
1252
- }, "sessions">>;
1253
- /**
1254
- * List snapshots that belong to this sandbox.
1255
- *
1256
- * @param params - Optional pagination parameters.
1257
- * @returns The list of snapshots and pagination metadata.
1258
- */
1259
- listSnapshots(params?: {
1260
- limit?: number;
1261
- cursor?: string;
1262
- sortOrder?: "asc" | "desc";
1263
- signal?: AbortSignal;
1264
- }): Promise<Paginator<{
1265
- snapshots: {
1266
- id: string;
1267
- sourceSessionId: string;
1268
- region: string;
1269
- status: "failed" | "created" | "deleted";
1270
- sizeBytes: number;
1271
- createdAt: number;
1272
- updatedAt: number;
1273
- regions?: string[] | undefined;
1274
- expiresAt?: number | undefined;
1275
- lastUsedAt?: number | undefined;
1276
- creationMethod?: string | undefined;
1277
- parentId?: string | undefined;
1278
- }[];
1279
- pagination: {
1280
- count: number;
1281
- next: string | null;
1282
- };
1283
- }, "snapshots">>;
1284
- }
1285
- //#endregion
1286
- export { BaseCreateSandboxParams, Sandbox, SandboxMountMode, SandboxMounts, SerializedSandbox };
1287
- //# sourceMappingURL=sandbox.d.ts.map