Skip to content
sandboxrouting

How a request finds a box

Every diagram on this page plays what the router’s own code did when this site was built, on Nov 21, 2026: real plans, a real failover, the real circuit breaker and state machines. The design behind them is in docs/routing.md.

Hard rules first, then a strategy

A provider that fails any of 12 rules is left out, with its reason recorded: no key, a missing capability, weaker isolation than you asked for, a rate-limit mark, an open circuit, or no free or paid usage that can take the whole request.

The rules are the same under every strategy, so no strategy can route around allowPaid or a budget. A strategy only orders what is left, in lanes: free every month first, then one-time credit, your own hardware, then paid. The example ledger: every provider's key is set; Modal has spent $18.40 of its $30 this month, Freestyle $9.10; Vercel refused with a 402 an hour ago; E2B answered 429 twenty seconds ago; Daytona's key was refused two minutes ago; Northflank failed three creates in a row.

sbr route --strategy free-first --cpu 2 --memory 4096 --timeout 60058 in order
strategy
needs
minIsolation
allowPaid
108 providers, 50 left out by the hard rules, 58 ranked
  1. 1InstaBoxFree every month, 100% left, resets in 9.5 dfree
  2. 2Islo MachinesFree every month, 100% left, resets in 9.5 dfree
  3. 3agentalFree every month, 100% left, resets in 9.5 dfree
  4. 4Upstash BoxFree every month, 100% left, resets in 9.5 dfree
  5. 5Fly.io MachinesFree every month, 100% left, resets in 9.5 dfree
  6. 6CyqleFree every month, 100% left, resets in 9.5 dfree
  7. 7Cloudflare SandboxFree every month, 100% left, resets in 9.5 dfree

then 51 more, each tried in turn if InstaBox refuses

The strategies

free-firstthe default
Free usage first: monthly tiers by most at risk per day left, then one-time credit by share left, then your hardware, then paid, cheapest first.
cheapest
By price: any free usage first, then your hardware, then paid, cheapest first.
balanced
The free-first lanes; within a lane, a weighted score of free value, health, speed, free coverage and load (routing.weights).
fastest
Unbilled first (free tiers and your hardware), then paid; within each, the shortest expected time to a ready box (median create latency ÷ success rate).
spread
The free-first lanes; within a lane, the most free headroom first (lowest live/cap, fewest recent creates), so fan-out doesn't hit one provider's rate limit.

When a provider refuses

The router tries the next provider in the plan and marks the one that refused. A 429 benches it for 1 min, a 401 or 403 for 10 min, and a 402 marks its free tier used up until the monthly reset.

A free tier that no reset brings back is asked again after 1, 2, 4 and then every 7 days, one create at a time, while the others skip it. These are three requests through the real router with four scripted providers.

router.create({ providers: ["modal", "vercel", "upstash", "freestyle"] })
  1. modal402 Payment Required: insufficient creditrefused (quota), so it gets a quota mark for 9.5 d
  2. vercel429 Too Many Requestsrefused (rate_limit), so it gets a rate-limit mark for 1 min
  3. upstash401 Unauthorized: invalid API keyrefused (auth), so it gets an auth mark for 10 min
  4. freestylecreated on a free tier (free-recurring)

The ledger after this request

  • modal: quota mark, in force for 9.5 dFree usage can't take requests until the tier's monthly reset. Then one free create checks whether it is back.
  • vercel: rate-limit mark, in force for 1 minA 429 is nearly always a cap on how many run at once, so the provider is only cooled down.
  • upstash: auth mark, in force for 10 minThe key was refused. sbr reset clears the mark once the key is fixed.

A mark is in force until its time, evaluated whenever it is read. Nothing has to clear it; a free create that works after a quota mark lapses removes it.

The circuit breaker

Network errors, 5xx and timeouts count toward a provider’s health. 3 in a row open its circuit for 120 seconds, doubling with each further failure up to 30 minutes. Then one create may probe it, and a success closes it.

Health is computed from the last 50 outcomes whenever it is read. There is no “open” flag to forget to clear.

0sRequest 1: northflank failed (503), served by modal10sRequest 2: northflank failed (503), served by modal20sRequest 3: northflank failed (503), served by modal60sRequest 4: northflank skipped, served by modal140sCooldown over145sRequest 5 probes: northflank failed (503), served by modal385sDoubled cooldown over390sRequest 6 probes: created on northflankgreen closed, black open, grey half-open; filled dots are creates that failed (black) or worked (green)

t = 20 s. Request 3: northflank failed (503), served by modal

Open: the provider is skipped until the cooldown ends. 3 failures in a row; open for 2 min more.

Config: 3 failures open it for 120 s, doubling with each further failure up to 1800 s (routing.circuitBreaker).

A sandbox's life

One function moves a sandbox between states, and the buttons below can only send the events it accepts. Billing is a list of segments, open exactly while the box is running, so a paused box costs nothing and one past its deadline is billed to the deadline.

expired is never stored: a running sandbox past its deadline reads as expired (effectiveState).

createdcreateFailed · lostpausedtimeoutSetstoppedlostresumedstoppedloststoppedlostdeadline passescreatingrunningpausedexpiredstoppedfailedderived, never stored

Send an event to the sandbox in creating

A new record starts in creating, holding what its timeout can spend. Disabled events are the ones the router refuses from here; hover one for the error it throws.

Work that moves when a box dies

A job is ordered steps plus a working directory, checkpointed after every step. When its box vanishes, its provider refuses, or a limit is about to end it, the job continues on another box from the last checkpoint, avoiding the provider that failed it.

A step marked idempotent: false never runs twice: if its outcome is unknown, the job fails instead. Defaults: 5 migrations a job, 3 attempts a step, a 60 s lease that a crashed runner’s job is resumed from.

  1. queued
  2. placing
  3. preparing
  4. running
  5. migrating
  6. succeeded

Box 1: modal

not placed yet

Checkpoints

~/.sandboxrouting/checkpoints/
  • none yet: the initial files are the spec’s

 

Box 2: freestyle

not placed yet
  1. python main.py > out.txtidempotent
  2. python report.py out.txtidempotent
  3. curl -fsS -X POST https://hooks.example/doneidempotent: false

submitted: 3 steps (1 of 16, 0 migrations)