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

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