Skip to content

Latest commit

 

History

History
1440 lines (1097 loc) · 104 KB

File metadata and controls

1440 lines (1097 loc) · 104 KB

Sandboxes

Overview

Available Operations

listSandboxes

Retrieves a paginated list of sandboxes belonging to a specific project. Results can be filtered by creation time using the since and until parameters.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.listSandboxes({
    project: "prj_abc123",
    limit: 20,
    since: 1540095775941,
    until: 1540095775951,
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesListSandboxes } from "@vercel/sdk/funcs/sandboxesListSandboxes.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesListSandboxes(vercel, {
    project: "prj_abc123",
    limit: 20,
    since: 1540095775941,
    until: 1540095775951,
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesListSandboxes failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.ListSandboxesRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.ListSandboxesResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

listSnapshots

Retrieves a paginated list of snapshots for a specific project.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.listSnapshots({
    project: "prj_abc123",
    limit: 20,
    since: 1540095775941,
    until: 1540095775951,
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesListSnapshots } from "@vercel/sdk/funcs/sandboxesListSnapshots.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesListSnapshots(vercel, {
    project: "prj_abc123",
    limit: 20,
    since: 1540095775941,
    until: 1540095775951,
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesListSnapshots failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.ListSnapshotsRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.ListSnapshotsResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

getSandbox

Retrieves detailed information about a specific sandbox, including its current status, resource configuration, and exposed routes.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.getSandbox({
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesGetSandbox } from "@vercel/sdk/funcs/sandboxesGetSandbox.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesGetSandbox(vercel, {
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesGetSandbox failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.GetSandboxRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.GetSandboxResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

listCommands

Retrieves a list of all commands that have been executed in a sandbox, including their current status, exit codes, and execution times, ordered from the most recent to the oldest.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.listCommands({
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesListCommands } from "@vercel/sdk/funcs/sandboxesListCommands.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesListCommands(vercel, {
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesListCommands failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.ListCommandsRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.ListCommandsResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

runCommand

Executes a shell command inside a running sandbox. The command runs asynchronously and returns immediately with a command ID that can be used to track its progress and retrieve its output. Optionally, use the wait parameter to stream the command status until completion.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.runCommand({
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      command: "npm",
      args: [
        "install",
        "--save",
        "lodash",
      ],
      cwd: "/home/vercel-sandbox",
      env: {
        "NODE_ENV": "production",
        "DEBUG": "true",
      },
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesRunCommand } from "@vercel/sdk/funcs/sandboxesRunCommand.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesRunCommand(vercel, {
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      command: "npm",
      args: [
        "install",
        "--save",
        "lodash",
      ],
      cwd: "/home/vercel-sandbox",
      env: {
        "NODE_ENV": "production",
        "DEBUG": "true",
      },
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesRunCommand failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.RunCommandRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.RunCommandResponse>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

killCommand

Sends a signal to terminate a running command in a sandbox. The signal can be used to gracefully stop (SIGTERM) or forcefully kill (SIGKILL) the process. The command must still be running for this operation to succeed.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.killCommand({
    cmdId: "cmd_abc123",
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      signal: 15,
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesKillCommand } from "@vercel/sdk/funcs/sandboxesKillCommand.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesKillCommand(vercel, {
    cmdId: "cmd_abc123",
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      signal: 15,
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesKillCommand failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.KillCommandRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.KillCommandResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

stopSandbox

Stops a running sandbox and releases its allocated resources. All running processes within the sandbox will be terminated. This action cannot be undone. A stopped sandbox cannot be restarted.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.stopSandbox({
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesStopSandbox } from "@vercel/sdk/funcs/sandboxesStopSandbox.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesStopSandbox(vercel, {
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesStopSandbox failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.StopSandboxRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.StopSandboxResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

extendSandboxTimeout

Extends the maximum execution time of a running sandbox. The sandbox must be active and able to accept commands. The total timeout cannot exceed the maximum allowed limit for your account.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.extendSandboxTimeout({
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      duration: 300000,
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesExtendSandboxTimeout } from "@vercel/sdk/funcs/sandboxesExtendSandboxTimeout.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesExtendSandboxTimeout(vercel, {
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      duration: 300000,
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesExtendSandboxTimeout failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.ExtendSandboxTimeoutRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.ExtendSandboxTimeoutResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

updateNetworkPolicy

Replaces the network access policy of a running sandbox. Use this to control which external hosts the sandbox can communicate with. This is a full replacement. Any previously configured network rules will be overwritten.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.updateNetworkPolicy({
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      mode: "custom",
      allowedDomains: [
        "api.github.com",
        "*.npmjs.org",
      ],
      allowedCIDRs: [
        "35.192.0.0/12",
        "104.16.0.0/12",
      ],
      deniedCIDRs: [
        "35.192.0.0/12",
      ],
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesUpdateNetworkPolicy } from "@vercel/sdk/funcs/sandboxesUpdateNetworkPolicy.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesUpdateNetworkPolicy(vercel, {
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      mode: "custom",
      allowedDomains: [
        "api.github.com",
        "*.npmjs.org",
      ],
      allowedCIDRs: [
        "35.192.0.0/12",
        "104.16.0.0/12",
      ],
      deniedCIDRs: [
        "35.192.0.0/12",
      ],
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesUpdateNetworkPolicy failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.UpdateNetworkPolicyRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.UpdateNetworkPolicyResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

getCommand

Retrieves the current status and details of a command executed in a sandbox. Use the wait parameter to block until the command finishes execution.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.getCommand({
    sandboxId: "sbx_abc123",
    cmdId: "cmd_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesGetCommand } from "@vercel/sdk/funcs/sandboxesGetCommand.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesGetCommand(vercel, {
    sandboxId: "sbx_abc123",
    cmdId: "cmd_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesGetCommand failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.GetCommandRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.GetCommandResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

getCommandLogs

Streams the output of a command in real-time using newline-delimited JSON (ND-JSON). Each entry includes the output data and stream type. Stream types include stdout, stderr, and error (for stream failures).

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.getCommandLogs({
    sandboxId: "sbx_abc123",
    cmdId: "cmd_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  for await (const event of result) {
    // Handle the event
    console.log(event);
  }
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesGetCommandLogs } from "@vercel/sdk/funcs/sandboxesGetCommandLogs.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesGetCommandLogs(vercel, {
    sandboxId: "sbx_abc123",
    cmdId: "cmd_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    for await (const event of result) {
    // Handle the event
    console.log(event);
  }
  } else {
    console.log("sandboxesGetCommandLogs failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.GetCommandLogsRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<JsonLStream<models.GetCommandLogsResponseBody>>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

readFile

Downloads the contents of a file from a sandbox's filesystem. The file content is returned as a binary stream with appropriate Content-Disposition headers for file download.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.readFile({
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      cwd: "/home/vercel-sandbox",
      path: "dist/agent-output.md",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesReadFile } from "@vercel/sdk/funcs/sandboxesReadFile.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesReadFile(vercel, {
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      cwd: "/home/vercel-sandbox",
      path: "dist/agent-output.md",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesReadFile failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.ReadFileRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<ReadableStream>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

createDirectory

Creates a new directory in a sandbox's filesystem. By default, parent directories are created recursively if they don't exist (similar to mkdir -p).

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.createDirectory({
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      cwd: "/home/vercel-sandbox",
      path: "src/components",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesCreateDirectory } from "@vercel/sdk/funcs/sandboxesCreateDirectory.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesCreateDirectory(vercel, {
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      cwd: "/home/vercel-sandbox",
      path: "src/components",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesCreateDirectory failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.CreateDirectoryRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.CreateDirectoryResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

writeFiles

Uploads and extracts files to a sandbox's filesystem. Files must be uploaded as a gzipped tarball (.tar.gz) with the Content-Type header set to application/gzip. The tarball contents are extracted to the sandbox's working directory, or to a custom directory specified via the x-cwd header.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.writeFiles({
    xCwd: "/home/vercel-sandbox",
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesWriteFiles } from "@vercel/sdk/funcs/sandboxesWriteFiles.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesWriteFiles(vercel, {
    xCwd: "/home/vercel-sandbox",
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesWriteFiles failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.WriteFilesRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.WriteFilesResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

getSnapshot

Retrieves detailed information about a specific snapshot, including its creation time, size, expiration date, and the source sandbox it was created from.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.getSnapshot({
    snapshotId: "snap_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesGetSnapshot } from "@vercel/sdk/funcs/sandboxesGetSnapshot.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesGetSnapshot(vercel, {
    snapshotId: "snap_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesGetSnapshot failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.GetSnapshotRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.GetSnapshotResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

deleteSnapshot

Permanently deletes a snapshot and frees its associated storage. This action cannot be undone. After deletion, the snapshot can no longer be used to create new sandboxes.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.deleteSnapshot({
    snapshotId: "snap_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesDeleteSnapshot } from "@vercel/sdk/funcs/sandboxesDeleteSnapshot.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesDeleteSnapshot(vercel, {
    snapshotId: "snap_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesDeleteSnapshot failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.DeleteSnapshotRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.DeleteSnapshotResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

createSnapshot

Creates a point-in-time snapshot of a running sandbox's filesystem. Snapshots can be used to quickly restore a sandbox to a previous state or to create new sandboxes with pre-configured environments. The sandbox must be running and able to accept commands for a snapshot to be created. The sandbox will be terminated after the snapshot is created.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.sandboxes.createSnapshot({
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { sandboxesCreateSnapshot } from "@vercel/sdk/funcs/sandboxesCreateSnapshot.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await sandboxesCreateSnapshot(vercel, {
    sandboxId: "sbx_abc123",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("sandboxesCreateSnapshot failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.CreateSnapshotRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.CreateSnapshotResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*