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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pages/sandbox/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ A real isolated computer for every agent. Each sandbox is a dev container or mic
## What you get

- **A full machine per agent.** Run shell commands, read and write files, open ports, snapshot state, and attach a GPU only for the command that needs it.
- **Any coding harness.** Each sandbox runs one AI backend: OpenCode (default), Claude Code, Codex, Cursor, and a dozen more. You pick it per sandbox.
- **Durable agent sessions.** Dispatch a prompt and reconnect to the same run after a client crash, a deploy, or a browser reload. Same session ID is idempotent, so a retried request never re-executes.
- **Any coding harness.** Choose the initial harness, such as OpenCode (default), Claude Code, or Codex, when you create a sandbox. Sessions can select different [supported harnesses](/infrastructure/harnesses).
- **Durable agent sessions.** Dispatch a prompt and reconnect to the same run after a client crash, a deploy, or a browser reload. Store session and turn IDs for retries; completed work is deduplicated while its result remains cached.
- **One key, metered per second.** The same [`sk-tan-` key](/platform/authentication) authenticates every call; you pay for what you use.

## Why use it
Expand All @@ -23,7 +23,7 @@ A real isolated computer for every agent. Each sandbox is a dev container or mic

## How it works

Your SDK or CLI call hits the Sandbox API, which routes to a driver (container or microVM), provisions the machine, and relays the agent's output back to you as it streams. You never manage the infrastructure: `create` returns a machine, `delete` releases it. For the execution and orchestration internals, see the [runtime docs](/infrastructure/introduction).
Your SDK and CLI calls hit the Sandbox API, which routes to a driver (container or microVM), provisions the machine, and relays the agent's output back to you as it streams. You never manage the infrastructure: `create` returns a machine, `delete` releases it. For the execution and orchestration internals, see the [runtime docs](/infrastructure/introduction).

## Use cases

Expand Down
71 changes: 55 additions & 16 deletions pages/sandbox/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,58 @@ Create an isolated machine, run a shell command in it, then hand it to a coding

```bash
npm install @tangle-network/sandbox
npm install --save-dev tsx
```

## 2. Get an API key

Create an `sk-tan-` key from [Authentication](/platform/authentication) and export it:

```bash
export TANGLE_API_KEY=sk-tan-...
read -rsp "Tangle API key: " TANGLE_API_KEY
printf "\n"
export TANGLE_API_KEY
```

One key authenticates every Tangle product. Pass it to the client as `apiKey`; the SDK does not read env vars for you.

## 3. Create a sandbox and run a command
## 3. Check your credit and the service

Free accounts start with no included credit.
Add prepaid credit or select a plan with included credit at [id.tangle.tools](https://id.tangle.tools) before creating a sandbox.
Agent model usage also draws from your balance.
On the Free plan, sandboxes pause when the balance reaches zero.

Check your key and available credit without provisioning a machine:

```bash
curl -fsS https://id.tangle.tools/v1/billing/balance \
-H "Authorization: Bearer ${TANGLE_API_KEY:?Set TANGLE_API_KEY}"
```

The response's `data.balance` is your available credit in US dollars.
You can also check the service and available templates without creating a sandbox:

```bash
curl -fsS https://sandbox.tangle.tools/health
curl -fsS https://sandbox.tangle.tools/v1/public-templates
```

Each TypeScript block below is a separate program for Node.js 22 or later.
Run it in a project with the SDK installed and `TANGLE_API_KEY` exported.
Save either block as `example.ts` and run it with `npx tsx example.ts`.
Both examples release their machine after completion.

## 4. Create a sandbox and run a command

```typescript
import { Sandbox } from "@tangle-network/sandbox";

const apiKey = process.env.TANGLE_API_KEY;
if (!apiKey) throw new Error("Set TANGLE_API_KEY");

const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
apiKey,
baseUrl: process.env.SANDBOX_BASE_URL ?? "https://sandbox.tangle.tools",
});

Expand All @@ -45,14 +78,25 @@ try {

`create` returns a live machine; `delete` releases it. You never provision infrastructure yourself.

## 4. Run a coding agent
## 5. Run a coding agent

Each sandbox runs one coding harness. Choose it with `backend.type`. `opencode` (OpenCode) is the default and needs no extra key. `claude-code` (Claude Code) runs on Tangle Router by default with no extra key. To bring your own Anthropic credential, pass `backend: { type: 'claude-code', model: { apiKey: process.env.ANTHROPIC_API_KEY } }`. See [supported harnesses](/infrastructure/harnesses) for the full list.
Choose the initial coding harness with `backend.type`.
Sessions can select different [supported harnesses](/infrastructure/harnesses) in the same sandbox. `opencode` (OpenCode) is the default and needs no separate model-provider key. `claude-code` (Claude Code) runs on Tangle Router by default with no separate model-provider key. To bring your own Anthropic credential, pass `backend: { type: 'claude-code', model: { apiKey: process.env.ANTHROPIC_API_KEY } }`. See [supported harnesses](/infrastructure/harnesses) for the full list.

```typescript
import { Sandbox } from "@tangle-network/sandbox";

const apiKey = process.env.TANGLE_API_KEY;
if (!apiKey) throw new Error("Set TANGLE_API_KEY");

const client = new Sandbox({
apiKey,
baseUrl: process.env.SANDBOX_BASE_URL ?? "https://sandbox.tangle.tools",
});

const box = await client.create({
environment: "universal",
backend: { type: "opencode" },
backend: { type: "opencode" }, // Also supports Claude Code, Codex, and other supported harnesses.
});

try {
Expand All @@ -63,16 +107,11 @@ try {
}
```

For runs that must survive a client crash or a browser reload, use `box.dispatchPrompt(message, { sessionId })` and reconnect with `box.session(sessionId)`. See [durable sessions in the SDK reference](/sandbox/sdk-reference).

## 5. Check before you build (optional)

These calls are safe to run without creating a sandbox:

```bash
curl -fsS https://sandbox.tangle.tools/health
curl -fsS https://sandbox.tangle.tools/v1/public-templates
```
For durable runs, use `box.dispatchPrompt(message, { sessionId, turnId })` and reconnect with `box.session(sessionId)`.
Store both IDs before dispatching and reuse them for retries of the same turn.
Completed retries are deduplicated while their results remain cached.
A session ID alone does not deduplicate completed retries.
See [durable sessions in the SDK reference](/sandbox/sdk-reference).

## Next

Expand Down
Loading
Loading