Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/vercel-sandbox/src/api-client/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export class APIClient extends BaseClient {

async createSandbox(
params: WithPrivate<{
name?: string;
ports?: number[];
projectId: string;
source?:
Expand All @@ -163,6 +164,7 @@ export class APIClient extends BaseClient {
| { type: "snapshot"; snapshotId: string };
timeout?: number;
resources?: { vcpus: number };
snapshotOnShutdown?: boolean;
runtime?: RUNTIMES | (string & {});
networkPolicy?: NetworkPolicy;
signal?: AbortSignal;
Expand All @@ -171,7 +173,7 @@ export class APIClient extends BaseClient {
const privateParams = getPrivateParams(params);
return parseOrThrow(
SandboxAndRoutesResponse,
await this.request("/v1/sandboxes", {
await this.request("/v1/sandboxes/named", {
method: "POST",
body: JSON.stringify({
projectId: params.projectId,
Expand All @@ -180,6 +182,8 @@ export class APIClient extends BaseClient {
timeout: params.timeout,
resources: params.resources,
runtime: params.runtime,
name: params.name,
snapshotOnShutdown: params.snapshotOnShutdown,
networkPolicy: params.networkPolicy
? toAPINetworkPolicy(params.networkPolicy)
: undefined,
Expand Down
21 changes: 16 additions & 5 deletions packages/vercel-sandbox/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ import { RUNTIMES } from "./constants";
import { Snapshot } from "./snapshot";
import { consumeReadable } from "./utils/consume-readable";
import {
type NetworkPolicy,
type NetworkPolicyRule,
type NetworkTransformer,
type NetworkPolicy,
type NetworkPolicyRule,
type NetworkTransformer,
} from "./network-policy";
import { convertSandbox, type ConvertedSandbox } from "./utils/convert-sandbox";

export type { NetworkPolicy, NetworkPolicyRule, NetworkTransformer };

/** @inline */
export interface BaseCreateSandboxParams {
/**
* The name of the sandbox. If omitted, a random name will be generated.
*/
name?: string;
/**
* The source of the sandbox.
*
Expand Down Expand Up @@ -81,6 +85,11 @@ export interface BaseCreateSandboxParams {
* An AbortSignal to cancel sandbox creation.
*/
signal?: AbortSignal;

/**
* Whether to enable snapshots on shutdown. Defaults to true.
*/
snapshotOnShutdown?: boolean;
}

export type CreateSandboxParams =
Expand Down Expand Up @@ -265,6 +274,8 @@ export class Sandbox {
runtime: params && "runtime" in params ? params?.runtime : undefined,
networkPolicy: params?.networkPolicy,
signal: params?.signal,
name: params?.name,
snapshotOnShutdown: params?.snapshotOnShutdown,
...privateParams,
});

Expand Down Expand Up @@ -423,7 +434,7 @@ export class Sandbox {
}
})();
}
}
};

if (wait) {
const commandStream = await this.client.runCommand({
Expand Down Expand Up @@ -589,7 +600,7 @@ export class Sandbox {
});
return dstPath;
} finally {
stream.destroy()
stream.destroy();
}
}

Expand Down