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

# Create an AI sandbox with TypeScript

> Create an AI sandbox with TypeScript using @beadrun/sdk, then authenticate, run a command, and delete the machine.

Create an AI sandbox with TypeScript, run a command on its Linux machine and delete it with `@beadrun/sdk`. Use Node.js 18 or later, Bun, or Deno with npm imports.

## Install and authenticate

```bash theme={null}
npm install @beadrun/sdk
```

Set `BEAD_API_KEY` through your secret manager or private environment. Get an account through [agent signup](https://docs.bead.run/agent-signup.md). The default API origin is `https://api.bead.run`; override it with `BEAD_API_URL`.

## Run a command

```typescript theme={null}
import { Sandbox } from '@beadrun/sdk';

const sb = await Sandbox.create({ template: 'base', size: 'small', timeout: 300 });
try {
  const result = await sb.run('echo hi', { timeout: 30 });
  console.log(result.stdout);
  console.log(result.exitCode);
} finally {
  await sb.kill();
}
```

A nonzero command exit is a result with `exitCode`, `stdout` and `stderr`. Inspect it before starting dependent work. All SDK timeouts use seconds; the default machine lifetime is 300 seconds.

## Automatic disposal

With TypeScript 5.2 or later and `ESNext.Disposable` enabled:

```typescript theme={null}
import { Sandbox } from '@beadrun/sdk';

await using sb = await Sandbox.create({ size: 'small' });
console.log((await sb.run('echo hi')).stdout);
```

Disposal deletes the machine. A disconnected process does not stop remote compute. Breaking a stream stops reading and may leave the process running.

See [TypeScript SDK reference](https://docs.bead.run/sdks/typescript/reference.md) for streaming, files, snapshots and parallel work.


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