A sandbox in four lines
Node 20 or newer. The router speaks most providers’ HTTP APIs itself, so installing it is usually all there is to install.
Install it
The router, plus the SDK of any provider here that still needs one. A few providers’ SDKs build native code or run install scripts, so they stay optional; a provider whose key is set but whose SDK is missing is skipped with an install hint.
npm i sandboxroutingSet the keys you have
Keys come from the environment. Daytona gives $200 once and E2B $100 once; each provider’s page lists its keys. Local Docker needs none and goes after the free tiers.
export DAYTONA_API_KEY=…
export E2B_API_KEY=…Create a sandbox
The router picks a provider with free usage left that can take the whole request, and tries the next one if it refuses. sbx.route says what it tried and why.
import { createRouter } from "sandboxrouting";
const router = await createRouter();
const sbx = await router.create({ timeoutSec: 600 });
const r = await sbx.commands.run("python3 -c 'print(6*7)'");
await sbx.files.write("/work/app.py", "print('hi')");
console.log(sbx.provider, r.stdout);
await sbx.kill();See where it would go
The CLI is sbr. It plans without creating anything, so you can check a config before it spends a cent. sbr serve starts the REST API and sbr mcp the MCP server.
npx sbr providers # free-tier status, health and circuit
npx sbr route --needs ports # where a sandbox would go, and why
npx sbr route --compare # the same request under every strategy
npx sbr run -- python3 -c 'print(42)'Run work that can move
A job checkpoints its working directory after each step. If the box dies or its provider refuses, it continues on another box from the last checkpoint. Watch one move
const job = await router.jobs.run({
sandbox: { image: "python:3.12-slim" },
files: { "main.py": "print('hi')" },
setup: [{ run: "pip install -q requests" }],
steps: [
{ run: "python main.py > out.txt" },
{ run: "curl -fsS -X POST https://hooks.example/done", idempotent: false },
],
});
console.log(job.state, job.migrations);Configure it
Every field is optional. The router reads ./sandboxrouting.json, else ~/.sandboxrouting/config.json, or the path in SBR_CONFIG.
{
"routing": { "strategy": "free-first", "circuitBreaker": { "failures": 3, "cooldownSec": 120 } },
"allowPaid": false,
"maxPaidUsdPerMonth": 10,
"selfHosted": "after-free",
"defaults": { "timeoutSec": 300 },
"providers": {
"e2b": { "usedBeforeUsd": 12.5 },
"daytona": { "priority": 10 },
"modal": { "options": { "app": "sandboxrouting", "ports": [8080] } },
"vercel": { "options": { "runtime": "node22", "ports": [3000] } },
"fly": { "enabled": false, "options": { "app": "my-sandboxes" } },
"openci": { "options": { "url": "https://ci.example.internal" } },
"docker": { "options": { "image": "python:3.12-slim", "runtime": "runsc" }, "isolation": "gvisor" },
"koyeb": { "allowPaid": true }
},
"jobs": { "checkpoint": "every-step", "maxMigrations": 5, "maxWaitSec": 300, "rebalance": false }
}