@vercel/sandbox 2.0.0-beta.11 → 2.0.0-beta.12

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/README.md +8 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/api-client/api-client.cjs +456 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +788 -0
  6. package/dist/api-client/api-client.d.ts +782 -777
  7. package/dist/api-client/api-client.js +445 -471
  8. package/dist/api-client/api-client.js.map +1 -1
  9. package/dist/api-client/api-error.cjs +32 -0
  10. package/dist/api-client/api-error.cjs.map +1 -0
  11. package/dist/api-client/api-error.d.cts +29 -0
  12. package/dist/api-client/api-error.d.ts +21 -18
  13. package/dist/api-client/api-error.js +28 -33
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +125 -0
  16. package/dist/api-client/base-client.cjs.map +1 -0
  17. package/dist/api-client/base-client.d.cts +38 -0
  18. package/dist/api-client/base-client.d.ts +31 -36
  19. package/dist/api-client/base-client.js +110 -130
  20. package/dist/api-client/base-client.js.map +1 -1
  21. package/dist/api-client/file-writer.cjs +62 -0
  22. package/dist/api-client/file-writer.cjs.map +1 -0
  23. package/dist/api-client/file-writer.d.cts +66 -0
  24. package/dist/api-client/file-writer.d.ts +56 -52
  25. package/dist/api-client/file-writer.js +57 -61
  26. package/dist/api-client/file-writer.js.map +1 -1
  27. package/dist/api-client/index.cjs +2 -0
  28. package/dist/api-client/index.d.ts +2 -2
  29. package/dist/api-client/index.js +4 -21
  30. package/dist/api-client/validators.cjs +181 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +1469 -0
  33. package/dist/api-client/validators.d.ts +1282 -3699
  34. package/dist/api-client/validators.js +154 -170
  35. package/dist/api-client/validators.js.map +1 -1
  36. package/dist/api-client/with-retry.cjs +89 -0
  37. package/dist/api-client/with-retry.cjs.map +1 -0
  38. package/dist/api-client/with-retry.d.cts +10 -0
  39. package/dist/api-client/with-retry.d.ts +9 -13
  40. package/dist/api-client/with-retry.js +81 -102
  41. package/dist/api-client/with-retry.js.map +1 -1
  42. package/dist/auth/api.cjs +29 -0
  43. package/dist/auth/api.cjs.map +1 -0
  44. package/dist/auth/api.js +26 -25
  45. package/dist/auth/api.js.map +1 -1
  46. package/dist/auth/error.cjs +13 -0
  47. package/dist/auth/error.cjs.map +1 -0
  48. package/dist/auth/error.js +11 -11
  49. package/dist/auth/error.js.map +1 -1
  50. package/dist/auth/file.cjs +64 -0
  51. package/dist/auth/file.cjs.map +1 -0
  52. package/dist/auth/file.d.cts +26 -0
  53. package/dist/auth/file.d.ts +19 -15
  54. package/dist/auth/file.js +49 -64
  55. package/dist/auth/file.js.map +1 -1
  56. package/dist/auth/index.cjs +12 -0
  57. package/dist/auth/index.d.cts +5 -0
  58. package/dist/auth/index.d.ts +5 -6
  59. package/dist/auth/index.js +6 -27
  60. package/dist/auth/linked-project.cjs +38 -0
  61. package/dist/auth/linked-project.cjs.map +1 -0
  62. package/dist/auth/linked-project.js +30 -64
  63. package/dist/auth/linked-project.js.map +1 -1
  64. package/dist/auth/oauth.cjs +205 -0
  65. package/dist/auth/oauth.cjs.map +1 -0
  66. package/dist/auth/oauth.d.cts +135 -0
  67. package/dist/auth/oauth.d.ts +113 -109
  68. package/dist/auth/oauth.js +185 -252
  69. package/dist/auth/oauth.js.map +1 -1
  70. package/dist/auth/poll-for-token.cjs +82 -0
  71. package/dist/auth/poll-for-token.cjs.map +1 -0
  72. package/dist/auth/poll-for-token.d.cts +28 -0
  73. package/dist/auth/poll-for-token.d.ts +23 -15
  74. package/dist/auth/poll-for-token.js +79 -64
  75. package/dist/auth/poll-for-token.js.map +1 -1
  76. package/dist/auth/project.cjs +80 -0
  77. package/dist/auth/project.cjs.map +1 -0
  78. package/dist/auth/project.d.cts +44 -0
  79. package/dist/auth/project.d.ts +12 -8
  80. package/dist/auth/project.js +70 -72
  81. package/dist/auth/project.js.map +1 -1
  82. package/dist/auth/zod.cjs +22 -0
  83. package/dist/auth/zod.cjs.map +1 -0
  84. package/dist/auth/zod.js +18 -17
  85. package/dist/auth/zod.js.map +1 -1
  86. package/dist/command.cjs +328 -0
  87. package/dist/command.cjs.map +1 -0
  88. package/dist/command.d.cts +289 -0
  89. package/dist/command.d.ts +265 -171
  90. package/dist/command.js +323 -226
  91. package/dist/command.js.map +1 -1
  92. package/dist/constants.d.cts +5 -0
  93. package/dist/constants.d.ts +5 -1
  94. package/dist/index.cjs +13 -0
  95. package/dist/index.d.cts +7 -0
  96. package/dist/index.d.ts +7 -6
  97. package/dist/index.js +7 -17
  98. package/dist/network-policy.d.cts +100 -0
  99. package/dist/network-policy.d.ts +32 -28
  100. package/dist/sandbox.cjs +688 -0
  101. package/dist/sandbox.cjs.map +1 -0
  102. package/dist/sandbox.d.cts +780 -0
  103. package/dist/sandbox.d.ts +767 -711
  104. package/dist/sandbox.js +678 -615
  105. package/dist/sandbox.js.map +1 -1
  106. package/dist/session.cjs +520 -0
  107. package/dist/session.cjs.map +1 -0
  108. package/dist/session.d.cts +406 -0
  109. package/dist/session.d.ts +398 -367
  110. package/dist/session.js +517 -505
  111. package/dist/session.js.map +1 -1
  112. package/dist/snapshot.cjs +116 -0
  113. package/dist/snapshot.cjs.map +1 -0
  114. package/dist/snapshot.d.cts +107 -0
  115. package/dist/snapshot.d.ts +98 -91
  116. package/dist/snapshot.js +114 -115
  117. package/dist/snapshot.js.map +1 -1
  118. package/dist/utils/array.cjs +17 -0
  119. package/dist/utils/array.cjs.map +1 -0
  120. package/dist/utils/array.js +12 -15
  121. package/dist/utils/array.js.map +1 -1
  122. package/dist/utils/consume-readable.cjs +18 -0
  123. package/dist/utils/consume-readable.cjs.map +1 -0
  124. package/dist/utils/consume-readable.js +13 -12
  125. package/dist/utils/consume-readable.js.map +1 -1
  126. package/dist/utils/decode-base64-url.cjs +15 -0
  127. package/dist/utils/decode-base64-url.cjs.map +1 -0
  128. package/dist/utils/decode-base64-url.js +10 -9
  129. package/dist/utils/decode-base64-url.js.map +1 -1
  130. package/dist/utils/dev-credentials.cjs +142 -0
  131. package/dist/utils/dev-credentials.cjs.map +1 -0
  132. package/dist/utils/dev-credentials.js +126 -184
  133. package/dist/utils/dev-credentials.js.map +1 -1
  134. package/dist/utils/get-credentials.cjs +123 -0
  135. package/dist/utils/get-credentials.cjs.map +1 -0
  136. package/dist/utils/get-credentials.d.cts +21 -0
  137. package/dist/utils/get-credentials.d.ts +19 -61
  138. package/dist/utils/get-credentials.js +106 -140
  139. package/dist/utils/get-credentials.js.map +1 -1
  140. package/dist/utils/log.cjs +25 -0
  141. package/dist/utils/log.cjs.map +1 -0
  142. package/dist/utils/log.js +15 -17
  143. package/dist/utils/log.js.map +1 -1
  144. package/dist/utils/network-policy.cjs +65 -0
  145. package/dist/utils/network-policy.cjs.map +1 -0
  146. package/dist/utils/network-policy.js +58 -77
  147. package/dist/utils/network-policy.js.map +1 -1
  148. package/dist/utils/normalizePath.cjs +27 -0
  149. package/dist/utils/normalizePath.cjs.map +1 -0
  150. package/dist/utils/normalizePath.js +21 -28
  151. package/dist/utils/normalizePath.js.map +1 -1
  152. package/dist/utils/resolveSignal.cjs +20 -0
  153. package/dist/utils/resolveSignal.cjs.map +1 -0
  154. package/dist/utils/resolveSignal.d.cts +15 -0
  155. package/dist/utils/resolveSignal.d.ts +12 -10
  156. package/dist/utils/resolveSignal.js +14 -17
  157. package/dist/utils/resolveSignal.js.map +1 -1
  158. package/dist/utils/sandbox-snapshot.cjs +14 -0
  159. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  160. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  161. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  162. package/dist/utils/sandbox-snapshot.js +14 -0
  163. package/dist/utils/sandbox-snapshot.js.map +1 -0
  164. package/dist/utils/types.cjs +13 -0
  165. package/dist/utils/types.cjs.map +1 -0
  166. package/dist/utils/types.d.cts +11 -0
  167. package/dist/utils/types.d.ts +5 -7
  168. package/dist/utils/types.js +8 -8
  169. package/dist/utils/types.js.map +1 -1
  170. package/dist/version.cjs +7 -0
  171. package/dist/version.cjs.map +1 -0
  172. package/dist/version.js +5 -5
  173. package/dist/version.js.map +1 -1
  174. package/package.json +23 -3
  175. package/dist/api-client/index.js.map +0 -1
  176. package/dist/auth/api.d.ts +0 -6
  177. package/dist/auth/error.d.ts +0 -11
  178. package/dist/auth/index.js.map +0 -1
  179. package/dist/auth/linked-project.d.ts +0 -10
  180. package/dist/auth/zod.d.ts +0 -5
  181. package/dist/constants.js +0 -3
  182. package/dist/constants.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/network-policy.js +0 -3
  185. package/dist/network-policy.js.map +0 -1
  186. package/dist/utils/array.d.ts +0 -9
  187. package/dist/utils/consume-readable.d.ts +0 -5
  188. package/dist/utils/convert-sandbox.d.ts +0 -6
  189. package/dist/utils/convert-sandbox.js +0 -14
  190. package/dist/utils/convert-sandbox.js.map +0 -1
  191. package/dist/utils/decode-base64-url.d.ts +0 -7
  192. package/dist/utils/dev-credentials.d.ts +0 -37
  193. package/dist/utils/log.d.ts +0 -2
  194. package/dist/utils/network-policy.d.ts +0 -7
  195. package/dist/utils/normalizePath.d.ts +0 -17
  196. package/dist/version.d.ts +0 -1
