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