@vercel/sandbox 2.0.0-beta.4 → 2.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sandbox.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SandboxMetaData, SandboxRouteData, NamedSandboxMetaData } from "./api-client";
1
+ import type { SessionMetaData, SandboxRouteData, SandboxMetaData } from "./api-client";
2
2
  import { APIClient } from "./api-client";
3
3
  import { type Credentials } from "./utils/get-credentials";
4
4
  import { type WithPrivate } from "./utils/types";
@@ -7,7 +7,7 @@ import type { RUNTIMES } from "./constants";
7
7
  import { Session, type RunCommandParams } from "./session";
8
8
  import type { Command, CommandFinished } from "./command";
9
9
  import type { Snapshot } from "./snapshot";
10
- import type { ConvertedSandbox } from "./utils/convert-sandbox";
10
+ import type { ConvertedSession } from "./utils/convert-sandbox";
11
11
  import type { NetworkPolicy } from "./network-policy";
12
12
  export type { NetworkPolicy };
13
13
  /** @inline */
@@ -82,12 +82,17 @@ export interface BaseCreateSandboxParams {
82
82
  * await sandbox.runCommand("node", ["app.js"]);
83
83
  */
84
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>;
85
90
  /**
86
91
  * An AbortSignal to cancel sandbox creation.
87
92
  */
88
93
  signal?: AbortSignal;
89
94
  /**
90
- * Whether to enable snapshots on shutdown. Defaults to true.
95
+ * Enable or disable automatic restore of the filesystem between sessions.
91
96
  */
92
97
  persistent?: boolean;
93
98
  }