@@ -0,0 +1,780 @@
1
+ import { SandboxMetaData, SandboxRouteData, SessionMetaData } from "./api-client/validators.cjs";
2
+ import { NetworkPolicy } from "./network-policy.cjs";
3
+ import { WithPrivate } from "./utils/types.cjs";
4
+ import { RUNTIMES } from "./constants.cjs";
5
+ import { APIClient, WithFetchOptions } from "./api-client/api-client.cjs";
6
+ import { Credentials } from "./utils/get-credentials.cjs";
7
+ import { Command, CommandFinished } from "./command.cjs";
8
+ import { Snapshot } from "./snapshot.cjs";
9
+ import { SandboxSnapshot } from "./utils/sandbox-snapshot.cjs";
10
+ import { RunCommandParams, Session } from "./session.cjs";
11
+ import * as zod0 from "zod";
12
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
13
+
14
+ //#region src/sandbox.d.ts
15
+ /** @inline */
16
+ interface BaseCreateSandboxParams {
17
+ /**
18
+ * The name of the sandbox. If omitted, a random name will be generated.
19
+ */
20
+ name?: string;
21
+ /**
22
+ * The source of the sandbox.
23
+ *
24
+ * Omit this parameter start a sandbox without a source.
25
+ *
26
+ * For git sources:
27
+ * - `depth`: Creates shallow clones with limited commit history (minimum: 1)
28
+ * - `revision`: Clones and checks out a specific commit, branch, or tag
29
+ */
30
+ source?: {
31
+ type: "git";
32
+ url: string;
33
+ depth?: number;
34
+ revision?: string;
35
+ } | {
36
+ type: "git";
37
+ url: string;
38
+ username: string;
39
+ password: string;
40
+ depth?: number;
41
+ revision?: string;
42
+ } | {
43
+ type: "tarball";
44
+ url: string;
45
+ };
46
+ /**
47
+ * Array of port numbers to expose from the sandbox. Sandboxes can
48
+ * expose up to 4 ports.
49
+ */
50
+ ports?: number[];
51
+ /**
52
+ * Timeout in milliseconds before the sandbox auto-terminates.
53
+ */
54
+ timeout?: number;
55
+ /**
56
+ * Resources to allocate to the sandbox.
57
+ *
58
+ * Your sandbox will get the amount of vCPUs you specify here and
59
+ * 2048 MB of memory per vCPU.
60
+ */
61
+ resources?: {
62
+ vcpus: number;
63
+ };
64
+ /**
65
+ * The runtime of the sandbox, currently only `node24`, `node22` and `python3.13` are supported.
66
+ * If not specified, the default runtime `node24` will be used.
67
+ */
68
+ runtime?: RUNTIMES | (string & {});
69
+ /**
70
+ * Network policy to define network restrictions for the sandbox.
71
+ * Defaults to full internet access if not specified.
72
+ */
73
+ networkPolicy?: NetworkPolicy;
74
+ /**
75
+ * Default environment variables for the sandbox.
76
+ * These are inherited by all commands unless overridden with
77
+ * the `env` option in `runCommand`.
78
+ *
79
+ * @example
80
+ * const sandbox = await Sandbox.create({
81
+ * env: { NODE_ENV: "production", API_KEY: "secret" },
82
+ * });
83
+ * // All commands will have NODE_ENV and API_KEY set
84
+ * await sandbox.runCommand("node", ["app.js"]);
85
+ */
86
+ env?: Record<string, string>;
87
+ /**
88
+ * Key-value tags to associate with the sandbox. Maximum 5 tags.
89
+ * @example { env: "staging", team: "infra" }
90
+ */
91
+ tags?: Record<string, string>;
92
+ /**
93
+ * An AbortSignal to cancel sandbox creation.
94
+ */
95
+ signal?: AbortSignal;
96
+ /**
97
+ * Enable or disable automatic restore of the filesystem between sessions.
98
+ */
99
+ persistent?: boolean;
100
+ /**
101
+ * Default snapshot expiration in milliseconds.
102
+ * When set, snapshots created for this sandbox will expire after this duration.
103
+ * Use `0` for no expiration.
104
+ */
105
+ snapshotExpiration?: number;
106
+ }
107
+ type CreateSandboxParams = BaseCreateSandboxParams | (Omit<BaseCreateSandboxParams, "runtime" | "source"> & {
108
+ source: {
109
+ type: "snapshot";
110
+ snapshotId: string;
111
+ };
112
+ });
113
+ /** @inline */
114
+ interface GetSandboxParams {
115
+ /**
116
+ * The name of the sandbox.
117
+ */
118
+ name: string;
119
+ /**
120
+ * Whether to resume an existing session. Defaults to true.
121
+ */
122
+ resume?: boolean;
123
+ /**
124
+ * An AbortSignal to cancel the operation.
125
+ */
126
+ signal?: AbortSignal;
127
+ }
128
+ /**
129
+ * Serialized representation of a Sandbox for @workflow/serde.
130
+ * Fields `metadata` and `routes` are the original wire format from main.
131
+ * Fields `sandboxMetadata` and `projectId` are added for named-sandboxes.
132
+ */
133
+ interface SerializedSandbox {
134
+ metadata: SandboxSnapshot;
135
+ routes: SandboxRouteData[];
136
+ sandboxMetadata?: SandboxMetaData;
137
+ projectId?: string;
138
+ }
139
+ /**
140
+ * A Sandbox is a persistent, isolated Linux MicroVMs to run commands in.
141
+ * Use {@link Sandbox.create} or {@link Sandbox.get} to construct.
142
+ * @hideconstructor
143
+ */
144
+ declare class Sandbox {
145
+ private _client;
146
+ private readonly projectId;
147
+ /**
148
+ * In-flight resume promise, used to deduplicate concurrent resume calls.
149
+ */
150
+ private resumePromise;
151
+ /**
152
+ * Internal Session instance for the current VM.
153
+ */
154
+ private session;
155
+ /**
156
+ * Internal metadata about the sandbox.
157
+ */
158
+ private sandbox;
159
+ /**
160
+ * Lazily resolve credentials and construct an API client.
161
+ * @internal
162
+ */
163
+ private ensureClient;
164
+ /**
165
+ * The name of this sandbox.
166
+ */
167
+ get name(): string;
168
+ /**
169
+ * Routes from ports to subdomains.
170
+ * @hidden
171
+ */
172
+ get routes(): SandboxRouteData[];
173
+ /**
174
+ * Whether the sandbox persists the state.
175
+ */
176
+ get persistent(): boolean;
177
+ /**
178
+ * The region this sandbox runs in.
179
+ */
180
+ get region(): string | undefined;
181
+ /**
182
+ * Number of virtual CPUs allocated.
183
+ */
184
+ get vcpus(): number | undefined;
185
+ /**
186
+ * Memory allocated in MB.
187
+ */
188
+ get memory(): number | undefined;
189
+ /** Runtime identifier (e.g. "node24", "python3.13"). */
190
+ get runtime(): string | undefined;
191
+ /**
192
+ * Cumulative egress bytes across all sessions.
193
+ */
194
+ get totalEgressBytes(): number | undefined;
195
+ /**
196
+ * Cumulative ingress bytes across all sessions.
197
+ */
198
+ get totalIngressBytes(): number | undefined;
199
+ /**
200
+ * Cumulative active CPU duration in milliseconds across all sessions.
201
+ */
202
+ get totalActiveCpuDurationMs(): number | undefined;
203
+ /**
204
+ * Cumulative wall-clock duration in milliseconds across all sessions.
205
+ */
206
+ get totalDurationMs(): number | undefined;
207
+ /**
208
+ * When this sandbox was last updated.
209
+ */
210
+ get updatedAt(): Date;
211
+ /**
212
+ * When the sandbox status was last updated.
213
+ */
214
+ get statusUpdatedAt(): Date | undefined;
215
+ /**
216
+ * When this sandbox was created.
217
+ */
218
+ get createdAt(): Date;
219
+ /**
220
+ * Interactive port.
221
+ */
222
+ get interactivePort(): number | undefined;
223
+ /**
224
+ * The status of the current session.
225
+ */
226
+ get status(): SessionMetaData["status"];
227
+ /**
228
+ * The default timeout of this sandbox in milliseconds.
229
+ */
230
+ get timeout(): number | undefined;
231
+ /**
232
+ * Key-value tags attached to the sandbox.
233
+ */
234
+ get tags(): Record<string, string> | undefined;
235
+ /**
236
+ * The default network policy of this sandbox.
237
+ */
238
+ get networkPolicy(): NetworkPolicy | undefined;
239
+ /**
240
+ * If the session was created from a snapshot, the ID of that snapshot.
241
+ */
242
+ get sourceSnapshotId(): string | undefined;
243
+ /**
244
+ * The current snapshot ID of this sandbox, if any.
245
+ */
246
+ get currentSnapshotId(): string | undefined;
247
+ /**
248
+ * The default snapshot expiration in milliseconds, if set.
249
+ */
250
+ get snapshotExpiration(): number | undefined;
251
+ /**
252
+ * The amount of CPU used by the session. Only reported once the VM is stopped.
253
+ */
254
+ get activeCpuUsageMs(): number | undefined;
255
+ /**
256
+ * The amount of network data used by the session. Only reported once the VM is stopped.
257
+ */
258
+ get networkTransfer(): {
259
+ ingress: number;
260
+ egress: number;
261
+ } | undefined;
262
+ /**
263
+ * Allow to get a list of sandboxes for a team narrowed to the given params.
264
+ * It returns both the sandboxes and the pagination metadata to allow getting
265
+ * the next page of results.
266
+ */
267
+ static list(params?: Partial<Parameters<APIClient["listSandboxes"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<{
268
+ sandboxes: {
269
+ status: "aborted" | "pending" | "running" | "stopping" | "stopped" | "failed" | "snapshotting";
270
+ name: string;
271
+ persistent: boolean;
272
+ createdAt: number;
273
+ updatedAt: number;
274
+ currentSessionId: string;
275
+ tags?: Record<string, string> | undefined;
276
+ region?: string | undefined;
277
+ vcpus?: number | undefined;
278
+ memory?: number | undefined;
279
+ runtime?: string | undefined;
280
+ timeout?: number | undefined;
281
+ networkPolicy?: zod0.objectInputType<{
282
+ mode: zod0.ZodLiteral<"allow-all">;
283
+ }, zod0.ZodTypeAny, "passthrough"> | zod0.objectInputType<{
284
+ mode: zod0.ZodLiteral<"deny-all">;
285
+ }, zod0.ZodTypeAny, "passthrough"> | zod0.objectInputType<{
286
+ mode: zod0.ZodLiteral<"custom">;
287
+ allowedDomains: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
288
+ allowedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
289
+ deniedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
290
+ injectionRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
291
+ domain: zod0.ZodString;
292
+ headers: zod0.ZodOptional<zod0.ZodRecord<zod0.ZodString, zod0.ZodString>>;
293
+ headerNames: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
294
+ }, "strip", zod0.ZodTypeAny, {
295
+ domain: string;
296
+ headers?: Record<string, string> | undefined;
297
+ headerNames?: string[] | undefined;
298
+ }, {
299
+ domain: string;
300
+ headers?: Record<string, string> | undefined;
301
+ headerNames?: string[] | undefined;
302
+ }>, "many">>;
303
+ }, zod0.ZodTypeAny, "passthrough"> | undefined;
304
+ totalEgressBytes?: number | undefined;
305
+ totalIngressBytes?: number | undefined;
306
+ totalActiveCpuDurationMs?: number | undefined;
307
+ totalDurationMs?: number | undefined;
308
+ currentSnapshotId?: string | undefined;
309
+ cwd?: string | undefined;
310
+ statusUpdatedAt?: number | undefined;
311
+ snapshotExpiration?: number | undefined;
312
+ }[];
313
+ pagination: {
314
+ count: number;
315
+ next: string | null;
316
+ };
317
+ }>;
318
+ /**
319
+ * Serialize a Sandbox instance to plain data for @workflow/serde.
320
+ *
321
+ * @param instance - The Sandbox instance to serialize
322
+ * @returns A plain object containing sandbox metadata and routes
323
+ */
324
+ static [WORKFLOW_SERIALIZE](instance: Sandbox): SerializedSandbox;
325
+ /**
326
+ * Deserialize a Sandbox from serialized snapshot data.
327
+ *
328
+ * The deserialized instance uses the serialized metadata synchronously and
329
+ * lazily creates an API client only when methods perform API requests.
330
+ *
331
+ * @param data - The serialized sandbox data
332
+ * @returns The reconstructed Sandbox instance
333
+ */
334
+ static [WORKFLOW_DESERIALIZE](data: SerializedSandbox): Sandbox;
335
+ /**
336
+ * Create a new sandbox.
337
+ *
338
+ * @param params - Creation parameters and optional credentials.
339
+ * @returns A promise resolving to the created {@link Sandbox}.
340
+ * @example
341
+ * <caption>Create a sandbox with default options</caption>
342
+ * const sandbox = await Sandbox.create();
343
+ *
344
+ * @example
345
+ * <caption>Create a sandbox and drop it in the end of the block</caption>
346
+ * async function fn() {
347
+ * await using const sandbox = await Sandbox.create();
348
+ * // Sandbox automatically stopped at the end of the lexical scope
349
+ * }
350
+ */
351
+ static create(params?: WithPrivate<CreateSandboxParams | (CreateSandboxParams & Credentials)> & WithFetchOptions): Promise<Sandbox & AsyncDisposable>;
352
+ /**
353
+ * Retrieve an existing sandbox and resume its session.
354
+ *
355
+ * @param params - Get parameters and optional credentials.
356
+ * @returns A promise resolving to the {@link Sandbox}.
357
+ */
358
+ static get(params: WithPrivate<GetSandboxParams | (GetSandboxParams & Credentials)> & WithFetchOptions): Promise<Sandbox>;
359
+ /**
360
+ * Create a new Sandbox instance.
361
+ *
362
+ * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.
363
+ * @param params.routes - Port-to-subdomain mappings for exposed ports
364
+ * @param params.sandbox - Sandbox snapshot metadata
365
+ */
366
+ constructor({
367
+ client,
368
+ routes,
369
+ session,
370
+ sandbox,
371
+ projectId
372
+ }: {
373
+ client?: APIClient;
374
+ routes: SandboxRouteData[];
375
+ session?: SessionMetaData;
376
+ sandbox: SandboxMetaData;
377
+ projectId?: string;
378
+ });
379
+ /**
380
+ * Get the current session (the running VM) for this sandbox.
381
+ *
382
+ * @returns The {@link Session} instance.
383
+ */
384
+ currentSession(): Session;
385
+ /**
386
+ * Resume this sandbox by creating a new session via `getSandbox`.
387
+ */
388
+ private resume;
389
+ private doResume;
390
+ /**
391
+ * Poll until the current session reaches a terminal state, then resume.
392
+ */
393
+ private waitForStopAndResume;
394
+ /**
395
+ * Execute `fn`, and if the session is stopped/stopping/snapshotting, resume and retry.
396
+ */
397
+ private withResume;
398
+ /**
399
+ * Start executing a command in this sandbox.
400
+ *
401
+ * @param command - The command to execute.
402
+ * @param args - Arguments to pass to the command.
403
+ * @param opts - Optional parameters.
404
+ * @param opts.signal - An AbortSignal to cancel the command execution.
405
+ * @returns A {@link CommandFinished} result once execution is done.
406
+ */
407
+ runCommand(command: string, args?: string[], opts?: {
408
+ signal?: AbortSignal;
409
+ }): Promise<CommandFinished>;
410
+ /**
411
+ * Start executing a command in detached mode.
412
+ *
413
+ * @param params - The command parameters.
414
+ * @returns A {@link Command} instance for the running command.
415
+ */
416
+ runCommand(params: RunCommandParams & {
417
+ detached: true;
418
+ }): Promise<Command>;
419
+ /**
420
+ * Start executing a command in this sandbox.
421
+ *
422
+ * @param params - The command parameters.
423
+ * @returns A {@link CommandFinished} result once execution is done.
424
+ */
425
+ runCommand(params: RunCommandParams): Promise<CommandFinished>;
426
+ /**
427
+ * Internal helper to start a command in the sandbox.
428
+ *
429
+ * @param params - Command execution parameters.
430
+ * @returns A {@link Command} or {@link CommandFinished}, depending on `detached`.
431
+ * @internal
432
+ */
433
+ getCommand(cmdId: string, opts?: {
434
+ signal?: AbortSignal;
435
+ }): Promise<Command>;
436
+ /**
437
+ * Create a directory in the filesystem of this sandbox.
438
+ *
439
+ * @param path - Path of the directory to create
440
+ * @param opts - Optional parameters.
441
+ * @param opts.signal - An AbortSignal to cancel the operation.
442
+ */
443
+ mkDir(path: string, opts?: {
444
+ signal?: AbortSignal;
445
+ }): Promise<void>;
446
+ /**
447
+ * Read a file from the filesystem of this sandbox as a stream.
448
+ *
449
+ * @param file - File to read, with path and optional cwd
450
+ * @param opts - Optional parameters.
451
+ * @param opts.signal - An AbortSignal to cancel the operation.
452
+ * @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found
453
+ */
454
+ readFile(file: {
455
+ path: string;
456
+ cwd?: string;
457
+ }, opts?: {
458
+ signal?: AbortSignal;
459
+ }): Promise<NodeJS.ReadableStream | null>;
460
+ /**
461
+ * Read a file from the filesystem of this sandbox as a Buffer.
462
+ *
463
+ * @param file - File to read, with path and optional cwd
464
+ * @param opts - Optional parameters.
465
+ * @param opts.signal - An AbortSignal to cancel the operation.
466
+ * @returns A promise that resolves to the file contents as a Buffer, or null if file not found
467
+ */
468
+ readFileToBuffer(file: {
469
+ path: string;
470
+ cwd?: string;
471
+ }, opts?: {
472
+ signal?: AbortSignal;
473
+ }): Promise<Buffer | null>;
474
+ /**
475
+ * Download a file from the sandbox to the local filesystem.
476
+ *
477
+ * @param src - Source file on the sandbox, with path and optional cwd
478
+ * @param dst - Destination file on the local machine, with path and optional cwd
479
+ * @param opts - Optional parameters.
480
+ * @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.
481
+ * @param opts.signal - An AbortSignal to cancel the operation.
482
+ * @returns The absolute path to the written file, or null if the source file was not found
483
+ */
484
+ downloadFile(src: {
485
+ path: string;
486
+ cwd?: string;
487
+ }, dst: {
488
+ path: string;
489
+ cwd?: string;
490
+ }, opts?: {
491
+ mkdirRecursive?: boolean;
492
+ signal?: AbortSignal;
493
+ }): Promise<string | null>;
494
+ /**
495
+ * Write files to the filesystem of this sandbox.
496
+ * Defaults to writing to /vercel/sandbox unless an absolute path is specified.
497
+ * Writes files using the `vercel-sandbox` user.
498
+ *
499
+ * @param files - Array of files with path, content, and optional mode (permissions)
500
+ * @param opts - Optional parameters.
501
+ * @param opts.signal - An AbortSignal to cancel the operation.
502
+ * @returns A promise that resolves when the files are written
503
+ *
504
+ * @example
505
+ * // Write an executable script
506
+ * await sandbox.writeFiles([
507
+ * { path: "/usr/local/bin/myscript", content: "#!/bin/bash\necho hello", mode: 0o755 }
508
+ * ]);
509
+ */
510
+ writeFiles(files: {
511
+ path: string;
512
+ content: string | Uint8Array;
513
+ mode?: number;
514
+ }[], opts?: {
515
+ signal?: AbortSignal;
516
+ }): Promise<void>;
517
+ /**
518
+ * Get the public domain of a port of this sandbox.
519
+ *
520
+ * @param p - Port number to resolve
521
+ * @returns A full domain (e.g. `https://subdomain.vercel.run`)
522
+ * @throws If the port has no associated route
523
+ */
524
+ domain(p: number): string;
525
+ /**
526
+ * Stop the sandbox.
527
+ *
528
+ * @param opts - Optional parameters.
529
+ * @param opts.signal - An AbortSignal to cancel the operation.
530
+ * @param opts.blocking - If true, poll until the sandbox has fully stopped and return the final state.
531
+ * @returns The sandbox at the time the stop was acknowledged, or after fully stopped if `blocking` is true.
532
+ */
533
+ stop(opts?: {
534
+ signal?: AbortSignal;
535
+ blocking?: boolean;
536
+ }): Promise<SandboxSnapshot>;
537
+ /**
538
+ * Update the network policy for this sandbox.
539
+ *
540
+ * @deprecated Use {@link Sandbox.update} instead.
541
+ *
542
+ * @param networkPolicy - The new network policy to apply.
543
+ * @param opts - Optional parameters.
544
+ * @param opts.signal - An AbortSignal to cancel the operation.
545
+ * @returns A promise that resolves when the network policy is updated.
546
+ *
547
+ * @example
548
+ * // Restrict to specific domains
549
+ * await sandbox.updateNetworkPolicy({
550
+ * allow: ["*.npmjs.org", "github.com"],
551
+ * });
552
+ *
553
+ * @example
554
+ * // Inject credentials with per-domain transformers
555
+ * await sandbox.updateNetworkPolicy({
556
+ * allow: {
557
+ * "ai-gateway.vercel.sh": [{
558
+ * transform: [{
559
+ * headers: { authorization: "Bearer ..." }
560
+ * }]
561
+ * }],
562
+ * "*": []
563
+ * }
564
+ * });
565
+ *
566
+ * @example
567
+ * // Deny all network access
568
+ * await sandbox.updateNetworkPolicy("deny-all");
569
+ */
570
+ updateNetworkPolicy(networkPolicy: NetworkPolicy, opts?: {
571
+ signal?: AbortSignal;
572
+ }): Promise<NetworkPolicy>;
573
+ /**
574
+ * Extend the timeout of the sandbox by the specified duration.
575
+ *
576
+ * This allows you to extend the lifetime of a sandbox up until the maximum
577
+ * execution timeout for your plan.
578
+ *
579
+ * @param duration - The duration in milliseconds to extend the timeout by
580
+ * @param opts - Optional parameters.
581
+ * @param opts.signal - An AbortSignal to cancel the operation.
582
+ * @returns A promise that resolves when the timeout is extended
583
+ *
584
+ * @example
585
+ * const sandbox = await Sandbox.create({ timeout: ms('10m') });
586
+ * // Extends timeout by 5 minutes, to a total of 15 minutes.
587
+ * await sandbox.extendTimeout(ms('5m'));
588
+ */
589
+ extendTimeout(duration: number, opts?: {
590
+ signal?: AbortSignal;
591
+ }): Promise<void>;
592
+ /**
593
+ * Create a snapshot from this currently running sandbox. New sandboxes can
594
+ * then be created from this snapshot using {@link Sandbox.createFromSnapshot}.
595
+ *
596
+ * Note: this sandbox will be stopped as part of the snapshot creation process.
597
+ *
598
+ * @param opts - Optional parameters.
599
+ * @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.
600
+ * @param opts.signal - An AbortSignal to cancel the operation.
601
+ * @returns A promise that resolves to the Snapshot instance
602
+ */
603
+ snapshot(opts?: {
604
+ expiration?: number;
605
+ signal?: AbortSignal;
606
+ }): Promise<Snapshot>;
607
+ /**
608
+ * Update the sandbox configuration.
609
+ *
610
+ * @param params - Fields to update.
611
+ * @param opts - Optional abort signal.
612
+ */
613
+ update(params: {
614
+ persistent?: boolean;
615
+ resources?: {
616
+ vcpus?: number;
617
+ };
618
+ timeout?: number;
619
+ networkPolicy?: NetworkPolicy;
620
+ tags?: Record<string, string>;
621
+ snapshotExpiration?: number;
622
+ }, opts?: {
623
+ signal?: AbortSignal;
624
+ }): Promise<void>;
625
+ /**
626
+ * Delete this sandbox.
627
+ *
628
+ * After deletion the instance becomes inert — all further API calls will
629
+ * throw immediately.
630
+ */
631
+ delete(opts?: {
632
+ signal?: AbortSignal;
633
+ }): Promise<void>;
634
+ /**
635
+ * List sessions (VMs) that have been created for this sandbox.
636
+ *
637
+ * @param params - Optional pagination parameters.
638
+ * @returns The list of sessions and pagination metadata.
639
+ */
640
+ listSessions(params?: {
641
+ limit?: number;
642
+ cursor?: string;
643
+ sortOrder?: "asc" | "desc";
644
+ signal?: AbortSignal;
645
+ }): Promise<{
646
+ pagination: {
647
+ count: number;
648
+ next: string | null;
649
+ };
650
+ sessions: zod0.objectInputType<{
651
+ id: zod0.ZodString;
652
+ memory: zod0.ZodNumber;
653
+ vcpus: zod0.ZodNumber;
654
+ region: zod0.ZodString;
655
+ runtime: zod0.ZodString;
656
+ timeout: zod0.ZodNumber;
657
+ status: zod0.ZodEnum<["pending", "running", "stopping", "stopped", "failed", "aborted", "snapshotting"]>;
658
+ requestedAt: zod0.ZodNumber;
659
+ startedAt: zod0.ZodOptional<zod0.ZodNumber>;
660
+ requestedStopAt: zod0.ZodOptional<zod0.ZodNumber>;
661
+ stoppedAt: zod0.ZodOptional<zod0.ZodNumber>;
662
+ abortedAt: zod0.ZodOptional<zod0.ZodNumber>;
663
+ duration: zod0.ZodOptional<zod0.ZodNumber>;
664
+ sourceSnapshotId: zod0.ZodOptional<zod0.ZodString>;
665
+ snapshottedAt: zod0.ZodOptional<zod0.ZodNumber>;
666
+ createdAt: zod0.ZodNumber;
667
+ cwd: zod0.ZodString;
668
+ updatedAt: zod0.ZodNumber;
669
+ interactivePort: zod0.ZodOptional<zod0.ZodNumber>;
670
+ networkPolicy: zod0.ZodOptional<zod0.ZodUnion<[zod0.ZodObject<{
671
+ mode: zod0.ZodLiteral<"allow-all">;
672
+ }, "passthrough", zod0.ZodTypeAny, zod0.objectOutputType<{
673
+ mode: zod0.ZodLiteral<"allow-all">;
674
+ }, zod0.ZodTypeAny, "passthrough">, zod0.objectInputType<{
675
+ mode: zod0.ZodLiteral<"allow-all">;
676
+ }, zod0.ZodTypeAny, "passthrough">>, zod0.ZodObject<{
677
+ mode: zod0.ZodLiteral<"deny-all">;
678
+ }, "passthrough", zod0.ZodTypeAny, zod0.objectOutputType<{
679
+ mode: zod0.ZodLiteral<"deny-all">;
680
+ }, zod0.ZodTypeAny, "passthrough">, zod0.objectInputType<{
681
+ mode: zod0.ZodLiteral<"deny-all">;
682
+ }, zod0.ZodTypeAny, "passthrough">>, zod0.ZodObject<{
683
+ mode: zod0.ZodLiteral<"custom">;
684
+ allowedDomains: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
685
+ allowedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
686
+ deniedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
687
+ injectionRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
688
+ domain: zod0.ZodString;
689
+ headers: zod0.ZodOptional<zod0.ZodRecord<zod0.ZodString, zod0.ZodString>>;
690
+ headerNames: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
691
+ }, "strip", zod0.ZodTypeAny, {
692
+ domain: string;
693
+ headers?: Record<string, string> | undefined;
694
+ headerNames?: string[] | undefined;
695
+ }, {
696
+ domain: string;
697
+ headers?: Record<string, string> | undefined;
698
+ headerNames?: string[] | undefined;
699
+ }>, "many">>;
700
+ }, "passthrough", zod0.ZodTypeAny, zod0.objectOutputType<{
701
+ mode: zod0.ZodLiteral<"custom">;
702
+ allowedDomains: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
703
+ allowedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
704
+ deniedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
705
+ injectionRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
706
+ domain: zod0.ZodString;
707
+ headers: zod0.ZodOptional<zod0.ZodRecord<zod0.ZodString, zod0.ZodString>>;
708
+ headerNames: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
709
+ }, "strip", zod0.ZodTypeAny, {
710
+ domain: string;
711
+ headers?: Record<string, string> | undefined;
712
+ headerNames?: string[] | undefined;
713
+ }, {
714
+ domain: string;
715
+ headers?: Record<string, string> | undefined;
716
+ headerNames?: string[] | undefined;
717
+ }>, "many">>;
718
+ }, zod0.ZodTypeAny, "passthrough">, zod0.objectInputType<{
719
+ mode: zod0.ZodLiteral<"custom">;
720
+ allowedDomains: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
721
+ allowedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
722
+ deniedCIDRs: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
723
+ injectionRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
724
+ domain: zod0.ZodString;
725
+ headers: zod0.ZodOptional<zod0.ZodRecord<zod0.ZodString, zod0.ZodString>>;
726
+ headerNames: zod0.ZodOptional<zod0.ZodArray<zod0.ZodString, "many">>;
727
+ }, "strip", zod0.ZodTypeAny, {
728
+ domain: string;
729
+ headers?: Record<string, string> | undefined;
730
+ headerNames?: string[] | undefined;
731
+ }, {
732
+ domain: string;
733
+ headers?: Record<string, string> | undefined;
734
+ headerNames?: string[] | undefined;
735
+ }>, "many">>;
736
+ }, zod0.ZodTypeAny, "passthrough">>]>>;
737
+ activeCpuDurationMs: zod0.ZodOptional<zod0.ZodNumber>;
738
+ networkTransfer: zod0.ZodOptional<zod0.ZodObject<{
739
+ ingress: zod0.ZodNumber;
740
+ egress: zod0.ZodNumber;
741
+ }, "strip", zod0.ZodTypeAny, {
742
+ ingress: number;
743
+ egress: number;
744
+ }, {
745
+ ingress: number;
746
+ egress: number;
747
+ }>>;
748
+ }, zod0.ZodTypeAny, "passthrough">[];
749
+ }>;
750
+ /**
751
+ * List snapshots that belong to this sandbox.
752
+ *
753
+ * @param params - Optional pagination parameters.
754
+ * @returns The list of snapshots and pagination metadata.
755
+ */
756
+ listSnapshots(params?: {
757
+ limit?: number;
758
+ cursor?: string;
759
+ sortOrder?: "asc" | "desc";
760
+ signal?: AbortSignal;
761
+ }): Promise<{
762
+ pagination: {
763
+ count: number;
764
+ next: string | null;
765
+ };
766
+ snapshots: {
767
+ status: "failed" | "created" | "deleted";
768
+ region: string;
769
+ createdAt: number;
770
+ updatedAt: number;
771
+ id: string;
772
+ sourceSessionId: string;
773
+ sizeBytes: number;
774
+ expiresAt?: number | undefined;
775
+ }[];
776
+ }>;
777
+ }
778
+ //#endregion
779
+ export { Sandbox, SerializedSandbox };
780
+ //# sourceMappingURL=sandbox.d.cts.map