@vercel/sandbox 2.0.0-beta.18 → 2.0.0-beta.19
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/api-client/api-client.d.cts +115 -115
- package/dist/api-client/api-client.d.ts +115 -115
- package/dist/api-client/validators.d.cts +364 -364
- package/dist/api-client/validators.d.ts +364 -364
- package/dist/auth/file.d.cts +3 -3
- package/dist/auth/file.d.ts +3 -3
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/sandbox.cjs.map +1 -1
- package/dist/sandbox.d.cts +24 -24
- package/dist/sandbox.d.ts +24 -24
- package/dist/sandbox.js.map +1 -1
- package/dist/snapshot.d.cts +1 -1
- package/dist/snapshot.d.ts +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
package/dist/auth/file.d.cts
CHANGED
|
@@ -7,18 +7,18 @@ declare const AuthFile: z.ZodObject<{
|
|
|
7
7
|
expiresAt: z.ZodOptional<z.ZodEffects<z.ZodNumber, Date, number>>;
|
|
8
8
|
}, "strip", z.ZodTypeAny, {
|
|
9
9
|
token?: string | undefined;
|
|
10
|
-
refreshToken?: string | undefined;
|
|
11
10
|
expiresAt?: Date | undefined;
|
|
11
|
+
refreshToken?: string | undefined;
|
|
12
12
|
}, {
|
|
13
13
|
token?: string | undefined;
|
|
14
|
-
refreshToken?: string | undefined;
|
|
15
14
|
expiresAt?: number | undefined;
|
|
15
|
+
refreshToken?: string | undefined;
|
|
16
16
|
}>;
|
|
17
17
|
type AuthFile = z.infer<typeof AuthFile>;
|
|
18
18
|
declare const getAuth: () => {
|
|
19
19
|
token?: string | undefined;
|
|
20
|
-
refreshToken?: string | undefined;
|
|
21
20
|
expiresAt?: Date | undefined;
|
|
21
|
+
refreshToken?: string | undefined;
|
|
22
22
|
} | null;
|
|
23
23
|
declare function updateAuthConfig(config: AuthFile): void;
|
|
24
24
|
//#endregion
|
package/dist/auth/file.d.ts
CHANGED
|
@@ -7,18 +7,18 @@ declare const AuthFile: z.ZodObject<{
|
|
|
7
7
|
expiresAt: z.ZodOptional<z.ZodEffects<z.ZodNumber, Date, number>>;
|
|
8
8
|
}, "strip", z.ZodTypeAny, {
|
|
9
9
|
token?: string | undefined;
|
|
10
|
-
refreshToken?: string | undefined;
|
|
11
10
|
expiresAt?: Date | undefined;
|
|
11
|
+
refreshToken?: string | undefined;
|
|
12
12
|
}, {
|
|
13
13
|
token?: string | undefined;
|
|
14
|
-
refreshToken?: string | undefined;
|
|
15
14
|
expiresAt?: number | undefined;
|
|
15
|
+
refreshToken?: string | undefined;
|
|
16
16
|
}>;
|
|
17
17
|
type AuthFile = z.infer<typeof AuthFile>;
|
|
18
18
|
declare const getAuth: () => {
|
|
19
19
|
token?: string | undefined;
|
|
20
|
-
refreshToken?: string | undefined;
|
|
21
20
|
expiresAt?: Date | undefined;
|
|
21
|
+
refreshToken?: string | undefined;
|
|
22
22
|
} | null;
|
|
23
23
|
declare function updateAuthConfig(config: AuthFile): void;
|
|
24
24
|
//#endregion
|
package/dist/constants.d.cts
CHANGED
package/dist/constants.d.ts
CHANGED
package/dist/sandbox.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.cjs","names":["APIError","getCredentials","APIClient","fromAPINetworkPolicy","attachPaginator","WORKFLOW_SERIALIZE","WORKFLOW_DESERIALIZE","Session","getPrivateParams","FileSystem","resources: { vcpus: number; memory: number } | undefined"],"sources":["../src/sandbox.ts"],"sourcesContent":["import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from \"@workflow/serde\";\nimport type {\n SessionMetaData,\n SandboxRouteData,\n SandboxMetaData,\n SnapshotMetadata,\n} from \"./api-client/index.js\";\nimport { APIClient } from \"./api-client/index.js\";\nimport { APIError } from \"./api-client/api-error.js\";\nimport { type Credentials, getCredentials } from \"./utils/get-credentials.js\";\nimport { getPrivateParams, type WithPrivate } from \"./utils/types.js\";\nimport type { WithFetchOptions } from \"./api-client/api-client.js\";\nimport type { RUNTIMES } from \"./constants.js\";\nimport { Session, type RunCommandParams } from \"./session.js\";\nimport type { Command, CommandFinished } from \"./command.js\";\nimport type { Snapshot } from \"./snapshot.js\";\nimport type { SandboxSnapshot } from \"./utils/sandbox-snapshot.js\";\nimport type {\n NetworkPolicy,\n NetworkPolicyKeyValueMatcher,\n NetworkPolicyMatch,\n NetworkPolicyMatcher,\n} from \"./network-policy.js\";\nimport { fromAPINetworkPolicy } from \"./utils/network-policy.js\";\nimport { attachPaginator } from \"./utils/paginator.js\";\nimport { setTimeout } from \"node:timers/promises\";\nimport { FileSystem } from \"./filesystem.js\";\n\nexport type {\n NetworkPolicy,\n NetworkPolicyKeyValueMatcher,\n NetworkPolicyMatch,\n NetworkPolicyMatcher,\n};\n\n/** @inline */\nexport interface BaseCreateSandboxParams {\n /**\n * The name of the sandbox. If omitted, a random name will be generated.\n */\n name?: string;\n /**\n * The source of the sandbox.\n *\n * Omit this parameter start a sandbox without a source.\n *\n * For git sources:\n * - `depth`: Creates shallow clones with limited commit history (minimum: 1)\n * - `revision`: Clones and checks out a specific commit, branch, or tag\n */\n source?:\n | {\n type: \"git\";\n url: string;\n depth?: number;\n revision?: string;\n }\n | {\n type: \"git\";\n url: string;\n username: string;\n password: string;\n depth?: number;\n revision?: string;\n }\n | { type: \"tarball\"; url: string };\n /**\n * Array of port numbers to expose from the sandbox. Sandboxes can\n * expose up to 4 ports.\n */\n ports?: number[];\n /**\n * Timeout in milliseconds before the sandbox auto-terminates.\n */\n timeout?: number;\n /**\n * Resources to allocate to the sandbox.\n *\n * Your sandbox will get the amount of vCPUs you specify here and\n * 2048 MB of memory per vCPU.\n */\n resources?: { vcpus: number };\n /**\n * The runtime of the sandbox, currently only `node24`, `node22` and `python3.13` are supported.\n * If not specified, the default runtime `node24` will be used.\n */\n runtime?: RUNTIMES | (string & {});\n /**\n * Network policy to define network restrictions for the sandbox.\n * Defaults to full internet access if not specified.\n */\n networkPolicy?: NetworkPolicy;\n /**\n * Default environment variables for the sandbox.\n * These are inherited by all commands unless overridden with\n * the `env` option in `runCommand`.\n *\n * @example\n * const sandbox = await Sandbox.create({\n * env: { NODE_ENV: \"production\", API_KEY: \"secret\" },\n * });\n * // All commands will have NODE_ENV and API_KEY set\n * await sandbox.runCommand(\"node\", [\"app.js\"]);\n */\n env?: Record<string, string>;\n /**\n * Key-value tags to associate with the sandbox. Maximum 5 tags.\n * @example { env: \"staging\", team: \"infra\" }\n */\n tags?: Record<string, string>;\n\n /**\n * An AbortSignal to cancel sandbox creation.\n */\n signal?: AbortSignal;\n /**\n * Enable or disable automatic restore of the filesystem between sessions.\n */\n persistent?: boolean;\n /**\n * Default snapshot expiration in milliseconds.\n * When set, snapshots created for this sandbox will expire after this duration.\n * Use `0` for no expiration.\n */\n snapshotExpiration?: number;\n /**\n * Called when the sandbox session is resumed (e.g., after a snapshot restore).\n * Use this to re-warm caches, restore transient state, or run other setup logic.\n */\n onResume?: (sandbox: Sandbox) => Promise<void>;\n}\n\nexport type CreateSandboxParams =\n | BaseCreateSandboxParams\n | (Omit<BaseCreateSandboxParams, \"runtime\" | \"source\"> & {\n source: { type: \"snapshot\"; snapshotId: string };\n });\n\n/** @inline */\ninterface GetSandboxParams {\n /**\n * The name of the sandbox.\n */\n name: string;\n /**\n * Whether to resume an existing session. Defaults to true.\n */\n resume?: boolean;\n /**\n * An AbortSignal to cancel the operation.\n */\n signal?: AbortSignal;\n /**\n * Called when the sandbox session is resumed (e.g., after a snapshot restore).\n * Use this to re-warm caches, restore transient state, or run other setup logic.\n */\n onResume?: (sandbox: Sandbox) => Promise<void>;\n}\n\n/**\n * Extends both {@link BaseCreateSandboxParams} and {@link GetSandboxParams}\n * (minus `name`, which is required on get but optional here) so that any\n * new parameter added to either flow is picked up automatically. The\n * structural overlap on `signal` / `onResume` is intentional — both\n * interfaces declare them with identical optional types.\n * @inline\n */\ninterface GetOrCreateSandboxParams\n extends BaseCreateSandboxParams,\n Omit<GetSandboxParams, \"name\"> {\n /**\n * Called once after a sandbox is freshly created (not when an existing\n * sandbox is retrieved). Use this for one-time setup such as seeding\n * files or warming caches. The returned promise is awaited before\n * {@link Sandbox.getOrCreate} resolves.\n */\n onCreate?: (sandbox: Sandbox) => Promise<void>;\n}\n\nfunction isSandboxStoppedError(err: unknown): boolean {\n return err instanceof APIError && err.response.status === 410;\n}\n\nfunction isNotFoundError(err: unknown): boolean {\n return err instanceof APIError && err.response.status === 404;\n}\n\nfunction isSnapshotNotFoundError(err: unknown): boolean {\n return (\n err instanceof APIError &&\n err.response.status === 400 &&\n (err.json as any)?.error?.code === \"snapshot_not_found\"\n );\n}\n\nfunction isSandboxStoppingError(err: unknown): boolean {\n return (\n err instanceof APIError &&\n err.response.status === 422 &&\n (err.json as any)?.error?.code === \"sandbox_stopping\"\n );\n}\n\nfunction isSandboxSnapshottingError(err: unknown): boolean {\n return (\n err instanceof APIError &&\n err.response.status === 422 &&\n (err.json as any)?.error?.code === \"sandbox_snapshotting\"\n );\n}\n\n/**\n * Serialized representation of a Sandbox for @workflow/serde.\n * Fields `metadata` and `routes` are the original wire format from main.\n * Fields `sandboxMetadata` and `projectId` are added for named-sandboxes.\n */\nexport interface SerializedSandbox {\n metadata: SandboxSnapshot;\n routes: SandboxRouteData[];\n sandboxMetadata?: SandboxMetaData;\n projectId?: string;\n}\n\n// ============================================================================\n// Sandbox class\n// ============================================================================\n\n/**\n * A Sandbox is a persistent, isolated Linux MicroVMs to run commands in.\n * Use {@link Sandbox.create} or {@link Sandbox.get} to construct.\n * @hideconstructor\n */\nexport class Sandbox {\n private _client: APIClient | null = null;\n private readonly projectId: string;\n\n /**\n * In-flight resume promise, used to deduplicate concurrent resume calls.\n */\n private resumePromise: Promise<void> | null = null;\n\n /**\n * Internal Session instance for the current VM.\n */\n private session: Session | undefined;\n\n /**\n * Internal metadata about the sandbox.\n */\n private sandbox: SandboxMetaData;\n\n /**\n * Hook that will be executed when a new session is created during resume.\n */\n private readonly onResume?: (sandbox: Sandbox) => Promise<void>;\n\n /**\n * A `node:fs/promises`-compatible API for interacting with the sandbox filesystem.\n *\n * @example\n * const content = await sandbox.fs.readFile('/etc/hostname', 'utf8');\n * await sandbox.fs.writeFile('/tmp/hello.txt', 'Hello, world!');\n * const files = await sandbox.fs.readdir('/tmp');\n * const stats = await sandbox.fs.stat('/tmp/hello.txt');\n */\n public readonly fs: FileSystem;\n\n /**\n * Lazily resolve credentials and construct an API client.\n * @internal\n */\n private async ensureClient(): Promise<APIClient> {\n \"use step\";\n if (this._client) return this._client;\n const credentials = await getCredentials();\n this._client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n return this._client;\n }\n\n /**\n * The name of this sandbox.\n */\n public get name(): string {\n return this.sandbox.name;\n }\n\n /**\n * Routes from ports to subdomains.\n * @hidden\n */\n public get routes(): SandboxRouteData[] {\n return this.currentSession().routes;\n }\n\n /**\n * Whether the sandbox persists the state.\n */\n public get persistent(): boolean {\n return this.sandbox.persistent;\n }\n\n /**\n * The region this sandbox runs in.\n */\n public get region(): string | undefined {\n return this.sandbox.region;\n }\n\n /**\n * Number of virtual CPUs allocated.\n */\n public get vcpus(): number | undefined {\n return this.sandbox.vcpus;\n }\n\n /**\n * Memory allocated in MB.\n */\n public get memory(): number | undefined {\n return this.sandbox.memory;\n }\n\n /** Runtime identifier (e.g. \"node24\", \"python3.13\"). */\n public get runtime(): string | undefined {\n return this.sandbox.runtime;\n }\n\n /**\n * Cumulative egress bytes across all sessions.\n */\n public get totalEgressBytes(): number | undefined {\n return this.sandbox.totalEgressBytes;\n }\n\n /**\n * Cumulative ingress bytes across all sessions.\n */\n public get totalIngressBytes(): number | undefined {\n return this.sandbox.totalIngressBytes;\n }\n\n /**\n * Cumulative active CPU duration in milliseconds across all sessions.\n */\n public get totalActiveCpuDurationMs(): number | undefined {\n return this.sandbox.totalActiveCpuDurationMs;\n }\n\n /**\n * Cumulative wall-clock duration in milliseconds across all sessions.\n */\n public get totalDurationMs(): number | undefined {\n return this.sandbox.totalDurationMs;\n }\n\n /**\n * When this sandbox was last updated.\n */\n public get updatedAt(): Date {\n return new Date(this.sandbox.updatedAt);\n }\n\n /**\n * When the sandbox status was last updated.\n */\n public get statusUpdatedAt(): Date | undefined {\n return this.sandbox.statusUpdatedAt\n ? new Date(this.sandbox.statusUpdatedAt)\n : undefined;\n }\n\n /**\n * When this sandbox was created.\n */\n public get createdAt(): Date {\n return new Date(this.sandbox.createdAt);\n }\n\n /**\n * Interactive port.\n */\n public get interactivePort(): number | undefined {\n return this.currentSession().interactivePort;\n }\n\n /**\n * The status of the current session.\n */\n public get status(): SessionMetaData[\"status\"] {\n return this.currentSession().status;\n }\n\n /**\n * The default timeout of this sandbox in milliseconds.\n */\n public get timeout(): number | undefined {\n return this.sandbox.timeout;\n }\n\n /**\n * Key-value tags attached to the sandbox.\n */\n public get tags(): Record<string, string> | undefined {\n return this.sandbox.tags;\n }\n\n /**\n * The default network policy of this sandbox.\n */\n public get networkPolicy(): NetworkPolicy | undefined {\n return this.sandbox.networkPolicy\n ? fromAPINetworkPolicy(this.sandbox.networkPolicy)\n : undefined;\n }\n\n /**\n * If the session was created from a snapshot, the ID of that snapshot.\n */\n public get sourceSnapshotId(): string | undefined {\n return this.currentSession().sourceSnapshotId;\n }\n\n /**\n * The current snapshot ID of this sandbox, if any.\n */\n public get currentSnapshotId(): string | undefined {\n return this.sandbox.currentSnapshotId;\n }\n\n /**\n * The default snapshot expiration in milliseconds, if set.\n */\n public get snapshotExpiration(): number | undefined {\n return this.sandbox.snapshotExpiration;\n }\n\n /**\n * The amount of CPU used by the session. Only reported once the VM is stopped.\n */\n public get activeCpuUsageMs(): number | undefined {\n return this.currentSession().activeCpuUsageMs;\n }\n\n /**\n * The amount of network data used by the session. Only reported once the VM is stopped.\n */\n public get networkTransfer():\n | { ingress: number; egress: number }\n | undefined {\n return this.currentSession().networkTransfer;\n }\n\n /**\n * Allow to get a list of sandboxes for a team narrowed to the given params.\n * It returns both the sandboxes and the pagination metadata to allow getting\n * the next page of results.\n *\n * The returned object is async-iterable to auto-paginate through all pages:\n *\n * ```ts\n * const result = await Sandbox.list({ namePrefix: \"ci-\" });\n * for await (const sandbox of result) { ... }\n * // or: await result.toArray();\n * // or: for await (const page of result.pages()) { ... }\n * ```\n */\n static async list(\n params?: Partial<Parameters<APIClient[\"listSandboxes\"]>[0]> &\n Partial<Credentials> &\n WithFetchOptions,\n ) {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n const fetchPage = async (cursor?: string) => {\n const response = await client.listSandboxes({\n ...credentials,\n ...params,\n ...(cursor !== undefined && { cursor }),\n });\n return response.json;\n };\n const firstPage = await fetchPage(params?.cursor);\n return attachPaginator(firstPage, {\n itemsKey: \"sandboxes\",\n fetchNext: fetchPage,\n signal: params?.signal,\n });\n }\n\n /**\n * Serialize a Sandbox instance to plain data for @workflow/serde.\n *\n * @param instance - The Sandbox instance to serialize\n * @returns A plain object containing sandbox metadata and routes\n */\n static [WORKFLOW_SERIALIZE](instance: Sandbox): SerializedSandbox {\n return {\n metadata: instance.session?._sessionSnapshot!,\n routes: instance.session?.routes ?? [],\n sandboxMetadata: instance.sandbox,\n projectId: instance.projectId,\n };\n }\n\n /**\n * Deserialize a Sandbox from serialized snapshot data.\n *\n * The deserialized instance uses the serialized metadata synchronously and\n * lazily creates an API client only when methods perform API requests.\n *\n * @param data - The serialized sandbox data\n * @returns The reconstructed Sandbox instance\n */\n static [WORKFLOW_DESERIALIZE](data: SerializedSandbox): Sandbox {\n const sandbox = new Sandbox({\n sandbox: data.sandboxMetadata!,\n routes: data.routes,\n projectId: data.projectId,\n });\n if (data.metadata) {\n sandbox.session = new Session({ routes: data.routes, snapshot: data.metadata });\n }\n return sandbox;\n }\n\n /**\n * Create a new sandbox.\n *\n * @param params - Creation parameters and optional credentials.\n * @returns A promise resolving to the created {@link Sandbox}.\n * @example\n * <caption>Create a sandbox with default options</caption>\n * const sandbox = await Sandbox.create();\n *\n * @example\n * <caption>Create a sandbox and drop it in the end of the block</caption>\n * async function fn() {\n * await using const sandbox = await Sandbox.create();\n * // Sandbox automatically stopped at the end of the lexical scope\n * }\n */\n static async create(\n params?: WithPrivate<\n CreateSandboxParams | (CreateSandboxParams & Credentials)\n > &\n WithFetchOptions,\n ): Promise<Sandbox & AsyncDisposable> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n\n const privateParams = getPrivateParams(params);\n const response = await client.createSandbox({\n source: params?.source,\n projectId: credentials.projectId,\n ports: params?.ports ?? [],\n timeout: params?.timeout,\n resources: params?.resources,\n runtime: params && \"runtime\" in params ? params?.runtime : undefined,\n networkPolicy: params?.networkPolicy,\n env: params?.env,\n tags: params?.tags,\n snapshotExpiration: params?.snapshotExpiration,\n signal: params?.signal,\n name: params?.name,\n persistent: params?.persistent,\n ...privateParams,\n });\n\n return new DisposableSandbox({\n client,\n session: response.json.session,\n sandbox: response.json.sandbox,\n routes: response.json.routes,\n projectId: credentials.projectId,\n onResume: params?.onResume,\n });\n }\n\n /**\n * Retrieve an existing sandbox and resume its session.\n *\n * @param params - Get parameters and optional credentials.\n * @returns A promise resolving to the {@link Sandbox}.\n */\n static async get(\n params: WithPrivate<GetSandboxParams | (GetSandboxParams & Credentials)> &\n WithFetchOptions,\n ): Promise<Sandbox> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params.fetch,\n });\n\n const privateParams = getPrivateParams(params);\n const response = await client.getSandbox({\n name: params.name,\n projectId: credentials.projectId,\n resume: params.resume,\n signal: params.signal,\n ...privateParams,\n });\n\n const sandbox = new Sandbox({\n client,\n session: response.json.session,\n sandbox: response.json.sandbox,\n routes: response.json.routes,\n projectId: credentials.projectId,\n onResume: params.onResume,\n });\n\n if (response.json.resumed && params.onResume) {\n await params.onResume(sandbox);\n }\n\n return sandbox;\n }\n\n /**\n * Retrieve an existing named sandbox, or create a new one if none exists.\n *\n * If `name` is omitted, this always creates a new sandbox and fires\n * `onCreate`. If `name` is provided, it first tries {@link Sandbox.get};\n * on `not_found` it creates a new sandbox with that name; on\n * `snapshot_not_found` it deletes the stale named sandbox and creates\n * a fresh one with the same name.\n *\n * @param params - Get/create parameters plus an optional `onCreate` hook.\n * @returns A promise resolving to the {@link Sandbox}.\n *\n * @example\n * <caption>Idempotent named sandbox with one-time setup</caption>\n * const sandbox = await Sandbox.getOrCreate({\n * name: \"my-workspace\",\n * onCreate: async (sbx) => {\n * await sbx.writeFiles([\n * { path: \"README.md\", content: Buffer.from(\"# Hello\") },\n * ]);\n * },\n * });\n *\n * @example\n * <caption>Unnamed — always creates</caption>\n * const sandbox = await Sandbox.getOrCreate({\n * onCreate: async (sbx) => {\n * await sbx.runCommand(\"npm\", [\"install\"]);\n * },\n * });\n */\n static async getOrCreate(\n params?: WithPrivate<\n GetOrCreateSandboxParams | (GetOrCreateSandboxParams & Credentials)\n > &\n WithFetchOptions,\n ): Promise<Sandbox> {\n \"use step\";\n // No name → always create, fire onCreate.\n if (!params?.name) {\n const sandbox = await Sandbox.create(params);\n if (params?.onCreate) {\n await params.onCreate(sandbox);\n }\n return sandbox;\n }\n\n try {\n return await Sandbox.get(\n params as unknown as Parameters<typeof Sandbox.get>[0],\n );\n } catch (err) {\n if (isNotFoundError(err)) {\n // Sandbox does not exist: re-create it.\n const sandbox = await Sandbox.create(params);\n if (params.onCreate) {\n await params.onCreate(sandbox);\n }\n return sandbox;\n }\n\n if (isSnapshotNotFoundError(err)) {\n // Sandbox exists but the snapshot has expired. Delete it and create\n // a new one.\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params.fetch,\n });\n const privateParams = getPrivateParams(params);\n try {\n await client.deleteSandbox({\n name: params.name,\n projectId: credentials.projectId,\n signal: params.signal,\n ...privateParams,\n });\n } catch (deleteErr) {\n // Tolerate 404 — the named sandbox was already cleaned up by a\n // concurrent request. Propagate anything else.\n if (!isNotFoundError(deleteErr)) {\n throw deleteErr;\n }\n }\n\n const sandbox = await Sandbox.create(params);\n if (params.onCreate) {\n await params.onCreate(sandbox);\n }\n return sandbox;\n }\n\n throw err;\n }\n }\n\n /**\n * Create a new Sandbox instance.\n *\n * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.\n * @param params.routes - Port-to-subdomain mappings for exposed ports\n * @param params.sandbox - Sandbox snapshot metadata\n */\n constructor({\n client,\n routes,\n session,\n sandbox,\n projectId,\n onResume,\n }: {\n client?: APIClient;\n routes: SandboxRouteData[];\n session?: SessionMetaData;\n sandbox: SandboxMetaData;\n projectId?: string;\n onResume?: (sandbox: Sandbox) => Promise<void>;\n }) {\n this._client = client ?? null;\n if (session) {\n this.session = new Session({ client: client!, routes, session });\n }\n this.sandbox = sandbox;\n this.projectId = projectId ?? \"\";\n this.onResume = onResume;\n this.fs = new FileSystem(this);\n }\n\n /**\n * Get the current session (the running VM) for this sandbox.\n *\n * @returns The {@link Session} instance.\n */\n currentSession(): Session {\n if (!this.session) {\n throw new Error(\"No active session. Run a command or call resume first.\");\n }\n return this.session;\n }\n\n /**\n * Resume this sandbox by creating a new session via `getSandbox`.\n */\n private async resume(signal?: AbortSignal): Promise<void> {\n if (!this.resumePromise) {\n this.resumePromise = this.doResume(signal).finally(() => {\n this.resumePromise = null;\n });\n }\n return this.resumePromise;\n }\n\n private async doResume(signal?: AbortSignal): Promise<void> {\n const client = await this.ensureClient();\n const response = await client.getSandbox({\n name: this.sandbox.name,\n projectId: this.projectId,\n resume: true,\n signal,\n });\n this.session = new Session({\n client,\n routes: response.json.routes,\n session: response.json.session,\n });\n if (this.onResume && response.json.resumed) {\n await this.onResume(this);\n }\n }\n\n /**\n * Poll until the current session reaches a terminal state, then resume.\n */\n private async waitForStopAndResume(signal?: AbortSignal): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n const pollingInterval = 500;\n let status = this.session!.status;\n\n while (status === \"stopping\" || status === \"snapshotting\") {\n await setTimeout(pollingInterval, undefined, { signal });\n const poll = await client.getSession({\n sessionId: this.session!.sessionId,\n signal,\n });\n this.session = new Session({\n client,\n routes: poll.json.routes,\n session: poll.json.session,\n });\n status = poll.json.session.status;\n }\n await this.resume(signal);\n }\n\n /**\n * Execute `fn`, and if the session is stopped/stopping/snapshotting, resume and retry.\n */\n private async withResume<T>(\n fn: () => Promise<T>,\n signal?: AbortSignal,\n ): Promise<T> {\n if (!this.session) {\n await this.resume(signal);\n }\n try {\n return await fn();\n } catch (err) {\n if (isSandboxStoppedError(err)) {\n await this.resume(signal);\n return fn();\n }\n if (isSandboxStoppingError(err) || isSandboxSnapshottingError(err)) {\n await this.waitForStopAndResume(signal);\n return fn();\n }\n throw err;\n }\n }\n\n /**\n * Start executing a command in this sandbox.\n *\n * @param command - The command to execute.\n * @param args - Arguments to pass to the command.\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the command execution.\n * @returns A {@link CommandFinished} result once execution is done.\n */\n async runCommand(\n command: string,\n args?: string[],\n opts?: { signal?: AbortSignal },\n ): Promise<CommandFinished>;\n /**\n * Start executing a command in detached mode.\n *\n * @param params - The command parameters.\n * @returns A {@link Command} instance for the running command.\n */\n async runCommand(\n params: RunCommandParams & { detached: true },\n ): Promise<Command>;\n\n /**\n * Start executing a command in this sandbox.\n *\n * @param params - The command parameters.\n * @returns A {@link CommandFinished} result once execution is done.\n */\n\n async runCommand(params: RunCommandParams): Promise<CommandFinished>;\n\n async runCommand(\n commandOrParams: string | RunCommandParams,\n args?: string[],\n opts?: { signal?: AbortSignal },\n ): Promise<Command | CommandFinished> {\n \"use step\";\n const signal =\n typeof commandOrParams === \"string\"\n ? opts?.signal\n : commandOrParams.signal;\n return this.withResume(\n () => this.session!.runCommand(commandOrParams as any, args, opts),\n signal,\n );\n }\n\n /**\n * Internal helper to start a command in the sandbox.\n *\n * @param params - Command execution parameters.\n * @returns A {@link Command} or {@link CommandFinished}, depending on `detached`.\n * @internal\n */\n async getCommand(\n cmdId: string,\n opts?: { signal?: AbortSignal },\n ): Promise<Command> {\n \"use step\";\n return this.withResume(\n () => this.session!.getCommand(cmdId, opts),\n opts?.signal,\n );\n }\n\n /**\n * Create a directory in the filesystem of this sandbox.\n *\n * @param path - Path of the directory to create\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n */\n async mkDir(path: string, opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n return this.withResume(\n () => this.session!.mkDir(path, opts),\n opts?.signal,\n );\n }\n\n /**\n * Read a file from the filesystem of this sandbox as a stream.\n *\n * @param file - File to read, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found\n */\n async readFile(\n file: { path: string; cwd?: string },\n opts?: { signal?: AbortSignal },\n ): Promise<NodeJS.ReadableStream | null> {\n \"use step\";\n return this.withResume(\n () => this.session!.readFile(file, opts),\n opts?.signal,\n );\n }\n\n /**\n * Read a file from the filesystem of this sandbox as a Buffer.\n *\n * @param file - File to read, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to the file contents as a Buffer, or null if file not found\n */\n async readFileToBuffer(\n file: { path: string; cwd?: string },\n opts?: { signal?: AbortSignal },\n ): Promise<Buffer | null> {\n \"use step\";\n return this.withResume(\n () => this.session!.readFileToBuffer(file, opts),\n opts?.signal,\n );\n }\n\n /**\n * Download a file from the sandbox to the local filesystem.\n *\n * @param src - Source file on the sandbox, with path and optional cwd\n * @param dst - Destination file on the local machine, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns The absolute path to the written file, or null if the source file was not found\n */\n async downloadFile(\n src: { path: string; cwd?: string },\n dst: { path: string; cwd?: string },\n opts?: { mkdirRecursive?: boolean; signal?: AbortSignal },\n ): Promise<string | null> {\n \"use step\";\n return this.withResume(\n () => this.session!.downloadFile(src, dst, opts),\n opts?.signal,\n );\n }\n\n /**\n * Write files to the filesystem of this sandbox.\n * Defaults to writing to /vercel/sandbox unless an absolute path is specified.\n * Writes files using the `vercel-sandbox` user.\n *\n * @param files - Array of files with path, content, and optional mode (permissions)\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the files are written\n *\n * @example\n * // Write an executable script\n * await sandbox.writeFiles([\n * { path: \"/usr/local/bin/myscript\", content: \"#!/bin/bash\\necho hello\", mode: 0o755 }\n * ]);\n */\n async writeFiles(\n files: {\n path: string;\n content: string | Uint8Array;\n mode?: number;\n }[],\n opts?: { signal?: AbortSignal },\n ) {\n \"use step\";\n return this.withResume(\n () => this.session!.writeFiles(files, opts),\n opts?.signal,\n );\n }\n\n /**\n * Get the public domain of a port of this sandbox.\n *\n * @param p - Port number to resolve\n * @returns A full domain (e.g. `https://subdomain.vercel.run`)\n * @throws If the port has no associated route\n */\n domain(p: number): string {\n return this.currentSession().domain(p);\n }\n\n /**\n * Stop the sandbox.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns The final session state after stopping, with optional snapshot metadata.\n */\n async stop(opts?: {\n signal?: AbortSignal;\n }): Promise<SandboxSnapshot & { snapshot?: SnapshotMetadata }> {\n \"use step\";\n if (!this.session) {\n throw new Error(\"No active session to stop.\");\n }\n const { session, sandbox, snapshot } = await this.session.stop(opts);\n if (sandbox) {\n this.sandbox = sandbox;\n }\n return Object.assign(session, { snapshot });\n }\n\n /**\n * Update the network policy for this sandbox.\n *\n * @deprecated Use {@link Sandbox.update} instead.\n *\n * @param networkPolicy - The new network policy to apply.\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the network policy is updated.\n *\n * @example\n * // Restrict to specific domains\n * await sandbox.updateNetworkPolicy({\n * allow: [\"*.npmjs.org\", \"github.com\"],\n * });\n *\n * @example\n * // Inject credentials with per-domain transformers\n * await sandbox.updateNetworkPolicy({\n * allow: {\n * \"ai-gateway.vercel.sh\": [{\n * transform: [{\n * headers: { authorization: \"Bearer ...\" }\n * }]\n * }],\n * \"*\": []\n * }\n * });\n *\n * @example\n * // Deny all network access\n * await sandbox.updateNetworkPolicy(\"deny-all\");\n */\n async updateNetworkPolicy(\n networkPolicy: NetworkPolicy,\n opts?: { signal?: AbortSignal },\n ): Promise<NetworkPolicy> {\n \"use step\";\n await this.withResume(\n () => this.session!.update({ networkPolicy: networkPolicy }, opts),\n opts?.signal,\n );\n\n return this.session!.networkPolicy!;\n }\n\n /**\n * Extend the timeout of the sandbox by the specified duration.\n *\n * This allows you to extend the lifetime of a sandbox up until the maximum\n * execution timeout for your plan.\n *\n * @param duration - The duration in milliseconds to extend the timeout by\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the timeout is extended\n *\n * @example\n * const sandbox = await Sandbox.create({ timeout: ms('10m') });\n * // Extends timeout by 5 minutes, to a total of 15 minutes.\n * await sandbox.extendTimeout(ms('5m'));\n */\n async extendTimeout(\n duration: number,\n opts?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n return this.withResume(\n () => this.session!.extendTimeout(duration, opts),\n opts?.signal,\n );\n }\n\n /**\n * Create a snapshot from this currently running sandbox. New sandboxes can\n * then be created from this snapshot using {@link Sandbox.createFromSnapshot}.\n *\n * Note: this sandbox will be stopped as part of the snapshot creation process.\n *\n * @param opts - Optional parameters.\n * @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to the Snapshot instance\n */\n async snapshot(opts?: {\n expiration?: number;\n signal?: AbortSignal;\n }): Promise<Snapshot> {\n \"use step\";\n return this.withResume(\n () => this.session!.snapshot(opts),\n opts?.signal,\n );\n }\n\n /**\n * Update the sandbox configuration.\n *\n * @param params - Fields to update.\n * @param opts - Optional abort signal.\n */\n async update(\n params: {\n persistent?: boolean;\n resources?: { vcpus?: number };\n timeout?: number;\n networkPolicy?: NetworkPolicy;\n tags?: Record<string, string>;\n snapshotExpiration?: number;\n currentSnapshotId?: string;\n },\n opts?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n let resources: { vcpus: number; memory: number } | undefined;\n if (params.resources?.vcpus) {\n resources = {\n vcpus: params.resources.vcpus,\n memory: params.resources.vcpus * 2048,\n };\n }\n\n // Update the sandbox config. This config will be used on the next session.\n const response = await client.updateSandbox({\n name: this.sandbox.name,\n projectId: this.projectId,\n persistent: params.persistent,\n resources,\n timeout: params.timeout,\n networkPolicy: params.networkPolicy,\n tags: params.tags,\n snapshotExpiration: params.snapshotExpiration,\n currentSnapshotId: params.currentSnapshotId,\n signal: opts?.signal,\n });\n this.sandbox = response.json.sandbox;\n\n // Update the current session config. This only applies to network policy.\n if (params.networkPolicy) {\n try {\n return await this.session?.update(\n { networkPolicy: params.networkPolicy },\n opts,\n );\n } catch (err) {\n if (isSandboxStoppedError(err) || isSandboxStoppingError(err)) {\n return;\n }\n throw err;\n }\n }\n }\n\n /**\n * Delete this sandbox.\n *\n * After deletion the instance becomes inert — all further API calls will\n * throw immediately.\n */\n async delete(opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n await client.deleteSandbox({\n name: this.sandbox.name,\n projectId: this.projectId,\n signal: opts?.signal,\n });\n }\n\n /**\n * List sessions (VMs) that have been created for this sandbox.\n *\n * @param params - Optional pagination parameters.\n * @returns The list of sessions and pagination metadata.\n */\n async listSessions(params?: {\n limit?: number;\n cursor?: string;\n sortOrder?: \"asc\" | \"desc\";\n signal?: AbortSignal;\n }) {\n \"use step\";\n const client = await this.ensureClient();\n const fetchPage = async (cursor?: string) => {\n const response = await client.listSessions({\n projectId: this.projectId,\n name: this.sandbox.name,\n limit: params?.limit,\n cursor,\n sortOrder: params?.sortOrder,\n signal: params?.signal,\n });\n return response.json;\n };\n const firstPage = await fetchPage(params?.cursor);\n return attachPaginator(firstPage, {\n itemsKey: \"sessions\",\n fetchNext: fetchPage,\n signal: params?.signal,\n });\n }\n\n /**\n * List snapshots that belong to this sandbox.\n *\n * @param params - Optional pagination parameters.\n * @returns The list of snapshots and pagination metadata.\n */\n async listSnapshots(params?: {\n limit?: number;\n cursor?: string;\n sortOrder?: \"asc\" | \"desc\";\n signal?: AbortSignal;\n }) {\n \"use step\";\n const client = await this.ensureClient();\n const fetchPage = async (cursor?: string) => {\n const response = await client.listSnapshots({\n projectId: this.projectId,\n name: this.sandbox.name,\n limit: params?.limit,\n cursor,\n sortOrder: params?.sortOrder,\n signal: params?.signal,\n });\n return response.json;\n };\n const firstPage = await fetchPage(params?.cursor);\n return attachPaginator(firstPage, {\n itemsKey: \"snapshots\",\n fetchNext: fetchPage,\n signal: params?.signal,\n });\n }\n}\n\n/**\n * A {@link Sandbox} that can automatically be disposed using a `await using` statement.\n *\n * @example\n * {\n * await using const sandbox = await Sandbox.create();\n * }\n * // Sandbox is automatically stopped here\n */\nclass DisposableSandbox extends Sandbox implements AsyncDisposable {\n async [Symbol.asyncDispose]() {\n await this.stop();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAmLA,SAAS,sBAAsB,KAAuB;AACpD,QAAO,eAAeA,8BAAY,IAAI,SAAS,WAAW;;AAG5D,SAAS,gBAAgB,KAAuB;AAC9C,QAAO,eAAeA,8BAAY,IAAI,SAAS,WAAW;;AAG5D,SAAS,wBAAwB,KAAuB;AACtD,QACE,eAAeA,8BACf,IAAI,SAAS,WAAW,OACvB,IAAI,MAAc,OAAO,SAAS;;AAIvC,SAAS,uBAAuB,KAAuB;AACrD,QACE,eAAeA,8BACf,IA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W_DESERIALIZE","Session","getPrivateParams","FileSystem","resources: { vcpus: number; memory: number } | undefined"],"sources":["../src/sandbox.ts"],"sourcesContent":["import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from \"@workflow/serde\";\nimport type {\n SessionMetaData,\n SandboxRouteData,\n SandboxMetaData,\n SnapshotMetadata,\n} from \"./api-client/index.js\";\nimport { APIClient } from \"./api-client/index.js\";\nimport { APIError } from \"./api-client/api-error.js\";\nimport { type Credentials, getCredentials } from \"./utils/get-credentials.js\";\nimport { getPrivateParams, type WithPrivate } from \"./utils/types.js\";\nimport type { WithFetchOptions } from \"./api-client/api-client.js\";\nimport type { RUNTIMES } from \"./constants.js\";\nimport { Session, type RunCommandParams } from \"./session.js\";\nimport type { Command, CommandFinished } from \"./command.js\";\nimport type { Snapshot } from \"./snapshot.js\";\nimport type { SandboxSnapshot } from \"./utils/sandbox-snapshot.js\";\nimport type {\n NetworkPolicy,\n NetworkPolicyKeyValueMatcher,\n NetworkPolicyMatch,\n NetworkPolicyMatcher,\n} from \"./network-policy.js\";\nimport { fromAPINetworkPolicy } from \"./utils/network-policy.js\";\nimport { attachPaginator } from \"./utils/paginator.js\";\nimport { setTimeout } from \"node:timers/promises\";\nimport { FileSystem } from \"./filesystem.js\";\n\nexport type {\n NetworkPolicy,\n NetworkPolicyKeyValueMatcher,\n NetworkPolicyMatch,\n NetworkPolicyMatcher,\n};\n\n/** @inline */\nexport interface BaseCreateSandboxParams {\n /**\n * The name of the sandbox. If omitted, a random name will be generated.\n */\n name?: string;\n /**\n * The source of the sandbox.\n *\n * Omit this parameter start a sandbox without a source.\n *\n * For git sources:\n * - `depth`: Creates shallow clones with limited commit history (minimum: 1)\n * - `revision`: Clones and checks out a specific commit, branch, or tag\n */\n source?:\n | {\n type: \"git\";\n url: string;\n depth?: number;\n revision?: string;\n }\n | {\n type: \"git\";\n url: string;\n username: string;\n password: string;\n depth?: number;\n revision?: string;\n }\n | { type: \"tarball\"; url: string };\n /**\n * Array of port numbers to expose from the sandbox. Sandboxes can\n * expose up to 4 ports.\n */\n ports?: number[];\n /**\n * Timeout in milliseconds before the sandbox auto-terminates.\n */\n timeout?: number;\n /**\n * Resources to allocate to the sandbox.\n *\n * Your sandbox will get the amount of vCPUs you specify here and\n * 2048 MB of memory per vCPU.\n */\n resources?: { vcpus: number };\n /**\n * The runtime of the sandbox, currently only `node24`, `node22`, `node26` and `python3.13` are supported.\n * If not specified, the default runtime `node24` will be used.\n */\n runtime?: RUNTIMES | (string & {});\n /**\n * Network policy to define network restrictions for the sandbox.\n * Defaults to full internet access if not specified.\n */\n networkPolicy?: NetworkPolicy;\n /**\n * Default environment variables for the sandbox.\n * These are inherited by all commands unless overridden with\n * the `env` option in `runCommand`.\n *\n * @example\n * const sandbox = await Sandbox.create({\n * env: { NODE_ENV: \"production\", API_KEY: \"secret\" },\n * });\n * // All commands will have NODE_ENV and API_KEY set\n * await sandbox.runCommand(\"node\", [\"app.js\"]);\n */\n env?: Record<string, string>;\n /**\n * Key-value tags to associate with the sandbox. Maximum 5 tags.\n * @example { env: \"staging\", team: \"infra\" }\n */\n tags?: Record<string, string>;\n\n /**\n * An AbortSignal to cancel sandbox creation.\n */\n signal?: AbortSignal;\n /**\n * Enable or disable automatic restore of the filesystem between sessions.\n */\n persistent?: boolean;\n /**\n * Default snapshot expiration in milliseconds.\n * When set, snapshots created for this sandbox will expire after this duration.\n * Use `0` for no expiration.\n */\n snapshotExpiration?: number;\n /**\n * Called when the sandbox session is resumed (e.g., after a snapshot restore).\n * Use this to re-warm caches, restore transient state, or run other setup logic.\n */\n onResume?: (sandbox: Sandbox) => Promise<void>;\n}\n\nexport type CreateSandboxParams =\n | BaseCreateSandboxParams\n | (Omit<BaseCreateSandboxParams, \"runtime\" | \"source\"> & {\n source: { type: \"snapshot\"; snapshotId: string };\n });\n\n/** @inline */\ninterface GetSandboxParams {\n /**\n * The name of the sandbox.\n */\n name: string;\n /**\n * Whether to resume an existing session. Defaults to true.\n */\n resume?: boolean;\n /**\n * An AbortSignal to cancel the operation.\n */\n signal?: AbortSignal;\n /**\n * Called when the sandbox session is resumed (e.g., after a snapshot restore).\n * Use this to re-warm caches, restore transient state, or run other setup logic.\n */\n onResume?: (sandbox: Sandbox) => Promise<void>;\n}\n\n/**\n * Extends both {@link BaseCreateSandboxParams} and {@link GetSandboxParams}\n * (minus `name`, which is required on get but optional here) so that any\n * new parameter added to either flow is picked up automatically. The\n * structural overlap on `signal` / `onResume` is intentional — both\n * interfaces declare them with identical optional types.\n * @inline\n */\ninterface GetOrCreateSandboxParams\n extends BaseCreateSandboxParams,\n Omit<GetSandboxParams, \"name\"> {\n /**\n * Called once after a sandbox is freshly created (not when an existing\n * sandbox is retrieved). Use this for one-time setup such as seeding\n * files or warming caches. The returned promise is awaited before\n * {@link Sandbox.getOrCreate} resolves.\n */\n onCreate?: (sandbox: Sandbox) => Promise<void>;\n}\n\nfunction isSandboxStoppedError(err: unknown): boolean {\n return err instanceof APIError && err.response.status === 410;\n}\n\nfunction isNotFoundError(err: unknown): boolean {\n return err instanceof APIError && err.response.status === 404;\n}\n\nfunction isSnapshotNotFoundError(err: unknown): boolean {\n return (\n err instanceof APIError &&\n err.response.status === 400 &&\n (err.json as any)?.error?.code === \"snapshot_not_found\"\n );\n}\n\nfunction isSandboxStoppingError(err: unknown): boolean {\n return (\n err instanceof APIError &&\n err.response.status === 422 &&\n (err.json as any)?.error?.code === \"sandbox_stopping\"\n );\n}\n\nfunction isSandboxSnapshottingError(err: unknown): boolean {\n return (\n err instanceof APIError &&\n err.response.status === 422 &&\n (err.json as any)?.error?.code === \"sandbox_snapshotting\"\n );\n}\n\n/**\n * Serialized representation of a Sandbox for @workflow/serde.\n * Fields `metadata` and `routes` are the original wire format from main.\n * Fields `sandboxMetadata` and `projectId` are added for named-sandboxes.\n */\nexport interface SerializedSandbox {\n metadata: SandboxSnapshot;\n routes: SandboxRouteData[];\n sandboxMetadata?: SandboxMetaData;\n projectId?: string;\n}\n\n// ============================================================================\n// Sandbox class\n// ============================================================================\n\n/**\n * A Sandbox is a persistent, isolated Linux MicroVMs to run commands in.\n * Use {@link Sandbox.create} or {@link Sandbox.get} to construct.\n * @hideconstructor\n */\nexport class Sandbox {\n private _client: APIClient | null = null;\n private readonly projectId: string;\n\n /**\n * In-flight resume promise, used to deduplicate concurrent resume calls.\n */\n private resumePromise: Promise<void> | null = null;\n\n /**\n * Internal Session instance for the current VM.\n */\n private session: Session | undefined;\n\n /**\n * Internal metadata about the sandbox.\n */\n private sandbox: SandboxMetaData;\n\n /**\n * Hook that will be executed when a new session is created during resume.\n */\n private readonly onResume?: (sandbox: Sandbox) => Promise<void>;\n\n /**\n * A `node:fs/promises`-compatible API for interacting with the sandbox filesystem.\n *\n * @example\n * const content = await sandbox.fs.readFile('/etc/hostname', 'utf8');\n * await sandbox.fs.writeFile('/tmp/hello.txt', 'Hello, world!');\n * const files = await sandbox.fs.readdir('/tmp');\n * const stats = await sandbox.fs.stat('/tmp/hello.txt');\n */\n public readonly fs: FileSystem;\n\n /**\n * Lazily resolve credentials and construct an API client.\n * @internal\n */\n private async ensureClient(): Promise<APIClient> {\n \"use step\";\n if (this._client) return this._client;\n const credentials = await getCredentials();\n this._client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n return this._client;\n }\n\n /**\n * The name of this sandbox.\n */\n public get name(): string {\n return this.sandbox.name;\n }\n\n /**\n * Routes from ports to subdomains.\n * @hidden\n */\n public get routes(): SandboxRouteData[] {\n return this.currentSession().routes;\n }\n\n /**\n * Whether the sandbox persists the state.\n */\n public get persistent(): boolean {\n return this.sandbox.persistent;\n }\n\n /**\n * The region this sandbox runs in.\n */\n public get region(): string | undefined {\n return this.sandbox.region;\n }\n\n /**\n * Number of virtual CPUs allocated.\n */\n public get vcpus(): number | undefined {\n return this.sandbox.vcpus;\n }\n\n /**\n * Memory allocated in MB.\n */\n public get memory(): number | undefined {\n return this.sandbox.memory;\n }\n\n /** Runtime identifier (e.g. \"node24\", \"python3.13\"). */\n public get runtime(): string | undefined {\n return this.sandbox.runtime;\n }\n\n /**\n * Cumulative egress bytes across all sessions.\n */\n public get totalEgressBytes(): number | undefined {\n return this.sandbox.totalEgressBytes;\n }\n\n /**\n * Cumulative ingress bytes across all sessions.\n */\n public get totalIngressBytes(): number | undefined {\n return this.sandbox.totalIngressBytes;\n }\n\n /**\n * Cumulative active CPU duration in milliseconds across all sessions.\n */\n public get totalActiveCpuDurationMs(): number | undefined {\n return this.sandbox.totalActiveCpuDurationMs;\n }\n\n /**\n * Cumulative wall-clock duration in milliseconds across all sessions.\n */\n public get totalDurationMs(): number | undefined {\n return this.sandbox.totalDurationMs;\n }\n\n /**\n * When this sandbox was last updated.\n */\n public get updatedAt(): Date {\n return new Date(this.sandbox.updatedAt);\n }\n\n /**\n * When the sandbox status was last updated.\n */\n public get statusUpdatedAt(): Date | undefined {\n return this.sandbox.statusUpdatedAt\n ? new Date(this.sandbox.statusUpdatedAt)\n : undefined;\n }\n\n /**\n * When this sandbox was created.\n */\n public get createdAt(): Date {\n return new Date(this.sandbox.createdAt);\n }\n\n /**\n * Interactive port.\n */\n public get interactivePort(): number | undefined {\n return this.currentSession().interactivePort;\n }\n\n /**\n * The status of the current session.\n */\n public get status(): SessionMetaData[\"status\"] {\n return this.currentSession().status;\n }\n\n /**\n * The default timeout of this sandbox in milliseconds.\n */\n public get timeout(): number | undefined {\n return this.sandbox.timeout;\n }\n\n /**\n * Key-value tags attached to the sandbox.\n */\n public get tags(): Record<string, string> | undefined {\n return this.sandbox.tags;\n }\n\n /**\n * The default network policy of this sandbox.\n */\n public get networkPolicy(): NetworkPolicy | undefined {\n return this.sandbox.networkPolicy\n ? fromAPINetworkPolicy(this.sandbox.networkPolicy)\n : undefined;\n }\n\n /**\n * If the session was created from a snapshot, the ID of that snapshot.\n */\n public get sourceSnapshotId(): string | undefined {\n return this.currentSession().sourceSnapshotId;\n }\n\n /**\n * The current snapshot ID of this sandbox, if any.\n */\n public get currentSnapshotId(): string | undefined {\n return this.sandbox.currentSnapshotId;\n }\n\n /**\n * The default snapshot expiration in milliseconds, if set.\n */\n public get snapshotExpiration(): number | undefined {\n return this.sandbox.snapshotExpiration;\n }\n\n /**\n * The amount of CPU used by the session. Only reported once the VM is stopped.\n */\n public get activeCpuUsageMs(): number | undefined {\n return this.currentSession().activeCpuUsageMs;\n }\n\n /**\n * The amount of network data used by the session. Only reported once the VM is stopped.\n */\n public get networkTransfer():\n | { ingress: number; egress: number }\n | undefined {\n return this.currentSession().networkTransfer;\n }\n\n /**\n * Allow to get a list of sandboxes for a team narrowed to the given params.\n * It returns both the sandboxes and the pagination metadata to allow getting\n * the next page of results.\n *\n * The returned object is async-iterable to auto-paginate through all pages:\n *\n * ```ts\n * const result = await Sandbox.list({ namePrefix: \"ci-\" });\n * for await (const sandbox of result) { ... }\n * // or: await result.toArray();\n * // or: for await (const page of result.pages()) { ... }\n * ```\n */\n static async list(\n params?: Partial<Parameters<APIClient[\"listSandboxes\"]>[0]> &\n Partial<Credentials> &\n WithFetchOptions,\n ) {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n const fetchPage = async (cursor?: string) => {\n const response = await client.listSandboxes({\n ...credentials,\n ...params,\n ...(cursor !== undefined && { cursor }),\n });\n return response.json;\n };\n const firstPage = await fetchPage(params?.cursor);\n return attachPaginator(firstPage, {\n itemsKey: \"sandboxes\",\n fetchNext: fetchPage,\n signal: params?.signal,\n });\n }\n\n /**\n * Serialize a Sandbox instance to plain data for @workflow/serde.\n *\n * @param instance - The Sandbox instance to serialize\n * @returns A plain object containing sandbox metadata and routes\n */\n static [WORKFLOW_SERIALIZE](instance: Sandbox): SerializedSandbox {\n return {\n metadata: instance.session?._sessionSnapshot!,\n routes: instance.session?.routes ?? [],\n sandboxMetadata: instance.sandbox,\n projectId: instance.projectId,\n };\n }\n\n /**\n * Deserialize a Sandbox from serialized snapshot data.\n *\n * The deserialized instance uses the serialized metadata synchronously and\n * lazily creates an API client only when methods perform API requests.\n *\n * @param data - The serialized sandbox data\n * @returns The reconstructed Sandbox instance\n */\n static [WORKFLOW_DESERIALIZE](data: SerializedSandbox): Sandbox {\n const sandbox = new Sandbox({\n sandbox: data.sandboxMetadata!,\n routes: data.routes,\n projectId: data.projectId,\n });\n if (data.metadata) {\n sandbox.session = new Session({ routes: data.routes, snapshot: data.metadata });\n }\n return sandbox;\n }\n\n /**\n * Create a new sandbox.\n *\n * @param params - Creation parameters and optional credentials.\n * @returns A promise resolving to the created {@link Sandbox}.\n * @example\n * <caption>Create a sandbox with default options</caption>\n * const sandbox = await Sandbox.create();\n *\n * @example\n * <caption>Create a sandbox and drop it in the end of the block</caption>\n * async function fn() {\n * await using const sandbox = await Sandbox.create();\n * // Sandbox automatically stopped at the end of the lexical scope\n * }\n */\n static async create(\n params?: WithPrivate<\n CreateSandboxParams | (CreateSandboxParams & Credentials)\n > &\n WithFetchOptions,\n ): Promise<Sandbox & AsyncDisposable> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n\n const privateParams = getPrivateParams(params);\n const response = await client.createSandbox({\n source: params?.source,\n projectId: credentials.projectId,\n ports: params?.ports ?? [],\n timeout: params?.timeout,\n resources: params?.resources,\n runtime: params && \"runtime\" in params ? params?.runtime : undefined,\n networkPolicy: params?.networkPolicy,\n env: params?.env,\n tags: params?.tags,\n snapshotExpiration: params?.snapshotExpiration,\n signal: params?.signal,\n name: params?.name,\n persistent: params?.persistent,\n ...privateParams,\n });\n\n return new DisposableSandbox({\n client,\n session: response.json.session,\n sandbox: response.json.sandbox,\n routes: response.json.routes,\n projectId: credentials.projectId,\n onResume: params?.onResume,\n });\n }\n\n /**\n * Retrieve an existing sandbox and resume its session.\n *\n * @param params - Get parameters and optional credentials.\n * @returns A promise resolving to the {@link Sandbox}.\n */\n static async get(\n params: WithPrivate<GetSandboxParams | (GetSandboxParams & Credentials)> &\n WithFetchOptions,\n ): Promise<Sandbox> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params.fetch,\n });\n\n const privateParams = getPrivateParams(params);\n const response = await client.getSandbox({\n name: params.name,\n projectId: credentials.projectId,\n resume: params.resume,\n signal: params.signal,\n ...privateParams,\n });\n\n const sandbox = new Sandbox({\n client,\n session: response.json.session,\n sandbox: response.json.sandbox,\n routes: response.json.routes,\n projectId: credentials.projectId,\n onResume: params.onResume,\n });\n\n if (response.json.resumed && params.onResume) {\n await params.onResume(sandbox);\n }\n\n return sandbox;\n }\n\n /**\n * Retrieve an existing named sandbox, or create a new one if none exists.\n *\n * If `name` is omitted, this always creates a new sandbox and fires\n * `onCreate`. If `name` is provided, it first tries {@link Sandbox.get};\n * on `not_found` it creates a new sandbox with that name; on\n * `snapshot_not_found` it deletes the stale named sandbox and creates\n * a fresh one with the same name.\n *\n * @param params - Get/create parameters plus an optional `onCreate` hook.\n * @returns A promise resolving to the {@link Sandbox}.\n *\n * @example\n * <caption>Idempotent named sandbox with one-time setup</caption>\n * const sandbox = await Sandbox.getOrCreate({\n * name: \"my-workspace\",\n * onCreate: async (sbx) => {\n * await sbx.writeFiles([\n * { path: \"README.md\", content: Buffer.from(\"# Hello\") },\n * ]);\n * },\n * });\n *\n * @example\n * <caption>Unnamed — always creates</caption>\n * const sandbox = await Sandbox.getOrCreate({\n * onCreate: async (sbx) => {\n * await sbx.runCommand(\"npm\", [\"install\"]);\n * },\n * });\n */\n static async getOrCreate(\n params?: WithPrivate<\n GetOrCreateSandboxParams | (GetOrCreateSandboxParams & Credentials)\n > &\n WithFetchOptions,\n ): Promise<Sandbox> {\n \"use step\";\n // No name → always create, fire onCreate.\n if (!params?.name) {\n const sandbox = await Sandbox.create(params);\n if (params?.onCreate) {\n await params.onCreate(sandbox);\n }\n return sandbox;\n }\n\n try {\n return await Sandbox.get(\n params as unknown as Parameters<typeof Sandbox.get>[0],\n );\n } catch (err) {\n if (isNotFoundError(err)) {\n // Sandbox does not exist: re-create it.\n const sandbox = await Sandbox.create(params);\n if (params.onCreate) {\n await params.onCreate(sandbox);\n }\n return sandbox;\n }\n\n if (isSnapshotNotFoundError(err)) {\n // Sandbox exists but the snapshot has expired. Delete it and create\n // a new one.\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params.fetch,\n });\n const privateParams = getPrivateParams(params);\n try {\n await client.deleteSandbox({\n name: params.name,\n projectId: credentials.projectId,\n signal: params.signal,\n ...privateParams,\n });\n } catch (deleteErr) {\n // Tolerate 404 — the named sandbox was already cleaned up by a\n // concurrent request. Propagate anything else.\n if (!isNotFoundError(deleteErr)) {\n throw deleteErr;\n }\n }\n\n const sandbox = await Sandbox.create(params);\n if (params.onCreate) {\n await params.onCreate(sandbox);\n }\n return sandbox;\n }\n\n throw err;\n }\n }\n\n /**\n * Create a new Sandbox instance.\n *\n * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.\n * @param params.routes - Port-to-subdomain mappings for exposed ports\n * @param params.sandbox - Sandbox snapshot metadata\n */\n constructor({\n client,\n routes,\n session,\n sandbox,\n projectId,\n onResume,\n }: {\n client?: APIClient;\n routes: SandboxRouteData[];\n session?: SessionMetaData;\n sandbox: SandboxMetaData;\n projectId?: string;\n onResume?: (sandbox: Sandbox) => Promise<void>;\n }) {\n this._client = client ?? null;\n if (session) {\n this.session = new Session({ client: client!, routes, session });\n }\n this.sandbox = sandbox;\n this.projectId = projectId ?? \"\";\n this.onResume = onResume;\n this.fs = new FileSystem(this);\n }\n\n /**\n * Get the current session (the running VM) for this sandbox.\n *\n * @returns The {@link Session} instance.\n */\n currentSession(): Session {\n if (!this.session) {\n throw new Error(\"No active session. Run a command or call resume first.\");\n }\n return this.session;\n }\n\n /**\n * Resume this sandbox by creating a new session via `getSandbox`.\n */\n private async resume(signal?: AbortSignal): Promise<void> {\n if (!this.resumePromise) {\n this.resumePromise = this.doResume(signal).finally(() => {\n this.resumePromise = null;\n });\n }\n return this.resumePromise;\n }\n\n private async doResume(signal?: AbortSignal): Promise<void> {\n const client = await this.ensureClient();\n const response = await client.getSandbox({\n name: this.sandbox.name,\n projectId: this.projectId,\n resume: true,\n signal,\n });\n this.session = new Session({\n client,\n routes: response.json.routes,\n session: response.json.session,\n });\n if (this.onResume && response.json.resumed) {\n await this.onResume(this);\n }\n }\n\n /**\n * Poll until the current session reaches a terminal state, then resume.\n */\n private async waitForStopAndResume(signal?: AbortSignal): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n const pollingInterval = 500;\n let status = this.session!.status;\n\n while (status === \"stopping\" || status === \"snapshotting\") {\n await setTimeout(pollingInterval, undefined, { signal });\n const poll = await client.getSession({\n sessionId: this.session!.sessionId,\n signal,\n });\n this.session = new Session({\n client,\n routes: poll.json.routes,\n session: poll.json.session,\n });\n status = poll.json.session.status;\n }\n await this.resume(signal);\n }\n\n /**\n * Execute `fn`, and if the session is stopped/stopping/snapshotting, resume and retry.\n */\n private async withResume<T>(\n fn: () => Promise<T>,\n signal?: AbortSignal,\n ): Promise<T> {\n if (!this.session) {\n await this.resume(signal);\n }\n try {\n return await fn();\n } catch (err) {\n if (isSandboxStoppedError(err)) {\n await this.resume(signal);\n return fn();\n }\n if (isSandboxStoppingError(err) || isSandboxSnapshottingError(err)) {\n await this.waitForStopAndResume(signal);\n return fn();\n }\n throw err;\n }\n }\n\n /**\n * Start executing a command in this sandbox.\n *\n * @param command - The command to execute.\n * @param args - Arguments to pass to the command.\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the command execution.\n * @returns A {@link CommandFinished} result once execution is done.\n */\n async runCommand(\n command: string,\n args?: string[],\n opts?: { signal?: AbortSignal },\n ): Promise<CommandFinished>;\n /**\n * Start executing a command in detached mode.\n *\n * @param params - The command parameters.\n * @returns A {@link Command} instance for the running command.\n */\n async runCommand(\n params: RunCommandParams & { detached: true },\n ): Promise<Command>;\n\n /**\n * Start executing a command in this sandbox.\n *\n * @param params - The command parameters.\n * @returns A {@link CommandFinished} result once execution is done.\n */\n\n async runCommand(params: RunCommandParams): Promise<CommandFinished>;\n\n async runCommand(\n commandOrParams: string | RunCommandParams,\n args?: string[],\n opts?: { signal?: AbortSignal },\n ): Promise<Command | CommandFinished> {\n \"use step\";\n const signal =\n typeof commandOrParams === \"string\"\n ? opts?.signal\n : commandOrParams.signal;\n return this.withResume(\n () => this.session!.runCommand(commandOrParams as any, args, opts),\n signal,\n );\n }\n\n /**\n * Internal helper to start a command in the sandbox.\n *\n * @param params - Command execution parameters.\n * @returns A {@link Command} or {@link CommandFinished}, depending on `detached`.\n * @internal\n */\n async getCommand(\n cmdId: string,\n opts?: { signal?: AbortSignal },\n ): Promise<Command> {\n \"use step\";\n return this.withResume(\n () => this.session!.getCommand(cmdId, opts),\n opts?.signal,\n );\n }\n\n /**\n * Create a directory in the filesystem of this sandbox.\n *\n * @param path - Path of the directory to create\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n */\n async mkDir(path: string, opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n return this.withResume(\n () => this.session!.mkDir(path, opts),\n opts?.signal,\n );\n }\n\n /**\n * Read a file from the filesystem of this sandbox as a stream.\n *\n * @param file - File to read, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found\n */\n async readFile(\n file: { path: string; cwd?: string },\n opts?: { signal?: AbortSignal },\n ): Promise<NodeJS.ReadableStream | null> {\n \"use step\";\n return this.withResume(\n () => this.session!.readFile(file, opts),\n opts?.signal,\n );\n }\n\n /**\n * Read a file from the filesystem of this sandbox as a Buffer.\n *\n * @param file - File to read, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to the file contents as a Buffer, or null if file not found\n */\n async readFileToBuffer(\n file: { path: string; cwd?: string },\n opts?: { signal?: AbortSignal },\n ): Promise<Buffer | null> {\n \"use step\";\n return this.withResume(\n () => this.session!.readFileToBuffer(file, opts),\n opts?.signal,\n );\n }\n\n /**\n * Download a file from the sandbox to the local filesystem.\n *\n * @param src - Source file on the sandbox, with path and optional cwd\n * @param dst - Destination file on the local machine, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns The absolute path to the written file, or null if the source file was not found\n */\n async downloadFile(\n src: { path: string; cwd?: string },\n dst: { path: string; cwd?: string },\n opts?: { mkdirRecursive?: boolean; signal?: AbortSignal },\n ): Promise<string | null> {\n \"use step\";\n return this.withResume(\n () => this.session!.downloadFile(src, dst, opts),\n opts?.signal,\n );\n }\n\n /**\n * Write files to the filesystem of this sandbox.\n * Defaults to writing to /vercel/sandbox unless an absolute path is specified.\n * Writes files using the `vercel-sandbox` user.\n *\n * @param files - Array of files with path, content, and optional mode (permissions)\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the files are written\n *\n * @example\n * // Write an executable script\n * await sandbox.writeFiles([\n * { path: \"/usr/local/bin/myscript\", content: \"#!/bin/bash\\necho hello\", mode: 0o755 }\n * ]);\n */\n async writeFiles(\n files: {\n path: string;\n content: string | Uint8Array;\n mode?: number;\n }[],\n opts?: { signal?: AbortSignal },\n ) {\n \"use step\";\n return this.withResume(\n () => this.session!.writeFiles(files, opts),\n opts?.signal,\n );\n }\n\n /**\n * Get the public domain of a port of this sandbox.\n *\n * @param p - Port number to resolve\n * @returns A full domain (e.g. `https://subdomain.vercel.run`)\n * @throws If the port has no associated route\n */\n domain(p: number): string {\n return this.currentSession().domain(p);\n }\n\n /**\n * Stop the sandbox.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns The final session state after stopping, with optional snapshot metadata.\n */\n async stop(opts?: {\n signal?: AbortSignal;\n }): Promise<SandboxSnapshot & { snapshot?: SnapshotMetadata }> {\n \"use step\";\n if (!this.session) {\n throw new Error(\"No active session to stop.\");\n }\n const { session, sandbox, snapshot } = await this.session.stop(opts);\n if (sandbox) {\n this.sandbox = sandbox;\n }\n return Object.assign(session, { snapshot });\n }\n\n /**\n * Update the network policy for this sandbox.\n *\n * @deprecated Use {@link Sandbox.update} instead.\n *\n * @param networkPolicy - The new network policy to apply.\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the network policy is updated.\n *\n * @example\n * // Restrict to specific domains\n * await sandbox.updateNetworkPolicy({\n * allow: [\"*.npmjs.org\", \"github.com\"],\n * });\n *\n * @example\n * // Inject credentials with per-domain transformers\n * await sandbox.updateNetworkPolicy({\n * allow: {\n * \"ai-gateway.vercel.sh\": [{\n * transform: [{\n * headers: { authorization: \"Bearer ...\" }\n * }]\n * }],\n * \"*\": []\n * }\n * });\n *\n * @example\n * // Deny all network access\n * await sandbox.updateNetworkPolicy(\"deny-all\");\n */\n async updateNetworkPolicy(\n networkPolicy: NetworkPolicy,\n opts?: { signal?: AbortSignal },\n ): Promise<NetworkPolicy> {\n \"use step\";\n await this.withResume(\n () => this.session!.update({ networkPolicy: networkPolicy }, opts),\n opts?.signal,\n );\n\n return this.session!.networkPolicy!;\n }\n\n /**\n * Extend the timeout of the sandbox by the specified duration.\n *\n * This allows you to extend the lifetime of a sandbox up until the maximum\n * execution timeout for your plan.\n *\n * @param duration - The duration in milliseconds to extend the timeout by\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the timeout is extended\n *\n * @example\n * const sandbox = await Sandbox.create({ timeout: ms('10m') });\n * // Extends timeout by 5 minutes, to a total of 15 minutes.\n * await sandbox.extendTimeout(ms('5m'));\n */\n async extendTimeout(\n duration: number,\n opts?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n return this.withResume(\n () => this.session!.extendTimeout(duration, opts),\n opts?.signal,\n );\n }\n\n /**\n * Create a snapshot from this currently running sandbox. New sandboxes can\n * then be created from this snapshot using {@link Sandbox.createFromSnapshot}.\n *\n * Note: this sandbox will be stopped as part of the snapshot creation process.\n *\n * @param opts - Optional parameters.\n * @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to the Snapshot instance\n */\n async snapshot(opts?: {\n expiration?: number;\n signal?: AbortSignal;\n }): Promise<Snapshot> {\n \"use step\";\n return this.withResume(\n () => this.session!.snapshot(opts),\n opts?.signal,\n );\n }\n\n /**\n * Update the sandbox configuration.\n *\n * @param params - Fields to update.\n * @param opts - Optional abort signal.\n */\n async update(\n params: {\n persistent?: boolean;\n resources?: { vcpus?: number };\n timeout?: number;\n networkPolicy?: NetworkPolicy;\n tags?: Record<string, string>;\n snapshotExpiration?: number;\n currentSnapshotId?: string;\n },\n opts?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n let resources: { vcpus: number; memory: number } | undefined;\n if (params.resources?.vcpus) {\n resources = {\n vcpus: params.resources.vcpus,\n memory: params.resources.vcpus * 2048,\n };\n }\n\n // Update the sandbox config. This config will be used on the next session.\n const response = await client.updateSandbox({\n name: this.sandbox.name,\n projectId: this.projectId,\n persistent: params.persistent,\n resources,\n timeout: params.timeout,\n networkPolicy: params.networkPolicy,\n tags: params.tags,\n snapshotExpiration: params.snapshotExpiration,\n currentSnapshotId: params.currentSnapshotId,\n signal: opts?.signal,\n });\n this.sandbox = response.json.sandbox;\n\n // Update the current session config. This only applies to network policy.\n if (params.networkPolicy) {\n try {\n return await this.session?.update(\n { networkPolicy: params.networkPolicy },\n opts,\n );\n } catch (err) {\n if (isSandboxStoppedError(err) || isSandboxStoppingError(err)) {\n return;\n }\n throw err;\n }\n }\n }\n\n /**\n * Delete this sandbox.\n *\n * After deletion the instance becomes inert — all further API calls will\n * throw immediately.\n */\n async delete(opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n await client.deleteSandbox({\n name: this.sandbox.name,\n projectId: this.projectId,\n signal: opts?.signal,\n });\n }\n\n /**\n * List sessions (VMs) that have been created for this sandbox.\n *\n * @param params - Optional pagination parameters.\n * @returns The list of sessions and pagination metadata.\n */\n async listSessions(params?: {\n limit?: number;\n cursor?: string;\n sortOrder?: \"asc\" | \"desc\";\n signal?: AbortSignal;\n }) {\n \"use step\";\n const client = await this.ensureClient();\n const fetchPage = async (cursor?: string) => {\n const response = await client.listSessions({\n projectId: this.projectId,\n name: this.sandbox.name,\n limit: params?.limit,\n cursor,\n sortOrder: params?.sortOrder,\n signal: params?.signal,\n });\n return response.json;\n };\n const firstPage = await fetchPage(params?.cursor);\n return attachPaginator(firstPage, {\n itemsKey: \"sessions\",\n fetchNext: fetchPage,\n signal: params?.signal,\n });\n }\n\n /**\n * List snapshots that belong to this sandbox.\n *\n * @param params - Optional pagination parameters.\n * @returns The list of snapshots and pagination metadata.\n */\n async listSnapshots(params?: {\n limit?: number;\n cursor?: string;\n sortOrder?: \"asc\" | \"desc\";\n signal?: AbortSignal;\n }) {\n \"use step\";\n const client = await this.ensureClient();\n const fetchPage = async (cursor?: string) => {\n const response = await client.listSnapshots({\n projectId: this.projectId,\n name: this.sandbox.name,\n limit: params?.limit,\n cursor,\n sortOrder: params?.sortOrder,\n signal: params?.signal,\n });\n return response.json;\n };\n const firstPage = await fetchPage(params?.cursor);\n return attachPaginator(firstPage, {\n itemsKey: \"snapshots\",\n fetchNext: fetchPage,\n signal: params?.signal,\n });\n }\n}\n\n/**\n * A {@link Sandbox} that can automatically be disposed using a `await using` statement.\n *\n * @example\n * {\n * await using const sandbox = await Sandbox.create();\n * }\n * // Sandbox is automatically stopped here\n */\nclass DisposableSandbox extends Sandbox implements AsyncDisposable {\n async [Symbol.asyncDispose]() {\n await this.stop();\n }\n}\n"],"mappings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,CAAC,EACc;;AAGlB,SAAOA,kCADW,MAAM,UAAU,QAAQ,OAAO,EACf;GAChC,UAAU;GACV,WAAW;GACX,QAAQ,QAAQ;GACjB,CAAC;;;;;;;;;;;;AAaN,IAAM,oBAAN,cAAgC,QAAmC;CACjE,OAAO,OAAO,gBAAgB;AAC5B,QAAM,KAAK,MAAM"}
|
package/dist/sandbox.d.cts
CHANGED
|
@@ -64,7 +64,7 @@ interface BaseCreateSandboxParams {
|
|
|
64
64
|
vcpus: number;
|
|
65
65
|
};
|
|
66
66
|
/**
|
|
67
|
-
* The runtime of the sandbox, currently only `node24`, `node22` and `python3.13` are supported.
|
|
67
|
+
* The runtime of the sandbox, currently only `node24`, `node22`, `node26` and `python3.13` are supported.
|
|
68
68
|
* If not specified, the default runtime `node24` will be used.
|
|
69
69
|
*/
|
|
70
70
|
runtime?: RUNTIMES | (string & {});
|
|
@@ -319,17 +319,17 @@ declare class Sandbox {
|
|
|
319
319
|
static list(params?: Partial<Parameters<APIClient["listSandboxes"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<Paginator<{
|
|
320
320
|
sandboxes: {
|
|
321
321
|
status: "aborted" | "pending" | "running" | "stopping" | "stopped" | "failed" | "snapshotting";
|
|
322
|
-
createdAt: number;
|
|
323
|
-
updatedAt: number;
|
|
324
322
|
name: string;
|
|
325
323
|
persistent: boolean;
|
|
324
|
+
createdAt: number;
|
|
325
|
+
updatedAt: number;
|
|
326
326
|
currentSessionId: string;
|
|
327
|
-
|
|
328
|
-
vcpus?: number | undefined;
|
|
327
|
+
tags?: Record<string, string> | undefined;
|
|
329
328
|
region?: string | undefined;
|
|
329
|
+
vcpus?: number | undefined;
|
|
330
|
+
memory?: number | undefined;
|
|
330
331
|
runtime?: string | undefined;
|
|
331
332
|
timeout?: number | undefined;
|
|
332
|
-
cwd?: string | undefined;
|
|
333
333
|
networkPolicy?: zod0.objectInputType<{
|
|
334
334
|
mode: zod0.ZodLiteral<"allow-all">;
|
|
335
335
|
}, zod0.ZodTypeAny, "passthrough"> | zod0.objectInputType<{
|
|
@@ -523,6 +523,8 @@ declare class Sandbox {
|
|
|
523
523
|
}>>;
|
|
524
524
|
}, "strip", zod0.ZodTypeAny, {
|
|
525
525
|
domain: string;
|
|
526
|
+
headers?: Record<string, string> | undefined;
|
|
527
|
+
headerNames?: string[] | undefined;
|
|
526
528
|
match?: {
|
|
527
529
|
path?: {
|
|
528
530
|
exact?: string | undefined;
|
|
@@ -555,10 +557,10 @@ declare class Sandbox {
|
|
|
555
557
|
} | undefined;
|
|
556
558
|
}[] | undefined;
|
|
557
559
|
} | undefined;
|
|
558
|
-
headers?: Record<string, string> | undefined;
|
|
559
|
-
headerNames?: string[] | undefined;
|
|
560
560
|
}, {
|
|
561
561
|
domain: string;
|
|
562
|
+
headers?: Record<string, string> | undefined;
|
|
563
|
+
headerNames?: string[] | undefined;
|
|
562
564
|
match?: {
|
|
563
565
|
path?: {
|
|
564
566
|
exact?: string | undefined;
|
|
@@ -591,8 +593,6 @@ declare class Sandbox {
|
|
|
591
593
|
} | undefined;
|
|
592
594
|
}[] | undefined;
|
|
593
595
|
} | undefined;
|
|
594
|
-
headers?: Record<string, string> | undefined;
|
|
595
|
-
headerNames?: string[] | undefined;
|
|
596
596
|
}>, "many">>;
|
|
597
597
|
forwardRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
|
|
598
598
|
domain: zod0.ZodString;
|
|
@@ -847,12 +847,12 @@ declare class Sandbox {
|
|
|
847
847
|
} | undefined;
|
|
848
848
|
}>, "many">>;
|
|
849
849
|
}, zod0.ZodTypeAny, "passthrough"> | undefined;
|
|
850
|
-
tags?: Record<string, string> | undefined;
|
|
851
850
|
totalEgressBytes?: number | undefined;
|
|
852
851
|
totalIngressBytes?: number | undefined;
|
|
853
852
|
totalActiveCpuDurationMs?: number | undefined;
|
|
854
853
|
totalDurationMs?: number | undefined;
|
|
855
854
|
currentSnapshotId?: string | undefined;
|
|
855
|
+
cwd?: string | undefined;
|
|
856
856
|
statusUpdatedAt?: number | undefined;
|
|
857
857
|
snapshotExpiration?: number | undefined;
|
|
858
858
|
}[];
|
|
@@ -1449,6 +1449,8 @@ declare class Sandbox {
|
|
|
1449
1449
|
}>>;
|
|
1450
1450
|
}, "strip", zod0.ZodTypeAny, {
|
|
1451
1451
|
domain: string;
|
|
1452
|
+
headers?: Record<string, string> | undefined;
|
|
1453
|
+
headerNames?: string[] | undefined;
|
|
1452
1454
|
match?: {
|
|
1453
1455
|
path?: {
|
|
1454
1456
|
exact?: string | undefined;
|
|
@@ -1481,10 +1483,10 @@ declare class Sandbox {
|
|
|
1481
1483
|
} | undefined;
|
|
1482
1484
|
}[] | undefined;
|
|
1483
1485
|
} | undefined;
|
|
1484
|
-
headers?: Record<string, string> | undefined;
|
|
1485
|
-
headerNames?: string[] | undefined;
|
|
1486
1486
|
}, {
|
|
1487
1487
|
domain: string;
|
|
1488
|
+
headers?: Record<string, string> | undefined;
|
|
1489
|
+
headerNames?: string[] | undefined;
|
|
1488
1490
|
match?: {
|
|
1489
1491
|
path?: {
|
|
1490
1492
|
exact?: string | undefined;
|
|
@@ -1517,8 +1519,6 @@ declare class Sandbox {
|
|
|
1517
1519
|
} | undefined;
|
|
1518
1520
|
}[] | undefined;
|
|
1519
1521
|
} | undefined;
|
|
1520
|
-
headers?: Record<string, string> | undefined;
|
|
1521
|
-
headerNames?: string[] | undefined;
|
|
1522
1522
|
}>, "many">>;
|
|
1523
1523
|
forwardRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
|
|
1524
1524
|
domain: zod0.ZodString;
|
|
@@ -1961,6 +1961,8 @@ declare class Sandbox {
|
|
|
1961
1961
|
}>>;
|
|
1962
1962
|
}, "strip", zod0.ZodTypeAny, {
|
|
1963
1963
|
domain: string;
|
|
1964
|
+
headers?: Record<string, string> | undefined;
|
|
1965
|
+
headerNames?: string[] | undefined;
|
|
1964
1966
|
match?: {
|
|
1965
1967
|
path?: {
|
|
1966
1968
|
exact?: string | undefined;
|
|
@@ -1993,10 +1995,10 @@ declare class Sandbox {
|
|
|
1993
1995
|
} | undefined;
|
|
1994
1996
|
}[] | undefined;
|
|
1995
1997
|
} | undefined;
|
|
1996
|
-
headers?: Record<string, string> | undefined;
|
|
1997
|
-
headerNames?: string[] | undefined;
|
|
1998
1998
|
}, {
|
|
1999
1999
|
domain: string;
|
|
2000
|
+
headers?: Record<string, string> | undefined;
|
|
2001
|
+
headerNames?: string[] | undefined;
|
|
2000
2002
|
match?: {
|
|
2001
2003
|
path?: {
|
|
2002
2004
|
exact?: string | undefined;
|
|
@@ -2029,8 +2031,6 @@ declare class Sandbox {
|
|
|
2029
2031
|
} | undefined;
|
|
2030
2032
|
}[] | undefined;
|
|
2031
2033
|
} | undefined;
|
|
2032
|
-
headers?: Record<string, string> | undefined;
|
|
2033
|
-
headerNames?: string[] | undefined;
|
|
2034
2034
|
}>, "many">>;
|
|
2035
2035
|
forwardRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
|
|
2036
2036
|
domain: zod0.ZodString;
|
|
@@ -2473,6 +2473,8 @@ declare class Sandbox {
|
|
|
2473
2473
|
}>>;
|
|
2474
2474
|
}, "strip", zod0.ZodTypeAny, {
|
|
2475
2475
|
domain: string;
|
|
2476
|
+
headers?: Record<string, string> | undefined;
|
|
2477
|
+
headerNames?: string[] | undefined;
|
|
2476
2478
|
match?: {
|
|
2477
2479
|
path?: {
|
|
2478
2480
|
exact?: string | undefined;
|
|
@@ -2505,10 +2507,10 @@ declare class Sandbox {
|
|
|
2505
2507
|
} | undefined;
|
|
2506
2508
|
}[] | undefined;
|
|
2507
2509
|
} | undefined;
|
|
2508
|
-
headers?: Record<string, string> | undefined;
|
|
2509
|
-
headerNames?: string[] | undefined;
|
|
2510
2510
|
}, {
|
|
2511
2511
|
domain: string;
|
|
2512
|
+
headers?: Record<string, string> | undefined;
|
|
2513
|
+
headerNames?: string[] | undefined;
|
|
2512
2514
|
match?: {
|
|
2513
2515
|
path?: {
|
|
2514
2516
|
exact?: string | undefined;
|
|
@@ -2541,8 +2543,6 @@ declare class Sandbox {
|
|
|
2541
2543
|
} | undefined;
|
|
2542
2544
|
}[] | undefined;
|
|
2543
2545
|
} | undefined;
|
|
2544
|
-
headers?: Record<string, string> | undefined;
|
|
2545
|
-
headerNames?: string[] | undefined;
|
|
2546
2546
|
}>, "many">>;
|
|
2547
2547
|
forwardRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
|
|
2548
2548
|
domain: zod0.ZodString;
|
|
@@ -2828,10 +2828,10 @@ declare class Sandbox {
|
|
|
2828
2828
|
};
|
|
2829
2829
|
snapshots: {
|
|
2830
2830
|
status: "failed" | "created" | "deleted";
|
|
2831
|
-
id: string;
|
|
2832
2831
|
region: string;
|
|
2833
2832
|
createdAt: number;
|
|
2834
2833
|
updatedAt: number;
|
|
2834
|
+
id: string;
|
|
2835
2835
|
sourceSessionId: string;
|
|
2836
2836
|
sizeBytes: number;
|
|
2837
2837
|
expiresAt?: number | undefined;
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ interface BaseCreateSandboxParams {
|
|
|
65
65
|
vcpus: number;
|
|
66
66
|
};
|
|
67
67
|
/**
|
|
68
|
-
* The runtime of the sandbox, currently only `node24`, `node22` and `python3.13` are supported.
|
|
68
|
+
* The runtime of the sandbox, currently only `node24`, `node22`, `node26` and `python3.13` are supported.
|
|
69
69
|
* If not specified, the default runtime `node24` will be used.
|
|
70
70
|
*/
|
|
71
71
|
runtime?: RUNTIMES | (string & {});
|
|
@@ -320,17 +320,17 @@ declare class Sandbox {
|
|
|
320
320
|
static list(params?: Partial<Parameters<APIClient["listSandboxes"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<Paginator<{
|
|
321
321
|
sandboxes: {
|
|
322
322
|
status: "aborted" | "pending" | "running" | "stopping" | "stopped" | "failed" | "snapshotting";
|
|
323
|
-
createdAt: number;
|
|
324
|
-
updatedAt: number;
|
|
325
323
|
name: string;
|
|
326
324
|
persistent: boolean;
|
|
325
|
+
createdAt: number;
|
|
326
|
+
updatedAt: number;
|
|
327
327
|
currentSessionId: string;
|
|
328
|
-
|
|
329
|
-
vcpus?: number | undefined;
|
|
328
|
+
tags?: Record<string, string> | undefined;
|
|
330
329
|
region?: string | undefined;
|
|
330
|
+
vcpus?: number | undefined;
|
|
331
|
+
memory?: number | undefined;
|
|
331
332
|
runtime?: string | undefined;
|
|
332
333
|
timeout?: number | undefined;
|
|
333
|
-
cwd?: string | undefined;
|
|
334
334
|
networkPolicy?: zod0.objectInputType<{
|
|
335
335
|
mode: zod0.ZodLiteral<"allow-all">;
|
|
336
336
|
}, zod0.ZodTypeAny, "passthrough"> | zod0.objectInputType<{
|
|
@@ -524,6 +524,8 @@ declare class Sandbox {
|
|
|
524
524
|
}>>;
|
|
525
525
|
}, "strip", zod0.ZodTypeAny, {
|
|
526
526
|
domain: string;
|
|
527
|
+
headers?: Record<string, string> | undefined;
|
|
528
|
+
headerNames?: string[] | undefined;
|
|
527
529
|
match?: {
|
|
528
530
|
path?: {
|
|
529
531
|
exact?: string | undefined;
|
|
@@ -556,10 +558,10 @@ declare class Sandbox {
|
|
|
556
558
|
} | undefined;
|
|
557
559
|
}[] | undefined;
|
|
558
560
|
} | undefined;
|
|
559
|
-
headers?: Record<string, string> | undefined;
|
|
560
|
-
headerNames?: string[] | undefined;
|
|
561
561
|
}, {
|
|
562
562
|
domain: string;
|
|
563
|
+
headers?: Record<string, string> | undefined;
|
|
564
|
+
headerNames?: string[] | undefined;
|
|
563
565
|
match?: {
|
|
564
566
|
path?: {
|
|
565
567
|
exact?: string | undefined;
|
|
@@ -592,8 +594,6 @@ declare class Sandbox {
|
|
|
592
594
|
} | undefined;
|
|
593
595
|
}[] | undefined;
|
|
594
596
|
} | undefined;
|
|
595
|
-
headers?: Record<string, string> | undefined;
|
|
596
|
-
headerNames?: string[] | undefined;
|
|
597
597
|
}>, "many">>;
|
|
598
598
|
forwardRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
|
|
599
599
|
domain: zod0.ZodString;
|
|
@@ -848,12 +848,12 @@ declare class Sandbox {
|
|
|
848
848
|
} | undefined;
|
|
849
849
|
}>, "many">>;
|
|
850
850
|
}, zod0.ZodTypeAny, "passthrough"> | undefined;
|
|
851
|
-
tags?: Record<string, string> | undefined;
|
|
852
851
|
totalEgressBytes?: number | undefined;
|
|
853
852
|
totalIngressBytes?: number | undefined;
|
|
854
853
|
totalActiveCpuDurationMs?: number | undefined;
|
|
855
854
|
totalDurationMs?: number | undefined;
|
|
856
855
|
currentSnapshotId?: string | undefined;
|
|
856
|
+
cwd?: string | undefined;
|
|
857
857
|
statusUpdatedAt?: number | undefined;
|
|
858
858
|
snapshotExpiration?: number | undefined;
|
|
859
859
|
}[];
|
|
@@ -1450,6 +1450,8 @@ declare class Sandbox {
|
|
|
1450
1450
|
}>>;
|
|
1451
1451
|
}, "strip", zod0.ZodTypeAny, {
|
|
1452
1452
|
domain: string;
|
|
1453
|
+
headers?: Record<string, string> | undefined;
|
|
1454
|
+
headerNames?: string[] | undefined;
|
|
1453
1455
|
match?: {
|
|
1454
1456
|
path?: {
|
|
1455
1457
|
exact?: string | undefined;
|
|
@@ -1482,10 +1484,10 @@ declare class Sandbox {
|
|
|
1482
1484
|
} | undefined;
|
|
1483
1485
|
}[] | undefined;
|
|
1484
1486
|
} | undefined;
|
|
1485
|
-
headers?: Record<string, string> | undefined;
|
|
1486
|
-
headerNames?: string[] | undefined;
|
|
1487
1487
|
}, {
|
|
1488
1488
|
domain: string;
|
|
1489
|
+
headers?: Record<string, string> | undefined;
|
|
1490
|
+
headerNames?: string[] | undefined;
|
|
1489
1491
|
match?: {
|
|
1490
1492
|
path?: {
|
|
1491
1493
|
exact?: string | undefined;
|
|
@@ -1518,8 +1520,6 @@ declare class Sandbox {
|
|
|
1518
1520
|
} | undefined;
|
|
1519
1521
|
}[] | undefined;
|
|
1520
1522
|
} | undefined;
|
|
1521
|
-
headers?: Record<string, string> | undefined;
|
|
1522
|
-
headerNames?: string[] | undefined;
|
|
1523
1523
|
}>, "many">>;
|
|
1524
1524
|
forwardRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
|
|
1525
1525
|
domain: zod0.ZodString;
|
|
@@ -1962,6 +1962,8 @@ declare class Sandbox {
|
|
|
1962
1962
|
}>>;
|
|
1963
1963
|
}, "strip", zod0.ZodTypeAny, {
|
|
1964
1964
|
domain: string;
|
|
1965
|
+
headers?: Record<string, string> | undefined;
|
|
1966
|
+
headerNames?: string[] | undefined;
|
|
1965
1967
|
match?: {
|
|
1966
1968
|
path?: {
|
|
1967
1969
|
exact?: string | undefined;
|
|
@@ -1994,10 +1996,10 @@ declare class Sandbox {
|
|
|
1994
1996
|
} | undefined;
|
|
1995
1997
|
}[] | undefined;
|
|
1996
1998
|
} | undefined;
|
|
1997
|
-
headers?: Record<string, string> | undefined;
|
|
1998
|
-
headerNames?: string[] | undefined;
|
|
1999
1999
|
}, {
|
|
2000
2000
|
domain: string;
|
|
2001
|
+
headers?: Record<string, string> | undefined;
|
|
2002
|
+
headerNames?: string[] | undefined;
|
|
2001
2003
|
match?: {
|
|
2002
2004
|
path?: {
|
|
2003
2005
|
exact?: string | undefined;
|
|
@@ -2030,8 +2032,6 @@ declare class Sandbox {
|
|
|
2030
2032
|
} | undefined;
|
|
2031
2033
|
}[] | undefined;
|
|
2032
2034
|
} | undefined;
|
|
2033
|
-
headers?: Record<string, string> | undefined;
|
|
2034
|
-
headerNames?: string[] | undefined;
|
|
2035
2035
|
}>, "many">>;
|
|
2036
2036
|
forwardRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
|
|
2037
2037
|
domain: zod0.ZodString;
|
|
@@ -2474,6 +2474,8 @@ declare class Sandbox {
|
|
|
2474
2474
|
}>>;
|
|
2475
2475
|
}, "strip", zod0.ZodTypeAny, {
|
|
2476
2476
|
domain: string;
|
|
2477
|
+
headers?: Record<string, string> | undefined;
|
|
2478
|
+
headerNames?: string[] | undefined;
|
|
2477
2479
|
match?: {
|
|
2478
2480
|
path?: {
|
|
2479
2481
|
exact?: string | undefined;
|
|
@@ -2506,10 +2508,10 @@ declare class Sandbox {
|
|
|
2506
2508
|
} | undefined;
|
|
2507
2509
|
}[] | undefined;
|
|
2508
2510
|
} | undefined;
|
|
2509
|
-
headers?: Record<string, string> | undefined;
|
|
2510
|
-
headerNames?: string[] | undefined;
|
|
2511
2511
|
}, {
|
|
2512
2512
|
domain: string;
|
|
2513
|
+
headers?: Record<string, string> | undefined;
|
|
2514
|
+
headerNames?: string[] | undefined;
|
|
2513
2515
|
match?: {
|
|
2514
2516
|
path?: {
|
|
2515
2517
|
exact?: string | undefined;
|
|
@@ -2542,8 +2544,6 @@ declare class Sandbox {
|
|
|
2542
2544
|
} | undefined;
|
|
2543
2545
|
}[] | undefined;
|
|
2544
2546
|
} | undefined;
|
|
2545
|
-
headers?: Record<string, string> | undefined;
|
|
2546
|
-
headerNames?: string[] | undefined;
|
|
2547
2547
|
}>, "many">>;
|
|
2548
2548
|
forwardRules: zod0.ZodOptional<zod0.ZodArray<zod0.ZodObject<{
|
|
2549
2549
|
domain: zod0.ZodString;
|
|
@@ -2829,10 +2829,10 @@ declare class Sandbox {
|
|
|
2829
2829
|
};
|
|
2830
2830
|
snapshots: {
|
|
2831
2831
|
status: "failed" | "created" | "deleted";
|
|
2832
|
-
id: string;
|
|
2833
2832
|
region: string;
|
|
2834
2833
|
createdAt: number;
|
|
2835
2834
|
updatedAt: number;
|
|
2835
|
+
id: string;
|
|
2836
2836
|
sourceSessionId: string;
|
|
2837
2837
|
sizeBytes: number;
|
|
2838
2838
|
expiresAt?: number | undefined;
|