AzatAI Sandbox
Get started
Start a sandbox from Python, run a command in it, and read and write its files.
A sandbox is a virtual machine of its own, with its own kernel. It starts in under a second. You create it, run commands in it, read and write its files, and delete it from code.
Before you start
You need:
- Python 3.11 or later
- uv, to add the client to your project
- An AzatAI API key and a sandbox domain. To get them, talk to us.
Install the client
uv add azatai
Set your key
The client reads its settings from environment variables:
export AZATAI_API_KEY="your-api-key"
export AZATAI_SANDBOX_DOMAIN="your-sandbox-domain"
Configuration lists all the settings.
Start a sandbox
from azatai import Sandbox
with Sandbox.create() as sbx:
run = sbx.commands.run("python3 --version")
print(run.stdout)
sbx.files.write("/home/user/hello.txt", "hello")
print(sbx.files.read("/home/user/hello.txt"))
The sandbox stops when the with block ends. Without a with block, call sbx.kill().
Use asyncio
For asyncio code, use AsyncSandbox:
from azatai import AsyncSandbox
sbx = await AsyncSandbox.create()
run = await sbx.commands.run("uname -a")
await sbx.kill()
Start from a template
Sandbox.create("my-template") starts a sandbox from a template. A template holds the packages and files that your sandboxes need, so each sandbox starts ready. Use Template and AsyncTemplate to build templates.
Limits
| Limit | Value |
|---|---|
| Start time | Under 1 second |
| CPU | Up to 32 vCPU |
| Memory | Up to 128 GiB |
| Run time | Up to 24 hours for one run |