Skip to content
sandboxrouting

Jobs: work that moves between boxes

From README.md, rendered when the site was built.

A sandbox can die, its provider can refuse, or a free tier's limits can end it: a lifetime cap (E2B's free hour, Vercel's 45 minutes), running out of credit, the provider failing. A job keeps going through all of that. It is ordered steps plus a working directory. The workdir is checkpointed after each step, so the job continues on another box from where it stopped.

const job = await router.jobs.run({
  sandbox: { image: "python:3.12-slim" },          // routed like router.create
  files: { "main.py": "print('hi')" },             // the initial workdir ($HOME/work)
  setup: [{ run: "pip install -q requests" }],     // runs again on every new box
  steps: [
    { run: "python main.py > out.txt" },
    { run: "curl -fsS -X POST https://hooks.example/done", idempotent: false },
  ],
});
console.log(job.state, job.migrations, job.placements.map((p) => `${p.provider}:${p.endReason}`));
  • Planned moves. Before each step the job checks the box. If the box can't fit the next step, the job extends it when the provider allows that within the free lifetime cap; otherwise it moves. It also moves when the free credit won't cover the step and another provider ranks first, when a quota or auth refusal or an open circuit hits the box's provider, and, with rebalance, off a paid box when a free one is available.
  • Unplanned losses. If a box vanishes, its provider refuses, or errors repeat, the job moves to a new box and restores the last checkpoint. The step that was running runs again, but only if it is idempotent (the default). Steps with outside effects are marked idempotent: false, so the job fails rather than run them twice. A non-zero exit is the step's own failure unless it has retries. Exit 137 can move the job to a box with twice the memory (growMemoryOnOom).
  • Crashes. The process driving a job holds a lease. If it dies, the job reads as orphaned after 60 s, and sbr job resume <id> (or sbr serve, every 5 minutes) continues it from what the ledger recorded.
  • Waiting. When no provider can take the job now, it waits only if a reason lapses within maxWaitSec: a rate-limit mark, a circuit, or a full free tier whose next sandbox ends soon. Otherwise it fails at once with every provider's reason.

Checkpoints live in ~/.sandboxrouting/checkpoints/ and are checked by SHA-256. When the job ends, the last one is the result: sbr job download <id> saves it. router.move(id) does the same move once for an interactive sandbox: it copies the workdir to a new box, then kills the old one. The design and every decision table are in docs/routing.md.