@@ -120,14 +125,18 @@ interface GetSandboxParams {
120
125
  export declare class Sandbox {
121
126
  private readonly client;
122
127
  private readonly projectId;
128
+ /**
129
+ * In-flight resume promise, used to deduplicate concurrent resume calls.
130
+ */
131
+ private resumePromise;
123
132
  /**
124
133
  * Internal Session instance for the current VM.
125
134
  */
126
135
  private session;
127
136
  /**
128
- * Internal metadata about the named sandbox.
137
+ * Internal metadata about the sandbox.
129
138
  */
130
- private namedSandbox;
139
+ private sandbox;
131
140
  /**
132
141
  * The name of this sandbox.
133
142
  */
@@ -144,17 +153,17 @@ export declare class Sandbox {
144
153
  /**
145
154
  * The region this sandbox runs in.
146
155
  */
147
- get region(): string;
156
+ get region(): string | undefined;
148
157
  /**
149
158
  * Number of virtual CPUs allocated.
150
159
  */
151
- get vcpus(): number;
160
+ get vcpus(): number | undefined;
152
161
  /**
153
162
  * Memory allocated in MB.
154
163
  */
155
- get memory(): number;
164
+ get memory(): number | undefined;
156
165
  /** Runtime identifier (e.g. "node24", "python3.13"). */
157
- get runtime(): string;
166
+ get runtime(): string | undefined;
158
167
  /**
159
168
  * Cumulative egress bytes across all sessions.
160
169
  */
@@ -186,11 +195,15 @@ export declare class Sandbox {
186
195
  /**
187
196
  * The status of the current session.
188
197
  */
189
- get status(): SandboxMetaData["status"];
198
+ get status(): SessionMetaData["status"];
190
199
  /**
191
200
  * The default timeout of this sandbox in milliseconds.
192
201
  */
193
- get timeout(): number;
202
+ get timeout(): number | undefined;
203
+ /**
204
+ * Key-value tags attached to the sandbox.
205
+ */
206
+ get tags(): Record<string, string> | undefined;
194
207
  /**
195
208
  * The default network policy of this sandbox.
196
209
  */
@@ -219,57 +232,55 @@ export declare class Sandbox {
219
232
  * It returns both the sandboxes and the pagination metadata to allow getting
220
233
  * the next page of results.
221
234
  */
222
- static list(params?: Partial<Parameters<APIClient["listNamedSandboxes"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<{
223
- json: {
224
- sandboxes: {
225
- memory: number;
226
- vcpus: number;
227
- region: string;
228
- runtime: string;
229
- timeout: number;
230
- status: "aborted" | "pending" | "running" | "stopping" | "stopped" | "failed" | "snapshotting";
231
- createdAt: number;
232
- updatedAt: number;
233
- name: string;
234
- persistent: boolean;
235
- currentSandboxId: string;
236
- networkPolicy?: import("zod").objectInputType<{
237
- mode: import("zod").ZodLiteral<"allow-all">;
238
- }, import("zod").ZodTypeAny, "passthrough"> | import("zod").objectInputType<{
239
- mode: import("zod").ZodLiteral<"deny-all">;
240
- }, import("zod").ZodTypeAny, "passthrough"> | import("zod").objectInputType<{
241
- mode: import("zod").ZodLiteral<"custom">;
242
- allowedDomains: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
243
- allowedCIDRs: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
244
- deniedCIDRs: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
245
- injectionRules: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
246
- domain: import("zod").ZodString;
247
- headers: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
248
- headerNames: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
249
- }, "strip", import("zod").ZodTypeAny, {
250
- domain: string;
251
- headers?: Record<string, string> | undefined;
252
- headerNames?: string[] | undefined;
253
- }, {
254
- domain: string;
255
- headers?: Record<string, string> | undefined;
256
- headerNames?: string[] | undefined;
257
- }>, "many">>;
258
- }, import("zod").ZodTypeAny, "passthrough"> | undefined;
259
- totalEgressBytes?: number | undefined;
260
- totalIngressBytes?: number | undefined;
261
- totalActiveCpuDurationMs?: number | undefined;
262
- totalDurationMs?: number | undefined;
263
- currentSnapshotId?: string | undefined;
264
- }[];
265
- pagination: {
266
- count: number;
267
- next: string | null;
268
- total: number;
269
- };
235
+ static list(params?: Partial<Parameters<APIClient["listSandboxes"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<{
236
+ pagination: {
237
+ count: number;
238
+ next: string | null;
239
+ total: number;
270
240
  };
271
- response: Response;
272
- text: string;
241
+ sandboxes: {
242
+ status: "aborted" | "pending" | "running" | "stopping" | "stopped" | "failed" | "snapshotting";
243
+ createdAt: number;
244
+ updatedAt: number;
245
+ name: string;
246
+ persistent: boolean;
247
+ currentSessionId: string;
248
+ memory?: number | undefined;
249
+ vcpus?: number | undefined;
250
+ region?: string | undefined;
251
+ runtime?: string | undefined;
252
+ timeout?: number | undefined;
253
+ cwd?: string | undefined;
254
+ networkPolicy?: import("zod").objectInputType<{
255
+ mode: import("zod").ZodLiteral<"allow-all">;
256
+ }, import("zod").ZodTypeAny, "passthrough"> | import("zod").objectInputType<{
257
+ mode: import("zod").ZodLiteral<"deny-all">;
258
+ }, import("zod").ZodTypeAny, "passthrough"> | import("zod").objectInputType<{
259
+ mode: import("zod").ZodLiteral<"custom">;
260
+ allowedDomains: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
261
+ allowedCIDRs: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
262
+ deniedCIDRs: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
263
+ injectionRules: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
264
+ domain: import("zod").ZodString;
265
+ headers: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
266
+ headerNames: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
267
+ }, "strip", import("zod").ZodTypeAny, {
268
+ domain: string;
269
+ headers?: Record<string, string> | undefined;
270
+ headerNames?: string[] | undefined;
271
+ }, {
272
+ domain: string;
273
+ headers?: Record<string, string> | undefined;
274
+ headerNames?: string[] | undefined;
275
+ }>, "many">>;
276
+ }, import("zod").ZodTypeAny, "passthrough"> | undefined;
277
+ totalEgressBytes?: number | undefined;
278
+ totalIngressBytes?: number | undefined;
279
+ totalActiveCpuDurationMs?: number | undefined;
280
+ totalDurationMs?: number | undefined;
281
+ currentSnapshotId?: string | undefined;
282
+ tags?: Record<string, string> | undefined;
283
+ }[];
273
284
  }>;
274
285
  /**
275
286
  * Create a new sandbox.
@@ -291,11 +302,11 @@ export declare class Sandbox {
291
302
  * @returns A promise resolving to the {@link Sandbox}.
292
303
  */
293
304
  static get(params: WithPrivate<GetSandboxParams | (GetSandboxParams & Credentials)> & WithFetchOptions): Promise<Sandbox>;
294
- constructor({ client, routes, session, namedSandbox, projectId, }: {
305
+ constructor({ client, routes, session, sandbox, projectId, }: {
295
306
  client: APIClient;
296
307
  routes: SandboxRouteData[];
297
- session: SandboxMetaData;
298
- namedSandbox: NamedSandboxMetaData;
308
+ session: SessionMetaData;
309
+ sandbox: SandboxMetaData;
299
310
  projectId: string;
300
311
  });
301
312
  /**
@@ -305,9 +316,10 @@ export declare class Sandbox {
305
316
  */
306
317
  currentSession(): Session;
307
318
  /**
308
- * Resume this sandbox by creating a new session via `getNamedSandbox`.
319
+ * Resume this sandbox by creating a new session via `getSandbox`.
309
320
  */
310
321
  private resume;
322
+ private doResume;
311
323
  /**
312
324
  * Poll until the current session reaches a terminal state, then resume.
313
325
  */
@@ -442,12 +454,12 @@ export declare class Sandbox {
442
454
  * @param opts - Optional parameters.
443
455
  * @param opts.signal - An AbortSignal to cancel the operation.
444
456
  * @param opts.blocking - If true, poll until the sandbox has fully stopped and return the final state.
445
- * @returns The sandbox metadata at the time the stop was acknowledged, or after fully stopped if `blocking` is true.
457
+ * @returns The sandbox at the time the stop was acknowledged, or after fully stopped if `blocking` is true.
446
458
  */
447
459
  stop(opts?: {
448
460
  signal?: AbortSignal;
449
461
  blocking?: boolean;
450
- }): Promise<ConvertedSandbox>;
462
+ }): Promise<ConvertedSession>;
451
463
  /**
452
464
  * Update the network policy for this sandbox.
453
465
  *
@@ -519,7 +531,7 @@ export declare class Sandbox {
519
531
  signal?: AbortSignal;
520
532
  }): Promise<Snapshot>;
521
533
  /**
522
- * Update the named sandbox configuration.
534
+ * Update the sandbox configuration.
523
535
  *
524
536
  * @param params - Fields to update.
525
537
  * @param opts - Optional abort signal.
@@ -531,21 +543,21 @@ export declare class Sandbox {
531
543
  };
532
544
  timeout?: number;
533
545
  networkPolicy?: NetworkPolicy;
546
+ tags?: Record<string, string>;
534
547
  }, opts?: {
535
548
  signal?: AbortSignal;
536
549
  }): Promise<void>;
537
550
  /**
538
- * Delete this named sandbox.
551
+ * Delete this sandbox.
539
552
  *
540
553
  * After deletion the instance becomes inert — all further API calls will
541
554
  * throw immediately.
542
555
  */
543
556
  delete(opts?: {
544
- preserveSnapshots?: boolean;
545
557
  signal?: AbortSignal;
546
558
  }): Promise<void>;
547
559
  /**
548
- * List sessions (VMs) that have been created for this named sandbox.
560
+ * List sessions (VMs) that have been created for this sandbox.
549
561
  *
550
562
  * @param params - Optional pagination parameters.
551
563
  * @returns The list of sessions and pagination metadata.
@@ -555,32 +567,40 @@ export declare class Sandbox {
555
567
  since?: number | Date;
556
568
  until?: number | Date;
557
569
  signal?: AbortSignal;
558
- }): Promise<import("./api-client/base-client").Parsed<{
559
- sandboxes: {
560
- id: string;
561
- memory: number;
562
- vcpus: number;
563
- region: string;
564
- runtime: string;
565
- timeout: number;
566
- status: "aborted" | "pending" | "running" | "stopping" | "stopped" | "failed" | "snapshotting";
567
- requestedAt: number;
568
- createdAt: number;
569
- cwd: string;
570
- updatedAt: number;
571
- startedAt?: number | undefined;
572
- requestedStopAt?: number | undefined;
573
- stoppedAt?: number | undefined;
574
- abortedAt?: number | undefined;
575
- duration?: number | undefined;
576
- sourceSnapshotId?: string | undefined;
577
- snapshottedAt?: number | undefined;
578
- interactivePort?: number | undefined;
579
- networkPolicy?: import("zod").objectInputType<{
570
+ }): Promise<{
571
+ sessions: import("zod").objectInputType<{
572
+ id: import("zod").ZodString;
573
+ memory: import("zod").ZodNumber;
574
+ vcpus: import("zod").ZodNumber;
575
+ region: import("zod").ZodString;
576
+ runtime: import("zod").ZodString;
577
+ timeout: import("zod").ZodNumber;
578
+ status: import("zod").ZodEnum<["pending", "running", "stopping", "stopped", "failed", "aborted", "snapshotting"]>;
579
+ requestedAt: import("zod").ZodNumber;
580
+ startedAt: import("zod").ZodOptional<import("zod").ZodNumber>;
581
+ requestedStopAt: import("zod").ZodOptional<import("zod").ZodNumber>;
582
+ stoppedAt: import("zod").ZodOptional<import("zod").ZodNumber>;
583
+ abortedAt: import("zod").ZodOptional<import("zod").ZodNumber>;
584
+ duration: import("zod").ZodOptional<import("zod").ZodNumber>;
585
+ sourceSnapshotId: import("zod").ZodOptional<import("zod").ZodString>;
586
+ snapshottedAt: import("zod").ZodOptional<import("zod").ZodNumber>;
587
+ createdAt: import("zod").ZodNumber;
588
+ cwd: import("zod").ZodString;
589
+ updatedAt: import("zod").ZodNumber;
590
+ interactivePort: import("zod").ZodOptional<import("zod").ZodNumber>;
591
+ networkPolicy: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodObject<{
580
592
  mode: import("zod").ZodLiteral<"allow-all">;
581
- }, import("zod").ZodTypeAny, "passthrough"> | import("zod").objectInputType<{
593
+ }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
594
+ mode: import("zod").ZodLiteral<"allow-all">;
595
+ }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
596
+ mode: import("zod").ZodLiteral<"allow-all">;
597
+ }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
582
598
  mode: import("zod").ZodLiteral<"deny-all">;
583
- }, import("zod").ZodTypeAny, "passthrough"> | import("zod").objectInputType<{
599
+ }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
600
+ mode: import("zod").ZodLiteral<"deny-all">;
601
+ }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
602
+ mode: import("zod").ZodLiteral<"deny-all">;
603
+ }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
584
604
  mode: import("zod").ZodLiteral<"custom">;
585
605
  allowedDomains: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
586
606
  allowedCIDRs: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
@@ -598,21 +618,63 @@ export declare class Sandbox {
598
618
  headers?: Record<string, string> | undefined;
599
619
  headerNames?: string[] | undefined;
600
620
  }>, "many">>;
601
- }, import("zod").ZodTypeAny, "passthrough"> | undefined;
602
- activeCpuDurationMs?: number | undefined;
603
- networkTransfer?: {
621
+ }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
622
+ mode: import("zod").ZodLiteral<"custom">;
623
+ allowedDomains: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
624
+ allowedCIDRs: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
625
+ deniedCIDRs: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
626
+ injectionRules: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
627
+ domain: import("zod").ZodString;
628
+ headers: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
629
+ headerNames: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
630
+ }, "strip", import("zod").ZodTypeAny, {
631
+ domain: string;
632
+ headers?: Record<string, string> | undefined;
633
+ headerNames?: string[] | undefined;
634
+ }, {
635
+ domain: string;
636
+ headers?: Record<string, string> | undefined;
637
+ headerNames?: string[] | undefined;
638
+ }>, "many">>;
639
+ }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
640
+ mode: import("zod").ZodLiteral<"custom">;
641
+ allowedDomains: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
642
+ allowedCIDRs: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
643
+ deniedCIDRs: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
644
+ injectionRules: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
645
+ domain: import("zod").ZodString;
646
+ headers: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
647
+ headerNames: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
648
+ }, "strip", import("zod").ZodTypeAny, {
649
+ domain: string;
650
+ headers?: Record<string, string> | undefined;
651
+ headerNames?: string[] | undefined;
652
+ }, {
653
+ domain: string;
654
+ headers?: Record<string, string> | undefined;
655
+ headerNames?: string[] | undefined;
656
+ }>, "many">>;
657
+ }, import("zod").ZodTypeAny, "passthrough">>]>>;
658
+ activeCpuDurationMs: import("zod").ZodOptional<import("zod").ZodNumber>;
659
+ networkTransfer: import("zod").ZodOptional<import("zod").ZodObject<{
660
+ ingress: import("zod").ZodNumber;
661
+ egress: import("zod").ZodNumber;
662
+ }, "strip", import("zod").ZodTypeAny, {
604
663
  ingress: number;
605
664
  egress: number;
606
- } | undefined;
607
- }[];
665
+ }, {
666
+ ingress: number;
667
+ egress: number;
668
+ }>>;
669
+ }, import("zod").ZodTypeAny, "passthrough">[];
608
670
  pagination: {
609
671
  count: number;
610
672
  next: number | null;
611
673
  prev: number | null;
612
674
  };
613
- }>>;
675
+ }>;
614
676
  /**
615
- * List snapshots that belong to this named sandbox.
677
+ * List snapshots that belong to this sandbox.
616
678
  *
617
679
  * @param params - Optional pagination parameters.
618
680
  * @returns The list of snapshots and pagination metadata.
@@ -622,7 +684,7 @@ export declare class Sandbox {
622
684
  since?: number | Date;
623
685
  until?: number | Date;
624
686
  signal?: AbortSignal;
625
- }): Promise<import("./api-client/base-client").Parsed<{
687
+ }): Promise<{
626
688
  pagination: {
627
689
  count: number;
628
690
  next: number | null;
@@ -634,9 +696,9 @@ export declare class Sandbox {
634
696
  status: "failed" | "created" | "deleted";
635
697
  createdAt: number;
636
698
  updatedAt: number;
637
- sourceSandboxId: string;
699
+ sourceSessionId: string;
638
700
  sizeBytes: number;
639
701
  expiresAt?: number | undefined;
640
702
  }[];
641
- }>>;
703
+ }>;
642
704
  }