> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anonalabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript: @anona/sdk

> Sandbox, live view tokens and SSH certificates for Node.js.

```text theme={null}
npm install @anona/sdk e2b
```

ESM only; Node.js 22.19 or newer.

## `configure`

```ts Signature theme={null}
configure(opts?: { apiKey?: string; domain?: string; apiUrl?: string; debug?: boolean }): void
```

Sets the `E2B_*` variables of this process so the stock `e2b` package, and the extras, talk to Anona.

```typescript configure.ts theme={null}
import { configure } from "@anona/sdk";
import { Sandbox } from "e2b"; // the stock SDK picks up the configuration

configure({ apiKey: process.env.ANONA_API_KEY });
const sbx = await Sandbox.create();
console.log((await sbx.commands.run("echo configured")).stdout);
await sbx.kill();
```

## `Sandbox`

A subclass of e2b's `Sandbox`. Every e2b method works unchanged and defaults to the Anona domain. Added:

| Member | Type |
| - | - |
| `sandbox.live` | `Live` |
| `sandbox.ssh` | `Ssh` |
| `Sandbox.connectionDefaults(opts?)` | the resolved connection options (diagnostics) |

## `sandbox.live`

| Method | Returns | |
| - | - | - |
| `token({ scope?, channels?, ttl? })` | `Promise<ViewerToken>` | `scope`: `"view"` (default) or `"control"`. `channels`: `"dom"`, `"pty"`, `"desktop"`, `"thumb"` (default `["dom"]`). `ttl`: 30 to 600 s (default 600) |
| `url({ mode?, scope?, ttl? })` | `Promise<string>` | Embed URL for one channel |
| `desktopUrl({ control?, ttl? })` | `Promise<string>` | Embed URL for the desktop; control scope unless `control: false` |
| `revokeAll()` | `Promise<void>` | Closes every viewer and invalidates issued tokens |

`ViewerToken` has `token`, `expiresAt` (`Date`), `embedUrl` and `claims()`. `toString()` and `toJSON()` never include the token.

```typescript live_tokens.ts theme={null}
import { Sandbox } from "@anona/sdk";

const sbx = await Sandbox.connect(process.env.SANDBOX_ID!);
const tok = await sbx.live.token({ scope: "control", channels: ["pty"], ttl: 120 });
console.log(String(tok), JSON.stringify(tok));
console.log(tok.claims().scp, tok.claims().sbx === sbx.sandboxId);
```

Errors map to e2b's classes: 400 `InvalidArgumentError`, 401/403 `AuthenticationError`, 404 `NotFoundError`, 429 `RateLimitError`, others `SandboxError`.

## `sandbox.ssh`

| Method | Returns | |
| - | - | - |
| `certificate(publicKey)` | `Promise<SshCertificate>` | The OpenSSH public key **text** (not a path) |
| `config({ identityFile?, certificateFile?, alias?, user?, proxyCommand? })` | `string` | An `ssh_config` block. No request |

`SshCertificate` is `{ cert, user, host, proxyCommand, expiresAt? }`. See [SSH](https://docs.anonalabs.com/compute/guides/ssh.md).

## Desktop

There is no desktop subclass in TypeScript: create with `@e2b/desktop`, then `Sandbox.connect(desk.sandboxId)` from `@anona/sdk` for `live.desktopUrl()`. See [Desktop](https://docs.anonalabs.com/compute/guides/desktop.md).

## Exports

`Sandbox`, `configure`, `applyEnv`, `anonaDefaults`, `Live`, `ViewerToken`, `Ssh`, `CHANNELS`, `SCOPES`, `MIN_TTL`, `MAX_TTL`, `DEFAULT_DOMAIN`, `DEFAULT_API_URL`, `DOMAIN_ENV`, `ENV_MAP`, and the types `ConfigureOpts`, `ViewerScope`, `ViewerChannel`, `ViewerTokenOpts`, `ViewerTokenClaims`, `SshCertificate`, `SshConfigOpts`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.