CoAI Sandbox quickstart
CoAI Sandbox runs your code in short-lived, isolated Linux sandboxes. It is compatible with the E2B SDK: you use the official
e2b package for Python or JavaScript, unchanged, and point it at CoAI Sandbox with two environment variables.
1. Get an API key
- Order CoAI Sandbox in the CoAI Host client area and verify your account with a saved card (the KB article "Order CoAI Sandbox and verify your account").
- Open the CoAI Sandbox console from the service page and create an API key. It starts with
ack_and is shown only once.
2. Set two environment variables
export E2B_API_KEY=ack_... # your CoAI Sandbox API key
export E2B_DOMAIN=sandbox.coaiwork.com # CoAI Sandbox instead of E2B
The SDK then talks to https://api.sandbox.coaiwork.com; your sandboxes get addresses under us-dal.coaisandbox.app.
Nothing else changes: no other variable, no code change.
3. Run a sandbox
Python (pip install e2b):
# CoAI Sandbox quickstart with the official E2B SDK for Python (pip install e2b).
# Set E2B_API_KEY (your ack_... key) and E2B_DOMAIN=sandbox.coaiwork.com first.
from e2b import Sandbox
# A sandbox of the template "base" that ends by itself after 5 minutes at the latest.
with Sandbox.create(timeout=300) as sbx:
result = sbx.commands.run("echo hello from CoAI Sandbox")
print(result.stdout, end="") # hello from CoAI Sandbox
sbx.files.write("/home/user/notes.txt", "written by the SDK\n")
print(sbx.files.read("/home/user/notes.txt"), end="") # written by the SDK
sbx.set_timeout(120) # the sandbox now ends 2 minutes from now
info = sbx.get_info()
print("sandbox", info.sandbox_id, "ends at", info.end_at)
# Leaving the with block kills the sandbox: its usage stops there.
JavaScript or TypeScript (npm install e2b; an ES module):
// CoAI Sandbox quickstart with the official E2B SDK for JavaScript (npm install e2b).
// Set E2B_API_KEY (your ack_... key) and E2B_DOMAIN=sandbox.coaiwork.com first.
import { Sandbox } from 'e2b'
// A sandbox of the template "base" that ends by itself after 5 minutes at the latest.
const sbx = await Sandbox.create({ timeoutMs: 300_000 })
try {
const result = await sbx.commands.run('echo hello from CoAI Sandbox')
process.stdout.write(result.stdout) // hello from CoAI Sandbox
await sbx.files.write('/home/user/notes.txt', 'written by the SDK\n')
process.stdout.write(await sbx.files.read('/home/user/notes.txt')) // written by the SDK
await sbx.setTimeout(120_000) // the sandbox now ends 2 minutes from now
const info = await sbx.getInfo()
console.log('sandbox', info.sandboxId, 'ends at', info.endAt.toISOString())
} finally {
await sbx.kill() // its usage stops here
}
Both print:
hello from CoAI Sandbox
written by the SDK
sandbox <id> ends at <time>
Templates
| Template | What it is |
|---|---|
base (the default) |
a Linux user user with sudo, python3, pip, venv, git, curl, Node.js, gcc, make and the GitHub CLI |
code-interpreter-v1 |
Jupyter with Python, R, JavaScript, Bash and Java kernels: the template of the Code Interpreter SDK (e2b-code-interpreter, @e2b/code-interpreter) |
What they cost is on the pricing page. Building your own templates is not available yet.
Good to know
- A sandbox always ends. Give
timeout(Python, in seconds) ortimeoutMs(JavaScript) when you create it, kill it when you are done, and copy out what you need first: when a sandbox ends, everything in it is deleted. - You pay while it runs, per millisecond (pricing page), from your CoAI Host account balance.
- Limits depend on your account's level (tiers and limits page); a new account starts at A0: 5 sandboxes at a time, at most 30 minutes each; internet access is allowlist only at every level for now (open internet access for A1 and A2 is planned).
- Errors carry the HTTP status and a message that says what to do (errors page).
- Keys: keep them secret, one per program; revoke a key in the console when you no longer need it.