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

# Sandbox API Flow

> Create, execute, manage files, and tear down a sandbox.

# Sandbox API Flow

This guide shows a typical end-to-end flow using the Sandbox API.

## 1) Register and get an API key

```bash theme={null}
curl -X POST https://api.sandbox.stateset.app/api/v1/register \
  -H "Content-Type: application/json" \
  -d '{"first_name": "Your", "last_name": "Name", "organization_name": "Company", "email": "you@example.com"}'
```

## 2) Create a sandbox

```bash theme={null}
curl -X POST https://api.sandbox.stateset.app/api/v1/sandbox/create \
  -H "Authorization: ApiKey YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"timeout_seconds": 300}'
```

## 3) Execute a command

```bash theme={null}
curl -X POST https://api.sandbox.stateset.app/api/v1/sandbox/SANDBOX_ID/execute \
  -H "Authorization: ApiKey YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"command": "python3 -c \"print(Hello World!)\""}'
```

## 4) Write a file

```bash theme={null}
curl -X POST https://api.sandbox.stateset.app/api/v1/sandbox/SANDBOX_ID/files/write \
  -H "Authorization: ApiKey YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"path": "/workspace/hello.txt", "content": "SGVsbG8h", "encoding": "base64"}'
```

## 5) Read a file

```bash theme={null}
curl -X POST https://api.sandbox.stateset.app/api/v1/sandbox/SANDBOX_ID/files/read \
  -H "Authorization: ApiKey YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"path": "/workspace/hello.txt"}'
```

## 6) Stop the sandbox

```bash theme={null}
curl -X POST https://api.sandbox.stateset.app/api/v1/sandbox/SANDBOX_ID/stop \
  -H "Authorization: ApiKey YOUR_API_KEY"
```

## Related Documentation

* [Sandbox Quickstart](/stateset-sandbox-quickstart)
* [API Reference](/stateset-sandbox/API_REFERENCE)
