Skip to content

SDK quickstart

Sign up for BoxCompute, install an official SDK, run a command in a Sandbox, and clean up.

Updated View as Markdown

Use the official SDK for application integrations. It handles authentication, typed API responses, binary file transfer, timeouts, cancellation, and structured errors for the public v2 API.

If you want to use BoxCompute from a terminal or a local coding agent, follow the CLI quickstart. For direct HTTP clients and generated tooling, see the HTTP API reference.

1. Sign up and create an API key

Some requests wait for sign-up review before a link is sent.

Sign up, confirm your email, and sign in to the BoxCompute app. Then open API keys, create a key, and include workspace:create, sandbox:read, sandbox:create, sandbox:execute, and sandbox:delete.

On your first app visit, answer Have you used AI before? with Not really, ChatGPT or Claude, or I code with AI. The answer tailors the first tasks and the agent’s explanations; the app creates your initial workspace without asking you to name it. The coding path can connect GitHub and select a repository. To work with your own tools instead, choose Just want the computer? to open Computers; the app remembers that as your home. Either route can use this SDK walkthrough. See app agent workflows.

Copy the bc_live_... secret immediately—it is displayed only once—and store it in your secret manager. For this local walkthrough:

read -rsp 'BoxCompute API key: ' BOXCOMPUTE_API_KEY && echo
export BOXCOMPUTE_API_KEY

See API keys for scope and revocation details. Never put this server-side key in a browser or mobile application.

2. Install an SDK

npm install @boxcompute/sdk
npm install --save-dev tsx
python -m pip install boxcompute

Both packages use https://api.boxcompute.ai by default. You do not need to build route URLs or authorization headers yourself.

New Sandboxes are VM-only: omit vmSandbox or send true. Sending false returns 400 INVALID_REQUEST; there is no fallback to gVisor. Operator-selected cooperative SSH and the selected-TCP access routes are not exposed by the current SDKs. One-hour VM browser previews are previews.create and previews.close from SDK 0.4.0; see the preview contract.

3. Create, execute, and clean up

The examples use a workspace named SDK quickstart, creating it on the first run. A workspace created through the API is personal, so the VM counts against your own limits rather than an organization’s. Workspaces are persistent parents and are not deleted. Each example creates one Sandbox and deletes that exact instance in a finally block.

Create quickstart.ts:

import { randomUUID } from "node:crypto";
import { BoxCompute } from "@boxcompute/sdk";

const apiKey = process.env.BOXCOMPUTE_API_KEY;
if (!apiKey) throw new Error("BOXCOMPUTE_API_KEY is required");

const boxcompute = new BoxCompute({ apiKey });
const workspaces = await boxcompute.workspaces.list();
const existingWorkspace = workspaces.find((item) => item.name === "SDK quickstart");
const workspace = existingWorkspace ?? await boxcompute.workspaces.create({
  name: "SDK quickstart",
  idempotencyKey: "sdk-quickstart-workspace-v1",
});

const sandbox = await boxcompute.sandboxes.create({
  workspaceId: workspace.id,
  name: "SDK quickstart",
  idempotencyKey: randomUUID(),
});

try {
  const result = await boxcompute.sandboxes.execute(sandbox.id, {
    argv: ["python3", "-c", "print(sum(range(100000)))"],
    cwd: "/workspace",
    timeoutSeconds: 120,
    maxOutputBytes: 262_144,
  });
  console.log(result.stdout);
  if (result.stderr) console.error(result.stderr);
  process.exitCode = result.exitCode;
} finally {
  await boxcompute.sandboxes.delete(sandbox.id);
}

Run it with npx tsx quickstart.ts.

Create quickstart.py:

import os
import sys
import uuid

from boxcompute import BoxCompute

with BoxCompute(api_key=os.environ["BOXCOMPUTE_API_KEY"]) as boxcompute:
    workspace = next(
        (item for item in boxcompute.workspaces.list() if item.name == "SDK quickstart"),
        None,
    ) or boxcompute.workspaces.create(
        name="SDK quickstart",
        idempotency_key="sdk-quickstart-workspace-v1",
    )
    sandbox = boxcompute.sandboxes.create(
        workspace_id=workspace.id,
        name="SDK quickstart",
        idempotency_key=str(uuid.uuid4()),
    )
    try:
        result = boxcompute.sandboxes.execute(
            sandbox.id,
            argv=["python3", "-c", "print(sum(range(100000)))"],
            cwd="/workspace",
        )
        print(result.stdout, end="")
        if result.stderr:
            print(result.stderr, end="", file=sys.stderr)
    finally:
        boxcompute.sandboxes.delete(sandbox.id)

Run it with python quickstart.py.

execute waits for completion and returns stdout, stderr, exit status, timeout, and truncation fields. A non-zero command exit is still a successful API response, so inspect exitCode / exit_code rather than treating it as a transport error.

For commands that must remain observable across an interrupted connection, use durable operations.

Next steps

Navigation

Type to search…

↑↓ navigate↵ selectEsc close