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

# Quickstart

> Create a sandbox, run a command in it, write a file and kill it, in about two minutes.

**You need** a Styne API key: create one on the dashboard ([API keys](https://docs.styne.ai/authentication.md)).

**1. Install and set your key**

```text Python theme={"theme":"css-variables"}
pip install e2b
export E2B_API_KEY=<your Styne API key>
export E2B_API_URL=https://api.styne.ai
export E2B_SANDBOX_URL=https://sandbox.styne.ai
```

```text TypeScript theme={"theme":"css-variables"}
npm install e2b
export E2B_API_KEY=<your Styne API key>
export E2B_API_URL=https://api.styne.ai
export E2B_SANDBOX_URL=https://sandbox.styne.ai
```

```text Styne Python theme={"theme":"css-variables"}
pip install styne-sdk
export STYNE_API_KEY=<your Styne API key>
```

```text Styne TypeScript theme={"theme":"css-variables"}
npm install styne-sdk
export STYNE_API_KEY=<your Styne API key>
```

```text cURL theme={"theme":"css-variables"}
export STYNE_API_KEY=<your Styne API key>
```

```text CLI theme={"theme":"css-variables"}
curl -fsSL https://styne.ai/install | sh
styne login
```

The unmodified `e2b` package works: those three variables are the only change from E2B ([Switch from E2B](https://docs.styne.ai/e2b-drop-in.md)).
`E2B_SANDBOX_URL` sends the commands and file calls of every sandbox over one kept-open connection, so the first command of
a new sandbox answers as fast as the second. `styne login` stores your key with mode 600; in CI set `STYNE_API_KEY` instead.

**2. Create a sandbox and run a command**

```python Python theme={"theme":"css-variables"}
from e2b import Sandbox

sbx = Sandbox.create(template="base", timeout=300)
try:
    print("created", bool(sbx.sandbox_id))
    result = sbx.commands.run("uname -sm")
    print("exec", result.stdout.strip(), "exit", result.exit_code)
    sbx.files.write("/root/hello.txt", "hello\n")
    print("file", sbx.files.read("/root/hello.txt").strip())
finally:
    sbx.kill()
print("killed")
```

```typescript TypeScript theme={"theme":"css-variables"}
import { Sandbox } from 'e2b'

const sbx = await Sandbox.create('base', { timeoutMs: 300_000 })
try {
  console.log('created', Boolean(sbx.sandboxId))
  const result = await sbx.commands.run('uname -sm')
  console.log('exec', result.stdout.trim(), 'exit', result.exitCode)
  await sbx.files.write('/root/hello.txt', 'hello\n')
  console.log('file', (await sbx.files.read('/root/hello.txt')).trim())
} finally {
  await sbx.kill()
}
console.log('killed')
```

```bash cURL theme={"theme":"css-variables"}
SANDBOX_ID=$(curl -sS https://api.styne.ai/sandboxes \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"templateID": "base", "timeout": 300}' | sed -n 's/.*"sandboxID":"\([^"]*\)".*/\1/p')
echo "created $SANDBOX_ID"

curl -sS https://api.styne.ai/sandboxes/$SANDBOX_ID/exec \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"cmd": "uname", "args": ["-sm"]}'

curl -sS -X DELETE https://api.styne.ai/sandboxes/$SANDBOX_ID \
  -H "Authorization: Bearer $STYNE_API_KEY"
echo "killed"
```

```bash CLI theme={"theme":"css-variables"}
id=$(styne sandbox create --template base --timeout 300)
styne sandbox exec "$id" -- uname -sm
echo hello | styne sandbox files write "$id" /root/hello.txt
styne sandbox files read "$id" /root/hello.txt
styne sandbox kill "$id"
```

Save the TypeScript version as `quickstart.mjs` (or `.ts`) and run `node quickstart.mjs`. Expected output:

```text Python theme={"theme":"css-variables"}
created True
exec Linux x86_64 exit 0
file hello
killed
```

```text TypeScript theme={"theme":"css-variables"}
created true
exec Linux x86_64 exit 0
file hello
killed
```

```text cURL theme={"theme":"css-variables"}
created vm0123456789abcdef
{"started":{"pid":105}}
{"stdout":"TGludXggeDg2XzY0Cg=="}
{"exit":{"exitCode":0,"signal":0,"timedOut":false}}
killed
```

```text CLI theme={"theme":"css-variables"}
Linux x86_64
wrote /root/hello.txt
hello
killed vm0123456789abcdef
```

**3. Know what just happened**

| Step | What Styne did |
| - | - |
| Create | Started a sandbox from the `base` template (general Linux) and returned when it was ready, so the first command can follow at once. |
| Run | Ran the command and streamed its output. Over HTTP the output is base64 JSON lines and the last line carries the exit code ([Run commands](https://docs.styne.ai/exec.md)). |
| Kill | Ended the sandbox. A second kill answers `404` (nothing is left to delete, so cleanup code can run twice); any other call on an ended sandbox answers `410 sandbox_ended`. |

A sandbox you do not kill ends at its `timeout`: 300 seconds here, 1 to 86,400 allowed. In
Python a command that exits non-zero raises `CommandExitException` with the exit code and the output; the CLI's `exec` exits
with the command's exit code.

## Next

> [card] [Run commands](https://docs.styne.ai/exec.md)
>
> Several commands, background processes, stdin and streaming output.

> [card] [Timeouts, pause and resume](https://docs.styne.ai/pause-tiers.md)
>
> Keep memory, processes and files between tasks.

> [card] [Fork and snapshots](https://docs.styne.ai/fork.md)
>
> Copy a running sandbox, or save one and start many from it.

> [card] [API reference](https://docs.styne.ai/api-reference.md)
>
> Every operation of the sandbox API.

## Operations

| Method | Path | What it does |
| - | - | - |
| `POST` | `/sandboxes` | Create a sandbox from a template |
| `GET` | `/sandboxes/{id}` | Read one sandbox |
| `GET` | `/sandboxes` | List the account's sandboxes |
| `DELETE` | `/sandboxes/{id}` | Kill a sandbox |
| `GET` | `/templates` | List the templates the key can start |
| `GET` | `/regions` | List the regions and whether a machine there takes new VMs now |
| `GET` | `/templates/{id}` | One template by id or alias |


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