How do I…
How do I run code in a sandbox?
A sandbox is a small Linux computer of your own that starts in a few seconds. Whatever runs in it cannot touch your computer. Use it to run code an AI wrote, try a package or check a script.
Steps
- Create a sandbox. You get a fresh Linux machine with Python, Node.js and the usual tools.
- Run code or a command. Python code directly, anything else as a shell command (
pip install,git clone,npm test). - Read the result. Every run gives you its output (
stdout), its errors (stderr) and an exit code –0means success. - Delete the sandbox when you are done – or keep it, see Keep a workspace.
No code: copy this into Claude or ChatGPT with WBX Sandbox connected and change it to fit.
Create a WBX sandbox and run this Python code in it. Show me the output. import platform, sys print(platform.platform(), sys.version) Then install the package cowsay and use it to print "Hello from WBX".
pip install wbxsandbox, your key in WBXSANDBOX_API_KEY.
from wbxsandbox import Sandbox
with Sandbox.create() as sb: # a fresh Linux sandbox, removed at the end
r = sb.run_code("import sys, platform\nprint(platform.platform(), sys.version)")
print(r.stdout)
r = sb.run("pip install -q cowsay && python -m cowsay -t 'Hello from WBX'")
print(r.exit_code, r.stdout)
npm install wbxsandbox (Node.js 20+); save as .mts for top-level await.
import { WBX } from "wbxsandbox";
const wbx = new WBX();
const sandbox = await wbx.sandboxes.create(); // a fresh Linux sandbox
try {
const r = await sandbox.runCode("import sys, platform\nprint(platform.platform(), sys.version)");
console.log(r.stdout);
const c = await sandbox.commands.run("pip install -q cowsay && python -m cowsay -t 'Hello from WBX'");
console.log(c.exitCode, c.stdout);
} finally {
await sandbox.kill();
}
Just curl and jq; your key in WBXSANDBOX_API_KEY.
H="Authorization: Bearer $WBXSANDBOX_API_KEY"
SB=$(curl -s -X POST https://sandbox.wbx.cz/v1/sandboxes -H "$H" -d '{}' | jq -r .id)
curl -s -X POST https://sandbox.wbx.cz/v1/sandboxes/$SB/exec -H "$H" -d '{"cmd": "python3 -c \"import platform; print(platform.platform())\""}'
curl -s -X DELETE https://sandbox.wbx.cz/v1/sandboxes/$SB -H "$H"
How to tell it worked
- The output starts with
Linux-…and a Python version. - The exit code is
0and you see the cow saying Hello from WBX. - In the portal, Sandboxes shows the sandbox while it runs.
If it doesn't work
| What you see | What to do |
|---|---|
Exit code is not 0 | The command failed – the reason is in stderr. An assistant shows it to you; in code print r.stderr. |
401 unauthorized | The API key is missing or wrong. Check WBXSANDBOX_API_KEY or create a new key in API keys. |
429 with a limit on concurrent sandboxes | Your plan runs a set number of sandboxes at once (2 on Free). Delete sandboxes you no longer need, or let them sleep. |
pip install takes long | Installing is the slow part. Do it once and start copies: Prepare once, copy many. |
What it costs
A sandbox is billed while it runs, by its vCPU and memory. The default template base (2 vCPU, 512 MB) costs about US$0.07 (€0.06, 1.6 Kč) an hour. A sleeping sandbox uses no compute; only its disk is billed as storage. Current prices: Pricing.