> For the complete documentation index, see [llms.txt](https://docs.computesdk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.computesdk.com/interfaces/sdk/reference.md). Agents can also search and read this documentation through its [MCP server](https://docs.computesdk.com/~gitbook/mcp).

# SDK reference

```typescript
import { compute } from 'computesdk';

const sandbox = await compute.instances.create({ size: 'small' });
try {
  console.log((await sandbox.runCommand('echo hello')).stdout);
} finally {
  await sandbox.destroy();
}
```

Install `computesdk`. The exported `compute` singleton uses the ComputeSDK router by default; no factory call or adapter package is needed. Set `COMPUTE_API_KEY` to authenticate.

## Methods

| Export or method                        | Purpose                                     |
| --------------------------------------- | ------------------------------------------- |
| `compute.instances.create(options)`     | Create a sandbox                            |
| `compute.instances.getById(id)`         | Reconnect to an existing sandbox            |
| `compute.instances.list()`              | List running sandboxes                      |
| `compute.instances.destroy(id)`         | Destroy a sandbox                           |
| `sandbox.runCommand(command, options?)` | Buffered, streaming or background execution |
| `sandbox.filesystem`                    | File and directory operations               |
| `sandbox.getUrl({ port })`              | Get a port URL                              |
| `sandbox.destroy()`                     | Release the sandbox                         |

## Create options

Pass options directly to `compute.instances.create()`. With no routing override, creation follows your organization's saved router.

| Option                       | Meaning                                                                                                                                                          |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `size`                       | `small`, `medium`, `large`, `xlarge`, `2xlarge` or `3xlarge`; available shapes depend on the provider                                                            |
| `cpus`, `memoryMb`, `diskMb` | Raw resource requirements; use these instead of `size`                                                                                                           |
| `timeout`                    | Sandbox lifetime in milliseconds, subject to provider limits                                                                                                     |
| `label`                      | A label for the sandbox, up to 200 characters; falls back to `name`                                                                                              |
| `envs`                       | Default environment variables for commands                                                                                                                       |
| `image` / `templateId`       | Provider-specific boot image or template                                                                                                                         |
| `snapshotId`                 | Restore a provider-supported snapshot                                                                                                                            |
| `secrets`                    | Up to 100 organization vault secret names to inject into commands                                                                                                |
| `disk`                       | Attach a supported disk with `{ diskId, path, readonly?, branch? }`                                                                                              |
| `idempotencyKey`             | A stable key for safe creation across process restarts, up to 200 characters                                                                                     |
| `providerOrder`              | Explicit placement order; named providers use connected provider keys. See [provider selection](https://docs.computesdk.com/interfaces/sdk.md#choose-a-provider) |

```typescript
import { compute } from 'computesdk';

const sandbox = await compute.instances.create({
  size: 'small',
  timeout: 600000,
  label: 'test-run',
  envs: { NODE_ENV: 'test' },
});
try {
  console.log(await sandbox.getInfo());
} finally {
  await sandbox.destroy();
}
```

Use either `size` or raw resources. Compatibility spellings include `vcpus`, `memoryMiB`, `memMiB`, `memory`, and `diskMiB`. Accepted option names do not imply that every provider offers the same resources, snapshots or images. Provider-specific direct-adapter `sizeClass` values are separate from router sizes.

## Command options

`runCommand(command, options?)` returns `stdout`, `stderr` and `exitCode`.

| Option                 | Meaning                                                                   |
| ---------------------- | ------------------------------------------------------------------------- |
| `cwd`                  | Working directory inside the sandbox                                      |
| `env`                  | Per-command environment variables                                         |
| `timeout`              | Command duration in milliseconds, up to 290 seconds for buffered commands |
| `onStdout`, `onStderr` | Callbacks for streamed output                                             |
| `background`           | Start detached work rather than wait for completion                       |

See [run commands](https://docs.computesdk.com/sandboxes/commands.md) and [errors and limits](https://docs.computesdk.com/interfaces/sdk/errors.md).

## Files, URLs and lifecycle

* `filesystem.readFile(path)` reads UTF-8 text; `writeFile(path, content)` writes it.
* `filesystem.mkdir(path)` creates a directory; `readdir(path)` lists entries.
* `getUrl({ port, protocol? })` resolves a provider-supported port URL.
* `getInfo()` reads sandbox details; `sandboxId` identifies the sandbox.
* `destroy()` releases the sandbox. Finishing a command or closing the client does not destroy it.

Read the task guides for [files](https://docs.computesdk.com/sandboxes/files.md), [previews](https://docs.computesdk.com/sandboxes/previews.md) and [lifecycle](https://docs.computesdk.com/sandboxes/lifecycle.md). `sandbox` remains a deprecated alias for `instances` on the compute object. Actions and organization resources use the [REST API](https://docs.computesdk.com/platform/api-reference.md).

## Compatibility

`computesdk@4.1.18` and earlier do not include the default router. Upgrade to a release containing built-in routing to use the examples in these docs.

Explicit provider and multi-provider configurations continue to work. An invalid explicit configuration still fails; it does not silently use the router. See the [GitHub adapter documentation](https://github.com/computesdk/computesdk/blob/main/OPEN_SOURCE.md) for existing direct provider integrations.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.computesdk.com/interfaces/sdk/reference.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
