@vercel/sandbox 1.8.1 → 1.9.1
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/README.md +8 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/api-client/api-client.cjs +375 -0
- package/dist/api-client/api-client.cjs.map +1 -0
- package/dist/api-client/api-client.d.cts +403 -0
- package/dist/api-client/api-client.d.ts +397 -391
- package/dist/api-client/api-client.js +365 -404
- package/dist/api-client/api-client.js.map +1 -1
- package/dist/api-client/api-error.cjs +31 -0
- package/dist/api-client/api-error.cjs.map +1 -0
- package/dist/api-client/api-error.d.cts +27 -0
- package/dist/api-client/api-error.d.ts +19 -16
- package/dist/api-client/api-error.js +27 -32
- package/dist/api-client/api-error.js.map +1 -1
- package/dist/api-client/base-client.cjs +113 -0
- package/dist/api-client/base-client.cjs.map +1 -0
- package/dist/api-client/base-client.d.cts +38 -0
- package/dist/api-client/base-client.d.ts +31 -36
- package/dist/api-client/base-client.js +101 -118
- package/dist/api-client/base-client.js.map +1 -1
- package/dist/api-client/file-writer.cjs +62 -0
- package/dist/api-client/file-writer.cjs.map +1 -0
- package/dist/api-client/file-writer.d.cts +66 -0
- package/dist/api-client/file-writer.d.ts +56 -42
- package/dist/api-client/file-writer.js +57 -61
- package/dist/api-client/file-writer.js.map +1 -1
- package/dist/api-client/index.cjs +2 -0
- package/dist/api-client/index.d.ts +2 -2
- package/dist/api-client/index.js +4 -21
- package/dist/api-client/validators.cjs +149 -0
- package/dist/api-client/validators.cjs.map +1 -0
- package/dist/api-client/validators.d.cts +1677 -0
- package/dist/api-client/validators.d.ts +1501 -2412
- package/dist/api-client/validators.js +124 -154
- package/dist/api-client/validators.js.map +1 -1
- package/dist/api-client/with-retry.cjs +89 -0
- package/dist/api-client/with-retry.cjs.map +1 -0
- package/dist/api-client/with-retry.d.cts +10 -0
- package/dist/api-client/with-retry.d.ts +9 -13
- package/dist/api-client/with-retry.js +81 -102
- package/dist/api-client/with-retry.js.map +1 -1
- package/dist/auth/api.cjs +29 -0
- package/dist/auth/api.cjs.map +1 -0
- package/dist/auth/api.js +26 -25
- package/dist/auth/api.js.map +1 -1
- package/dist/auth/error.cjs +13 -0
- package/dist/auth/error.cjs.map +1 -0
- package/dist/auth/error.js +11 -11
- package/dist/auth/error.js.map +1 -1
- package/dist/auth/file.cjs +64 -0
- package/dist/auth/file.cjs.map +1 -0
- package/dist/auth/file.d.cts +26 -0
- package/dist/auth/file.d.ts +19 -15
- package/dist/auth/file.js +49 -64
- package/dist/auth/file.js.map +1 -1
- package/dist/auth/index.cjs +12 -0
- package/dist/auth/index.d.cts +5 -0
- package/dist/auth/index.d.ts +5 -6
- package/dist/auth/index.js +6 -27
- package/dist/auth/linked-project.cjs +38 -0
- package/dist/auth/linked-project.cjs.map +1 -0
- package/dist/auth/linked-project.js +30 -64
- package/dist/auth/linked-project.js.map +1 -1
- package/dist/auth/oauth.cjs +205 -0
- package/dist/auth/oauth.cjs.map +1 -0
- package/dist/auth/oauth.d.cts +135 -0
- package/dist/auth/oauth.d.ts +113 -109
- package/dist/auth/oauth.js +185 -252
- package/dist/auth/oauth.js.map +1 -1
- package/dist/auth/poll-for-token.cjs +82 -0
- package/dist/auth/poll-for-token.cjs.map +1 -0
- package/dist/auth/poll-for-token.d.cts +28 -0
- package/dist/auth/poll-for-token.d.ts +23 -15
- package/dist/auth/poll-for-token.js +79 -64
- package/dist/auth/poll-for-token.js.map +1 -1
- package/dist/auth/project.cjs +80 -0
- package/dist/auth/project.cjs.map +1 -0
- package/dist/auth/project.d.cts +44 -0
- package/dist/auth/project.d.ts +12 -8
- package/dist/auth/project.js +70 -72
- package/dist/auth/project.js.map +1 -1
- package/dist/auth/zod.cjs +22 -0
- package/dist/auth/zod.cjs.map +1 -0
- package/dist/auth/zod.js +18 -17
- package/dist/auth/zod.js.map +1 -1
- package/dist/command.cjs +326 -0
- package/dist/command.cjs.map +1 -0
- package/dist/command.d.cts +289 -0
- package/dist/command.d.ts +265 -171
- package/dist/command.js +321 -226
- package/dist/command.js.map +1 -1
- package/dist/constants.d.cts +5 -0
- package/dist/constants.d.ts +5 -1
- package/dist/index.cjs +11 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -15
- package/dist/network-policy.d.cts +100 -0
- package/dist/network-policy.d.ts +32 -28
- package/dist/sandbox.cjs +543 -0
- package/dist/sandbox.cjs.map +1 -0
- package/dist/sandbox.d.cts +538 -0
- package/dist/sandbox.d.ts +521 -472
- package/dist/sandbox.js +539 -506
- package/dist/sandbox.js.map +1 -1
- package/dist/snapshot.cjs +116 -0
- package/dist/snapshot.cjs.map +1 -0
- package/dist/snapshot.d.cts +109 -0
- package/dist/snapshot.d.ts +100 -92
- package/dist/snapshot.js +114 -114
- package/dist/snapshot.js.map +1 -1
- package/dist/utils/array.cjs +17 -0
- package/dist/utils/array.cjs.map +1 -0
- package/dist/utils/array.js +12 -15
- package/dist/utils/array.js.map +1 -1
- package/dist/utils/consume-readable.cjs +18 -0
- package/dist/utils/consume-readable.cjs.map +1 -0
- package/dist/utils/consume-readable.js +13 -12
- package/dist/utils/consume-readable.js.map +1 -1
- package/dist/utils/decode-base64-url.cjs +15 -0
- package/dist/utils/decode-base64-url.cjs.map +1 -0
- package/dist/utils/decode-base64-url.js +10 -9
- package/dist/utils/decode-base64-url.js.map +1 -1
- package/dist/utils/dev-credentials.cjs +142 -0
- package/dist/utils/dev-credentials.cjs.map +1 -0
- package/dist/utils/dev-credentials.js +126 -184
- package/dist/utils/dev-credentials.js.map +1 -1
- package/dist/utils/get-credentials.cjs +123 -0
- package/dist/utils/get-credentials.cjs.map +1 -0
- package/dist/utils/get-credentials.d.cts +21 -0
- package/dist/utils/get-credentials.d.ts +19 -61
- package/dist/utils/get-credentials.js +106 -140
- package/dist/utils/get-credentials.js.map +1 -1
- package/dist/utils/log.cjs +25 -0
- package/dist/utils/log.cjs.map +1 -0
- package/dist/utils/log.js +15 -17
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/network-policy.cjs +65 -0
- package/dist/utils/network-policy.cjs.map +1 -0
- package/dist/utils/network-policy.js +58 -77
- package/dist/utils/network-policy.js.map +1 -1
- package/dist/utils/normalizePath.cjs +27 -0
- package/dist/utils/normalizePath.cjs.map +1 -0
- package/dist/utils/normalizePath.js +21 -28
- package/dist/utils/normalizePath.js.map +1 -1
- package/dist/utils/resolveSignal.cjs +20 -0
- package/dist/utils/resolveSignal.cjs.map +1 -0
- package/dist/utils/resolveSignal.d.cts +15 -0
- package/dist/utils/resolveSignal.d.ts +12 -10
- package/dist/utils/resolveSignal.js +14 -17
- package/dist/utils/resolveSignal.js.map +1 -1
- package/dist/utils/sandbox-snapshot.cjs +14 -0
- package/dist/utils/sandbox-snapshot.cjs.map +1 -0
- package/dist/utils/sandbox-snapshot.d.cts +10 -0
- package/dist/utils/sandbox-snapshot.d.ts +11 -0
- package/dist/utils/sandbox-snapshot.js +14 -0
- package/dist/utils/sandbox-snapshot.js.map +1 -0
- package/dist/utils/types.cjs +13 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +11 -0
- package/dist/utils/types.d.ts +5 -7
- package/dist/utils/types.js +8 -8
- package/dist/utils/types.js.map +1 -1
- package/dist/version.cjs +7 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +5 -5
- package/dist/version.js.map +1 -1
- package/package.json +23 -3
- package/dist/api-client/index.js.map +0 -1
- package/dist/auth/api.d.ts +0 -6
- package/dist/auth/error.d.ts +0 -11
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/linked-project.d.ts +0 -10
- package/dist/auth/zod.d.ts +0 -5
- package/dist/constants.js +0 -3
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/network-policy.js +0 -3
- package/dist/network-policy.js.map +0 -1
- package/dist/utils/array.d.ts +0 -9
- package/dist/utils/consume-readable.d.ts +0 -5
- package/dist/utils/convert-sandbox.d.ts +0 -6
- package/dist/utils/convert-sandbox.js +0 -14
- package/dist/utils/convert-sandbox.js.map +0 -1
- package/dist/utils/decode-base64-url.d.ts +0 -7
- package/dist/utils/dev-credentials.d.ts +0 -37
- package/dist/utils/log.d.ts +0 -2
- package/dist/utils/network-policy.d.ts +0 -7
- package/dist/utils/normalizePath.d.ts +0 -17
- package/dist/version.d.ts +0 -1
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import { Parsed } from "./api-client/base-client.cjs";
|
|
2
|
+
import { SandboxMetaData, SandboxRouteData } from "./api-client/validators.cjs";
|
|
3
|
+
import { NetworkPolicy, NetworkPolicyRule, NetworkTransformer } from "./network-policy.cjs";
|
|
4
|
+
import { WithPrivate } from "./utils/types.cjs";
|
|
5
|
+
import { RUNTIMES } from "./constants.cjs";
|
|
6
|
+
import { APIClient, WithFetchOptions } from "./api-client/api-client.cjs";
|
|
7
|
+
import { Command, CommandFinished } from "./command.cjs";
|
|
8
|
+
import { Credentials } from "./utils/get-credentials.cjs";
|
|
9
|
+
import { Snapshot } from "./snapshot.cjs";
|
|
10
|
+
import { SandboxSnapshot } from "./utils/sandbox-snapshot.cjs";
|
|
11
|
+
import * as zod0 from "zod";
|
|
12
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
|
|
13
|
+
import { Writable } from "stream";
|
|
14
|
+
|
|
15
|
+
//#region src/sandbox.d.ts
|
|
16
|
+
/** @inline */
|
|
17
|
+
interface BaseCreateSandboxParams {
|
|
18
|
+
/**
|
|
19
|
+
* The source of the sandbox.
|
|
20
|
+
*
|
|
21
|
+
* Omit this parameter start a sandbox without a source.
|
|
22
|
+
*
|
|
23
|
+
* For git sources:
|
|
24
|
+
* - `depth`: Creates shallow clones with limited commit history (minimum: 1)
|
|
25
|
+
* - `revision`: Clones and checks out a specific commit, branch, or tag
|
|
26
|
+
*/
|
|
27
|
+
source?: {
|
|
28
|
+
type: "git";
|
|
29
|
+
url: string;
|
|
30
|
+
depth?: number;
|
|
31
|
+
revision?: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: "git";
|
|
34
|
+
url: string;
|
|
35
|
+
username: string;
|
|
36
|
+
password: string;
|
|
37
|
+
depth?: number;
|
|
38
|
+
revision?: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: "tarball";
|
|
41
|
+
url: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Array of port numbers to expose from the sandbox. Sandboxes can
|
|
45
|
+
* expose up to 4 ports.
|
|
46
|
+
*/
|
|
47
|
+
ports?: number[];
|
|
48
|
+
/**
|
|
49
|
+
* Timeout in milliseconds before the sandbox auto-terminates.
|
|
50
|
+
*/
|
|
51
|
+
timeout?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Resources to allocate to the sandbox.
|
|
54
|
+
*
|
|
55
|
+
* Your sandbox will get the amount of vCPUs you specify here and
|
|
56
|
+
* 2048 MB of memory per vCPU.
|
|
57
|
+
*/
|
|
58
|
+
resources?: {
|
|
59
|
+
vcpus: number;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The runtime of the sandbox, currently only `node24`, `node22` and `python3.13` are supported.
|
|
63
|
+
* If not specified, the default runtime `node24` will be used.
|
|
64
|
+
*/
|
|
65
|
+
runtime?: RUNTIMES | (string & {});
|
|
66
|
+
/**
|
|
67
|
+
* Network policy to define network restrictions for the sandbox.
|
|
68
|
+
* Defaults to full internet access if not specified.
|
|
69
|
+
*/
|
|
70
|
+
networkPolicy?: NetworkPolicy;
|
|
71
|
+
/**
|
|
72
|
+
* Default environment variables for the sandbox.
|
|
73
|
+
* These are inherited by all commands unless overridden with
|
|
74
|
+
* the `env` option in `runCommand`.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* const sandbox = await Sandbox.create({
|
|
78
|
+
* env: { NODE_ENV: "production", API_KEY: "secret" },
|
|
79
|
+
* });
|
|
80
|
+
* // All commands will have NODE_ENV and API_KEY set
|
|
81
|
+
* await sandbox.runCommand("node", ["app.js"]);
|
|
82
|
+
*/
|
|
83
|
+
env?: Record<string, string>;
|
|
84
|
+
/**
|
|
85
|
+
* An AbortSignal to cancel sandbox creation.
|
|
86
|
+
*/
|
|
87
|
+
signal?: AbortSignal;
|
|
88
|
+
}
|
|
89
|
+
type CreateSandboxParams = BaseCreateSandboxParams | (Omit<BaseCreateSandboxParams, "runtime" | "source"> & {
|
|
90
|
+
source: {
|
|
91
|
+
type: "snapshot";
|
|
92
|
+
snapshotId: string;
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
/** @inline */
|
|
96
|
+
interface GetSandboxParams {
|
|
97
|
+
/**
|
|
98
|
+
* Unique identifier of the sandbox.
|
|
99
|
+
*/
|
|
100
|
+
sandboxId: string;
|
|
101
|
+
/**
|
|
102
|
+
* An AbortSignal to cancel the operation.
|
|
103
|
+
*/
|
|
104
|
+
signal?: AbortSignal;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Serialized representation of a Sandbox for @workflow/serde.
|
|
108
|
+
*/
|
|
109
|
+
interface SerializedSandbox {
|
|
110
|
+
metadata: SandboxSnapshot;
|
|
111
|
+
routes: SandboxRouteData[];
|
|
112
|
+
}
|
|
113
|
+
/** @inline */
|
|
114
|
+
interface RunCommandParams {
|
|
115
|
+
/**
|
|
116
|
+
* The command to execute
|
|
117
|
+
*/
|
|
118
|
+
cmd: string;
|
|
119
|
+
/**
|
|
120
|
+
* Arguments to pass to the command
|
|
121
|
+
*/
|
|
122
|
+
args?: string[];
|
|
123
|
+
/**
|
|
124
|
+
* Working directory to execute the command in
|
|
125
|
+
*/
|
|
126
|
+
cwd?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Environment variables to set for this command
|
|
129
|
+
*/
|
|
130
|
+
env?: Record<string, string>;
|
|
131
|
+
/**
|
|
132
|
+
* If true, execute this command with root privileges. Defaults to false.
|
|
133
|
+
*/
|
|
134
|
+
sudo?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* If true, the command will return without waiting for `exitCode`
|
|
137
|
+
*/
|
|
138
|
+
detached?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* A `Writable` stream where `stdout` from the command will be piped
|
|
141
|
+
*/
|
|
142
|
+
stdout?: Writable;
|
|
143
|
+
/**
|
|
144
|
+
* A `Writable` stream where `stderr` from the command will be piped
|
|
145
|
+
*/
|
|
146
|
+
stderr?: Writable;
|
|
147
|
+
/**
|
|
148
|
+
* An AbortSignal to cancel the command execution
|
|
149
|
+
*/
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A Sandbox is an isolated Linux MicroVM to run commands in.
|
|
154
|
+
*
|
|
155
|
+
* Use {@link Sandbox.create} or {@link Sandbox.get} to construct.
|
|
156
|
+
* @hideconstructor
|
|
157
|
+
*/
|
|
158
|
+
declare class Sandbox {
|
|
159
|
+
private _client;
|
|
160
|
+
/**
|
|
161
|
+
* Lazily resolve credentials and construct an API client.
|
|
162
|
+
* This is used in step contexts where the Sandbox was deserialized
|
|
163
|
+
* without a client (e.g. when crossing workflow/step boundaries).
|
|
164
|
+
* Uses getCredentials() which resolves from OIDC or env vars.
|
|
165
|
+
* @internal
|
|
166
|
+
*/
|
|
167
|
+
private ensureClient;
|
|
168
|
+
/**
|
|
169
|
+
* Routes from ports to subdomains.
|
|
170
|
+
/* @hidden
|
|
171
|
+
*/
|
|
172
|
+
readonly routes: SandboxRouteData[];
|
|
173
|
+
/**
|
|
174
|
+
* Unique ID of this sandbox.
|
|
175
|
+
*/
|
|
176
|
+
get sandboxId(): string;
|
|
177
|
+
get interactivePort(): number | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* The status of the sandbox.
|
|
180
|
+
*/
|
|
181
|
+
get status(): SandboxMetaData["status"];
|
|
182
|
+
/**
|
|
183
|
+
* The creation date of the sandbox.
|
|
184
|
+
*/
|
|
185
|
+
get createdAt(): Date;
|
|
186
|
+
/**
|
|
187
|
+
* The timeout of the sandbox in milliseconds.
|
|
188
|
+
*/
|
|
189
|
+
get timeout(): number;
|
|
190
|
+
/**
|
|
191
|
+
* The network policy of the sandbox.
|
|
192
|
+
*/
|
|
193
|
+
get networkPolicy(): NetworkPolicy | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* If the sandbox was created from a snapshot, the ID of that snapshot.
|
|
196
|
+
*/
|
|
197
|
+
get sourceSnapshotId(): string | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* The amount of CPU used by the sandbox. Only reported once the VM is stopped.
|
|
200
|
+
*/
|
|
201
|
+
get activeCpuUsageMs(): number | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* The amount of network data used by the sandbox. Only reported once the VM is stopped.
|
|
204
|
+
*/
|
|
205
|
+
get networkTransfer(): {
|
|
206
|
+
ingress: number;
|
|
207
|
+
egress: number;
|
|
208
|
+
} | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Internal metadata about this sandbox.
|
|
211
|
+
*/
|
|
212
|
+
private sandbox;
|
|
213
|
+
/**
|
|
214
|
+
* Allow to get a list of sandboxes for a team narrowed to the given params.
|
|
215
|
+
* It returns both the sandboxes and the pagination metadata to allow getting
|
|
216
|
+
* the next page of results.
|
|
217
|
+
*/
|
|
218
|
+
static list(params?: Partial<Parameters<APIClient["listSandboxes"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<Parsed<{
|
|
219
|
+
sandboxes: {
|
|
220
|
+
status: "aborted" | "pending" | "running" | "stopping" | "stopped" | "failed" | "snapshotting";
|
|
221
|
+
id: string;
|
|
222
|
+
memory: number;
|
|
223
|
+
vcpus: number;
|
|
224
|
+
region: string;
|
|
225
|
+
runtime: string;
|
|
226
|
+
timeout: number;
|
|
227
|
+
requestedAt: number;
|
|
228
|
+
createdAt: number;
|
|
229
|
+
cwd: string;
|
|
230
|
+
updatedAt: number;
|
|
231
|
+
startedAt?: number | undefined;
|
|
232
|
+
requestedStopAt?: number | undefined;
|
|
233
|
+
stoppedAt?: number | undefined;
|
|
234
|
+
abortedAt?: number | undefined;
|
|
235
|
+
duration?: number | undefined;
|
|
236
|
+
sourceSnapshotId?: string | undefined;
|
|
237
|
+
snapshottedAt?: number | undefined;
|
|
238
|
+
interactivePort?: number | undefined;
|
|
239
|
+
networkPolicy?: zod0.objectInputType<{
|
|
240
|
+
mode: zod0.ZodLiteral<"allow-all">;
|
|
241
|
+
}, zod0.ZodTypeAny, "passthrough"> | zod0.objectInputType<{
|
|
242
|
+
mode: zod0.ZodLiteral<"deny-all">;
|
|
243
|
+
}, zod0.ZodTypeAny, "passthrough"> | zod0.objectInputType<{
|
|
244
|
+
mode: zod0.ZodLiteral<"custom">;
|
|
245
|
+
allowedDomains: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
|
|
246
|
+
allowedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
|
|
247
|
+
deniedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
|
|
248
|
+
injectionRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
|
|
249
|
+
domain: zod0.ZodString;
|
|
250
|
+
headers: zod0.ZodOptional<zod0.ZodRecord<zod0.ZodString, zod0.ZodString>>;
|
|
251
|
+
headerNames: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
|
|
252
|
+
}, "strip", zod0.ZodTypeAny, {
|
|
253
|
+
domain: string;
|
|
254
|
+
headers?: Record<string, string> | undefined;
|
|
255
|
+
headerNames?: string[] | undefined;
|
|
256
|
+
}, {
|
|
257
|
+
domain: string;
|
|
258
|
+
headers?: Record<string, string> | undefined;
|
|
259
|
+
headerNames?: string[] | undefined;
|
|
260
|
+
}>, "many">>;
|
|
261
|
+
}, zod0.ZodTypeAny, "passthrough"> | undefined;
|
|
262
|
+
activeCpuDurationMs?: number | undefined;
|
|
263
|
+
networkTransfer?: {
|
|
264
|
+
ingress: number;
|
|
265
|
+
egress: number;
|
|
266
|
+
} | undefined;
|
|
267
|
+
}[];
|
|
268
|
+
pagination: {
|
|
269
|
+
count: number;
|
|
270
|
+
next: number | null;
|
|
271
|
+
prev: number | null;
|
|
272
|
+
};
|
|
273
|
+
}>>;
|
|
274
|
+
/**
|
|
275
|
+
* Serialize a Sandbox instance to plain data for @workflow/serde.
|
|
276
|
+
*
|
|
277
|
+
* @param instance - The Sandbox instance to serialize
|
|
278
|
+
* @returns A plain object containing sandbox metadata and routes
|
|
279
|
+
*/
|
|
280
|
+
static [WORKFLOW_SERIALIZE](instance: Sandbox): SerializedSandbox;
|
|
281
|
+
/**
|
|
282
|
+
* Deserialize a Sandbox from serialized snapshot data.
|
|
283
|
+
*
|
|
284
|
+
* The deserialized instance uses the serialized metadata synchronously and
|
|
285
|
+
* lazily creates an API client only when methods perform API requests.
|
|
286
|
+
*
|
|
287
|
+
* @param data - The serialized sandbox data
|
|
288
|
+
* @returns The reconstructed Sandbox instance
|
|
289
|
+
*/
|
|
290
|
+
static [WORKFLOW_DESERIALIZE](data: SerializedSandbox): Sandbox;
|
|
291
|
+
/**
|
|
292
|
+
* Create a new sandbox.
|
|
293
|
+
*
|
|
294
|
+
* @param params - Creation parameters and optional credentials.
|
|
295
|
+
* @returns A promise resolving to the created {@link Sandbox}.
|
|
296
|
+
* @example
|
|
297
|
+
* <caption>Create a sandbox and drop it in the end of the block</caption>
|
|
298
|
+
* async function fn() {
|
|
299
|
+
* await using const sandbox = await Sandbox.create();
|
|
300
|
+
* // Sandbox automatically stopped at the end of the lexical scope
|
|
301
|
+
* }
|
|
302
|
+
*/
|
|
303
|
+
static create(params?: WithPrivate<CreateSandboxParams | (CreateSandboxParams & Credentials)> & WithFetchOptions): Promise<Sandbox & AsyncDisposable>;
|
|
304
|
+
/**
|
|
305
|
+
* Retrieve an existing sandbox.
|
|
306
|
+
*
|
|
307
|
+
* @param params - Get parameters and optional credentials.
|
|
308
|
+
* @returns A promise resolving to the {@link Sandbox}.
|
|
309
|
+
*/
|
|
310
|
+
static get(params: WithPrivate<GetSandboxParams | (GetSandboxParams & Credentials)> & WithFetchOptions): Promise<Sandbox>;
|
|
311
|
+
/**
|
|
312
|
+
* Create a new Sandbox instance.
|
|
313
|
+
*
|
|
314
|
+
* @param params.client - Optional API client. If not provided, will be lazily created using global credentials.
|
|
315
|
+
* @param params.routes - Port-to-subdomain mappings for exposed ports
|
|
316
|
+
* @param params.sandbox - Sandbox snapshot metadata
|
|
317
|
+
*/
|
|
318
|
+
constructor({
|
|
319
|
+
client,
|
|
320
|
+
routes,
|
|
321
|
+
sandbox
|
|
322
|
+
}: {
|
|
323
|
+
client?: APIClient;
|
|
324
|
+
routes: SandboxRouteData[];
|
|
325
|
+
sandbox: SandboxSnapshot;
|
|
326
|
+
});
|
|
327
|
+
/**
|
|
328
|
+
* Get a previously run command by its ID.
|
|
329
|
+
*
|
|
330
|
+
* @param cmdId - ID of the command to retrieve
|
|
331
|
+
* @param opts - Optional parameters.
|
|
332
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
333
|
+
* @returns A {@link Command} instance representing the command
|
|
334
|
+
*/
|
|
335
|
+
getCommand(cmdId: string, opts?: {
|
|
336
|
+
signal?: AbortSignal;
|
|
337
|
+
}): Promise<Command>;
|
|
338
|
+
/**
|
|
339
|
+
* Start executing a command in this sandbox.
|
|
340
|
+
*
|
|
341
|
+
* @param command - The command to execute.
|
|
342
|
+
* @param args - Arguments to pass to the command.
|
|
343
|
+
* @param opts - Optional parameters.
|
|
344
|
+
* @param opts.signal - An AbortSignal to cancel the command execution.
|
|
345
|
+
* @returns A {@link CommandFinished} result once execution is done.
|
|
346
|
+
*/
|
|
347
|
+
runCommand(command: string, args?: string[], opts?: {
|
|
348
|
+
signal?: AbortSignal;
|
|
349
|
+
}): Promise<CommandFinished>;
|
|
350
|
+
/**
|
|
351
|
+
* Start executing a command in detached mode.
|
|
352
|
+
*
|
|
353
|
+
* @param params - The command parameters.
|
|
354
|
+
* @returns A {@link Command} instance for the running command.
|
|
355
|
+
*/
|
|
356
|
+
runCommand(params: RunCommandParams & {
|
|
357
|
+
detached: true;
|
|
358
|
+
}): Promise<Command>;
|
|
359
|
+
/**
|
|
360
|
+
* Start executing a command in this sandbox.
|
|
361
|
+
*
|
|
362
|
+
* @param params - The command parameters.
|
|
363
|
+
* @returns A {@link CommandFinished} result once execution is done.
|
|
364
|
+
*/
|
|
365
|
+
runCommand(params: RunCommandParams): Promise<CommandFinished>;
|
|
366
|
+
/**
|
|
367
|
+
* Create a directory in the filesystem of this sandbox.
|
|
368
|
+
*
|
|
369
|
+
* @param path - Path of the directory to create
|
|
370
|
+
* @param opts - Optional parameters.
|
|
371
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
372
|
+
*/
|
|
373
|
+
mkDir(path: string, opts?: {
|
|
374
|
+
signal?: AbortSignal;
|
|
375
|
+
}): Promise<void>;
|
|
376
|
+
/**
|
|
377
|
+
* Read a file from the filesystem of this sandbox as a stream.
|
|
378
|
+
*
|
|
379
|
+
* @param file - File to read, with path and optional cwd
|
|
380
|
+
* @param opts - Optional parameters.
|
|
381
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
382
|
+
* @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found
|
|
383
|
+
*/
|
|
384
|
+
readFile(file: {
|
|
385
|
+
path: string;
|
|
386
|
+
cwd?: string;
|
|
387
|
+
}, opts?: {
|
|
388
|
+
signal?: AbortSignal;
|
|
389
|
+
}): Promise<NodeJS.ReadableStream | null>;
|
|
390
|
+
/**
|
|
391
|
+
* Read a file from the filesystem of this sandbox as a Buffer.
|
|
392
|
+
*
|
|
393
|
+
* @param file - File to read, with path and optional cwd
|
|
394
|
+
* @param opts - Optional parameters.
|
|
395
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
396
|
+
* @returns A promise that resolves to the file contents as a Buffer, or null if file not found
|
|
397
|
+
*/
|
|
398
|
+
readFileToBuffer(file: {
|
|
399
|
+
path: string;
|
|
400
|
+
cwd?: string;
|
|
401
|
+
}, opts?: {
|
|
402
|
+
signal?: AbortSignal;
|
|
403
|
+
}): Promise<Buffer | null>;
|
|
404
|
+
/**
|
|
405
|
+
* Download a file from the sandbox to the local filesystem.
|
|
406
|
+
*
|
|
407
|
+
* @param src - Source file on the sandbox, with path and optional cwd
|
|
408
|
+
* @param dst - Destination file on the local machine, with path and optional cwd
|
|
409
|
+
* @param opts - Optional parameters.
|
|
410
|
+
* @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.
|
|
411
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
412
|
+
* @returns The absolute path to the written file, or null if the source file was not found
|
|
413
|
+
*/
|
|
414
|
+
downloadFile(src: {
|
|
415
|
+
path: string;
|
|
416
|
+
cwd?: string;
|
|
417
|
+
}, dst: {
|
|
418
|
+
path: string;
|
|
419
|
+
cwd?: string;
|
|
420
|
+
}, opts?: {
|
|
421
|
+
mkdirRecursive?: boolean;
|
|
422
|
+
signal?: AbortSignal;
|
|
423
|
+
}): Promise<string | null>;
|
|
424
|
+
/**
|
|
425
|
+
* Write files to the filesystem of this sandbox.
|
|
426
|
+
* Defaults to writing to /vercel/sandbox unless an absolute path is specified.
|
|
427
|
+
* Writes files using the `vercel-sandbox` user.
|
|
428
|
+
*
|
|
429
|
+
* @param files - Array of files with path, content, and optional mode (permissions)
|
|
430
|
+
* @param opts - Optional parameters.
|
|
431
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
432
|
+
* @returns A promise that resolves when the files are written
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* // Write an executable script
|
|
436
|
+
* await sandbox.writeFiles([
|
|
437
|
+
* { path: "/usr/local/bin/myscript", content: "#!/bin/bash\necho hello", mode: 0o755 }
|
|
438
|
+
* ]);
|
|
439
|
+
*/
|
|
440
|
+
writeFiles(files: {
|
|
441
|
+
path: string;
|
|
442
|
+
content: string | Uint8Array;
|
|
443
|
+
mode?: number;
|
|
444
|
+
}[], opts?: {
|
|
445
|
+
signal?: AbortSignal;
|
|
446
|
+
}): Promise<void>;
|
|
447
|
+
/**
|
|
448
|
+
* Get the public domain of a port of this sandbox.
|
|
449
|
+
*
|
|
450
|
+
* @param p - Port number to resolve
|
|
451
|
+
* @returns A full domain (e.g. `https://subdomain.vercel.run`)
|
|
452
|
+
* @throws If the port has no associated route
|
|
453
|
+
*/
|
|
454
|
+
domain(p: number): string;
|
|
455
|
+
/**
|
|
456
|
+
* Stop the sandbox.
|
|
457
|
+
*
|
|
458
|
+
* @param opts - Optional parameters.
|
|
459
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
460
|
+
* @param opts.blocking - If true, poll until the sandbox has fully stopped and return the final state.
|
|
461
|
+
* @returns The sandbox metadata at the time the stop was acknowledged, or after fully stopped if `blocking` is true.
|
|
462
|
+
*/
|
|
463
|
+
stop(opts?: {
|
|
464
|
+
signal?: AbortSignal;
|
|
465
|
+
blocking?: boolean;
|
|
466
|
+
}): Promise<SandboxSnapshot>;
|
|
467
|
+
/**
|
|
468
|
+
* Update the network policy for this sandbox.
|
|
469
|
+
*
|
|
470
|
+
* @param networkPolicy - The new network policy to apply.
|
|
471
|
+
* @param opts - Optional parameters.
|
|
472
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
473
|
+
* @returns A promise that resolves when the network policy is updated.
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* // Restrict to specific domains
|
|
477
|
+
* await sandbox.updateNetworkPolicy({
|
|
478
|
+
* allow: ["*.npmjs.org", "github.com"],
|
|
479
|
+
* });
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* // Inject credentials with per-domain transformers
|
|
483
|
+
* await sandbox.updateNetworkPolicy({
|
|
484
|
+
* allow: {
|
|
485
|
+
* "ai-gateway.vercel.sh": [{
|
|
486
|
+
* transform: [{
|
|
487
|
+
* headers: { authorization: "Bearer ..." }
|
|
488
|
+
* }]
|
|
489
|
+
* }],
|
|
490
|
+
* "*": []
|
|
491
|
+
* }
|
|
492
|
+
* });
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* // Deny all network access
|
|
496
|
+
* await sandbox.updateNetworkPolicy("deny-all");
|
|
497
|
+
*/
|
|
498
|
+
updateNetworkPolicy(networkPolicy: NetworkPolicy, opts?: {
|
|
499
|
+
signal?: AbortSignal;
|
|
500
|
+
}): Promise<NetworkPolicy>;
|
|
501
|
+
/**
|
|
502
|
+
* Extend the timeout of the sandbox by the specified duration.
|
|
503
|
+
*
|
|
504
|
+
* This allows you to extend the lifetime of a sandbox up until the maximum
|
|
505
|
+
* execution timeout for your plan.
|
|
506
|
+
*
|
|
507
|
+
* @param duration - The duration in milliseconds to extend the timeout by
|
|
508
|
+
* @param opts - Optional parameters.
|
|
509
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
510
|
+
* @returns A promise that resolves when the timeout is extended
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* const sandbox = await Sandbox.create({ timeout: ms('10m') });
|
|
514
|
+
* // Extends timeout by 5 minutes, to a total of 15 minutes.
|
|
515
|
+
* await sandbox.extendTimeout(ms('5m'));
|
|
516
|
+
*/
|
|
517
|
+
extendTimeout(duration: number, opts?: {
|
|
518
|
+
signal?: AbortSignal;
|
|
519
|
+
}): Promise<void>;
|
|
520
|
+
/**
|
|
521
|
+
* Create a snapshot from this currently running sandbox. New sandboxes can
|
|
522
|
+
* then be created from this snapshot using {@link Sandbox.createFromSnapshot}.
|
|
523
|
+
*
|
|
524
|
+
* Note: this sandbox will be stopped as part of the snapshot creation process.
|
|
525
|
+
*
|
|
526
|
+
* @param opts - Optional parameters.
|
|
527
|
+
* @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.
|
|
528
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
529
|
+
* @returns A promise that resolves to the Snapshot instance
|
|
530
|
+
*/
|
|
531
|
+
snapshot(opts?: {
|
|
532
|
+
expiration?: number;
|
|
533
|
+
signal?: AbortSignal;
|
|
534
|
+
}): Promise<Snapshot>;
|
|
535
|
+
}
|
|
536
|
+
//#endregion
|
|
537
|
+
export { Sandbox, SerializedSandbox };
|
|
538
|
+
//# sourceMappingURL=sandbox.d.cts.map
|