> ## 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.

# Give your agent sandboxes

> Let a coding agent run untrusted or heavy work in a sandbox, through the command line, an SDK or the MCP server.

## Give the agent the CLI

Coding agents run shell commands. Install `styne` where the agent runs ([install](https://docs.styne.ai/install.md)), put your key in
`STYNE_API_KEY`, and tell the agent how to use it. Add this to the agent's instruction file:

```text theme={"theme":"css-variables"}
## Sandboxes
Run untrusted or heavy work in a Styne sandbox, never on this machine.
- create:  id=$(styne sandbox create --template base --timeout 900)
- run:     styne sandbox exec "$id" -- 'cd /root/work && python3 test.py'   (exits with the command's exit code)
- write:   styne sandbox files write "$id" /root/work/test.py ./test.py
- read:    styne sandbox files read "$id" /root/work/out.txt
- end:     styne sandbox kill "$id"   (always kill what you create)
```

The agent reads stdout, stderr and the exit code like for any command. The loop an agent runs looks like this:

```bash theme={"theme":"css-variables"}
id=$(curl -sS https://api.styne.ai/sandboxes \
  -H "Authorization: Bearer $STYNE_API_KEY" -H "content-type: application/json" \
  -d '{"templateID": "base", "timeout": 300}' | python3 -c 'import json,sys; print(json.load(sys.stdin)["sandboxID"])')
curl -sS https://api.styne.ai/sandboxes/$id/commands \
  -H "Authorization: Bearer $STYNE_API_KEY" -H "content-type: application/json" \
  -d '{"cmd": "sh", "args": ["-c", "python3 -c \"print(6*7)\""]}'
curl -sS -X DELETE https://api.styne.ai/sandboxes/$id -H "Authorization: Bearer $STYNE_API_KEY"
```

The second call answers a record with `"stdout":"42\n"` and `"exitCode":0`. [CLI reference](https://docs.styne.ai/cli.md#command-reference) lists every
command.

## Use an agent framework with the SDK

Frameworks that already run code in an E2B sandbox work unchanged with `E2B_API_KEY` set to your Styne key and
`E2B_API_URL=https://api.styne.ai`; see [Switch from E2B](https://docs.styne.ai/e2b-drop-in.md). Wrap `sbx.commands.run` and `sbx.files.write` as the
agent's tools.

## Connect the MCP server

The server is a thin layer over the same API, so the same key, limits and billing apply. These are the settings you will
use:

```json theme={"theme":"css-variables"}
{ "mcpServers": { "sandbox": { "url": "https://mcp.styne.ai/mcp", "headers": { "Authorization": "Bearer ${env:STYNE_API_KEY}" } } } }
```

Tools: `sandbox_create`, `sandbox_list`, `sandbox_kill`, `sandbox_pause`, `sandbox_resume`, `run_command`, `run_code`,
`file_write`, `file_read`, `file_list`, `get_preview_url`. The full table, output cuts and retry rules are on
[MCP server](https://docs.styne.ai/mcp.md).

## Keep it safe

* Give the agent a key of its own, so you can revoke it without touching yours.
* An agent forgets sandboxes. Create with a short `timeout` so a lost sandbox ends by itself, and tag it with `metadata`.
* Do not paste secrets into a sandbox you do not control; pass them as `envs` of the one command that needs them.


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