How a provider is chosen
From README.md, rendered when the site was built.
A routing strategy makes the choice, and you can switch it. The hard rules come first
and are the same under every strategy, so no strategy can route around them. sbr route
prints the ranked plan and why each provider sits where it does. sbr route --compare
prints the plan under every strategy. The full design is in docs/routing.md.
| Strategy | Order |
|---|---|
free-first (default) |
Lanes: monthly free usage (the most at risk before its reset goes first), one-time credit (the largest share left goes first), your own hardware, then paid (cheapest first). |
cheapest |
Any free usage by price, then your hardware, then paid by price. |
balanced |
The free-first lanes. Within a free lane, a weighted score of free value, health, speed, free headroom and load (weights in config). In the paid lane, price comes first. |
fastest |
Unbilled first, then paid. Within each, the shortest expected time to a ready box: median create latency ÷ success rate. A provider never tried gets one try. The one strategy that pays more for speed. |
spread |
The free-first lanes. Within a free lane, the most free slots first (lowest live/cap, fewest recent creates), so fan-out doesn't trip one provider's rate limit. In the paid lane, price comes first. |
You pick a strategy three ways:
- in config, with
"routing": { "strategy": "balanced" }; - per request, with
strategy: "fastest"(--strategy); - by registering your own with
router.registerStrategy({ name, description, rank }).
Within a lane, priority in config breaks ties first. The lanes keep paid usage off by
default: with allowPaid: false nothing is ever billed, and a request no free tier can
take fails with the reason for every provider. You can turn paid usage on globally or per
provider. With maxPaidUsdPerMonth set, paid routing stops when the month's spend
reaches it. Your own hardware (openci, OpenSandbox, local Docker) goes after the free lanes. With
selfHosted: "first" it goes ahead of them, and with "never" it's removed.
A provider is left out when:
-
it has no key, or it is disabled;
-
it lacks a capability in
needs(ports,pause,customImage,gpu,snapshot,extendTimeout,fileList); -
it can't run the requested
image; -
the timeout is over its maximum;
-
execTimeoutSecis over its per-command cap (exe.dev cuts commands off at 30 s); -
its isolation is weaker than
minIsolation(container<gvisor<microvm/vm); -
it runs another operating system than the request's
os(linuxunless the request saysmacos;offstageis the macOS provider); -
its circuit is open (see below);
-
neither free nor paid usage can take the request. Free fails when:
- the tier is used up;
- what's left won't cover the whole request;
- its concurrency is full;
- the timeout is over the free lifetime cap.
Paid fails when it isn't allowed, or when the month's budget won't cover the whole request.
Live sandboxes reserve what they can still spend: until their deadline, at their own
size. So a free tier takes a request only if, after those reservations, it covers the full
timeout at the size the provider will create. A paid request needs the same from the
budget. Extending a sandbox (sbr extend) or resuming one reserves the time it adds under
the same rule, or is refused. With allowPaid: false, no sandbox can run past its free tier,
and maxPaidUsdPerMonth is a hard cap.
The router re-checks the provider under the ledger lock when reserving. A request planned as free that loses the last free slot or credit to a parallel request moves on to the next provider. It never quietly becomes paid.
If the chosen provider refuses, the router tries the next one, and the refusal changes what it does next:
| Refusal | What happens next |
|---|---|
| 402 or "out of credit" | The free tier is marked used up until the monthly reset. Other grants are checked again after 1 day, then 2, then 4, then weekly while they keep refusing. When a mark lapses, one request checks whether the tier is back while the others skip it; a free create that works clears the mark. |
| 429 | The provider is cooled down for a minute, even when the body says "quota": that is nearly always a cap on how many run at once. Only a 429 that says money ran out ("credit", "billing", "insufficient balance") counts as used-up credit. |
| 401 or 403 | The provider is skipped for 10 minutes. |
| Network errors and 5xx | The router moves on to the next provider. Three in a row open the provider's circuit: it is skipped for 2 minutes. The cooldown doubles with each further failure, up to 30. Then one request probes it. |
sandbox.route records every provider tried or skipped and why. sbr providers shows each
provider's health: the success rate of recent creates and the circuit state. This health
is computed from the last 50 outcomes whenever it is read, and sbr reset <provider>
clears it.
Metering
No provider has an API that reports remaining free credit, which the research for this router confirmed. So the router meters locally. Every sandbox's running time is recorded as billing segments. Pausing closes a segment. A sandbox past its deadline is billed only up to the deadline. Cost is running time × (vCPU × vCPU price + GiB × GiB price), using the provider's prices or yours.
Usage outside the router (the provider's console, another tool) isn't seen. For a one-time
credit you have already spent part of, set usedBeforeUsd. If a provider refuses for quota
anyway, the mark above catches it.
Some providers bill the vCPUs only while they are busy (pricing.billing: "active-cpu":
Vercel, Cloudflare, Render, Upstash Box, Fly Sprites, boxd, SuperHQ Nanite, Tensorlake, Runtime,
DigitalOcean Harness Runtime, Railway, smol).
Strategies rank these by the expected cost, with the vCPUs busy activeCpuShare of the time
(default 0.3; set routing.activeCpuShare for your workload, or
providers.<id>.pricing.activeCpuShare for one provider), so cheapest compares them fairly.
Reservations and metering still count every vCPU busy, since the router can't see CPU time: a
busy box can't overrun a free tier or a budget, and the router stops using such a free tier a
little before the provider would. Details in docs/routing.md.