@sandboxrouter/sdk 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +13 -8
  2. package/dist/agent-bench.d.ts +12 -1
  3. package/dist/agent-bench.js +46 -7
  4. package/dist/bench.d.ts +13 -1
  5. package/dist/bench.js +39 -17
  6. package/dist/billing.js +0 -1
  7. package/dist/burst.d.ts +10 -0
  8. package/dist/burst.js +21 -10
  9. package/dist/catalog.d.ts +13 -0
  10. package/dist/catalog.js +34 -16
  11. package/dist/cli.js +47 -37
  12. package/dist/client.d.ts +6 -1
  13. package/dist/client.js +19 -0
  14. package/dist/computers.d.ts +2 -2
  15. package/dist/cost.d.ts +44 -5
  16. package/dist/cost.js +54 -24
  17. package/dist/leaderboard.d.ts +30 -8
  18. package/dist/leaderboard.js +89 -50
  19. package/dist/price-index.d.ts +3 -3
  20. package/dist/price-index.js +3 -3
  21. package/dist/providers/blaxel.d.ts +1 -0
  22. package/dist/providers/blaxel.js +56 -1
  23. package/dist/providers/daytona.js +33 -1
  24. package/dist/providers/deno.d.ts +3 -0
  25. package/dist/providers/deno.js +14 -0
  26. package/dist/providers/docker.d.ts +1 -0
  27. package/dist/providers/docker.js +30 -3
  28. package/dist/providers/e2b.d.ts +22 -1
  29. package/dist/providers/e2b.js +50 -3
  30. package/dist/providers/hopx.js +12 -0
  31. package/dist/providers/limrun.d.ts +1 -8
  32. package/dist/providers/limrun.js +0 -1
  33. package/dist/providers/mobilerun.d.ts +1 -5
  34. package/dist/providers/mobilerun.js +18 -26
  35. package/dist/providers/modal.js +7 -0
  36. package/dist/providers/novita.js +5 -5
  37. package/dist/providers/sail.js +4 -4
  38. package/dist/providers/vercel.js +41 -3
  39. package/dist/published.js +639 -1283
  40. package/dist/recommend.d.ts +17 -0
  41. package/dist/recommend.js +17 -11
  42. package/dist/results.d.ts +2 -2
  43. package/dist/results.js +104 -3
  44. package/dist/router.d.ts +22 -8
  45. package/dist/router.js +58 -11
  46. package/dist/server.d.ts +4 -1
  47. package/dist/server.js +101 -7
  48. package/dist/task.d.ts +2 -1
  49. package/dist/task.js +38 -19
  50. package/dist/types.d.ts +20 -4
  51. package/dist/validate.d.ts +4 -2
  52. package/dist/validate.js +18 -1
  53. package/package.json +18 -3
package/README.md CHANGED
@@ -2,15 +2,20 @@
2
2
 
3
3
  **One API for every sandbox.** A free, open-source router for the places an AI agent can run code: Agent37, Alibaba Cloud, AWS (Bedrock AgentCore and Lambda MicroVMs), Azure Container Apps, Beam, Blaxel, Boat, Cloudflare, CodeSandbox, Daytona, Dedalus Machines, Deno, E2B, exe.dev, Fly.io Sprites, Freestyle, HOPX, InstaBox, Koyeb, Maritime, Modal, Morph, Northflank, Novita, OpenScale, Runloop, Sail, Superserve, Tensorlake, Upstash Box and Vercel, plus Docker on your own machine. It picks a provider by price, speed or capability, and falls back to the next one when a provider is down or rate-limited.
4
4
 
5
+ E2B quickstart (Node 22.19+ and an E2B API key):
6
+
5
7
  ```bash
6
- npm i @sandboxrouter/sdk # plus the SDK of each provider you use: see Install below
8
+ npm i @sandboxrouter/sdk e2b
9
+ export E2B_API_KEY=... # your E2B API key
7
10
  ```
8
11
 
9
- ```ts
12
+ Save as `agent.mjs` and run `node agent.mjs`:
13
+
14
+ ```js
10
15
  import { Router } from "@sandboxrouter/sdk";
11
16
 
12
- const router = new Router(); // uses whichever provider keys you've set
13
- const sbx = await router.create(); // or create({ vcpu: 2, memoryGb: 4 }) for a size
17
+ const router = new Router();
18
+ const sbx = await router.create({ timeoutMinutes: 10 }, { provider: "e2b" });
14
19
  try {
15
20
  const r = await sbx.exec("python3 -c 'print(6*7)'");
16
21
  console.log(r.stdout, "ran on", sbx.provider);
@@ -19,9 +24,9 @@ try {
19
24
  }
20
25
  ```
21
26
 
22
- Runs as plain JavaScript on Node 20+. (In TypeScript 5.2+, or Node 24+, `await using sbx = ...` kills the sandbox for you.)
27
+ The SDK uses ES modules and runs on Node 20+. Each optional provider SDK can require a newer Node version. For TypeScript 5.2+ on Node 22+, `await using sbx = ...` also works when the compiler includes `ESNext.Disposable`. Plain JavaScript supports that syntax on Node 24+.
23
28
 
24
- Set the keys of the providers you use. `create()` starts the sandbox on the cheapest one that fits: list price for the size you asked for, corrected where we measured what a provider really bills. Providers within 10% of each other on price go fastest first, by start times measured where you run the router. Providers that failed their last real-account check go last. Ties are alphabetical, and no provider pays for placement. If that provider is down, busy or out of credit, the next one takes it, and every attempt is on `sbx.attempts`. The sandbox stays on that provider until you `kill()` it.
29
+ Set the keys of the providers you use. `create()` starts the sandbox on the cheapest one that fits: list price for the size you asked for, corrected where we measured what a provider really bills. Providers within 10% of each other on estimated price go fastest first. The router uses its own timings, your benchmark file or published timings, in that order. Estimates exclude account-specific charges such as [Boat’s fees above its included start allowance](https://docs.boat.dev/limits.md#extra-starts). Providers that failed their last real-account check go last. Ties are alphabetical, and no provider pays for placement. If that provider is down, busy or out of credit, the next one takes it, and every attempt is on `sbx.attempts`. The sandbox stays on that provider until you `kill()` it.
25
30
 
26
31
  Site and docs: [sandboxrouter.ai](https://sandboxrouter.ai) · npm: [`@sandboxrouter/sdk`](https://www.npmjs.com/package/@sandboxrouter/sdk)
27
32
 
@@ -29,8 +34,8 @@ Site and docs: [sandboxrouter.ai](https://sandboxrouter.ai) · npm: [`@sandboxro
29
34
 
30
35
  AI agents need a disposable computer to run code a model wrote: install packages, run tests, do an RL rollout. Dozens of providers sell one, each with its own SDK and auth, and the same 2 vCPU / 4 GB sandbox costs from under a cent to over thirty cents an hour. sandboxRouter is one interface over all of them:
31
36
 
32
- - **Same code everywhere.** `create`, `exec` (streamed), `writeFile`, `readFile`, `pause`, `kill`. Switch providers by changing which keys are set.
33
- - **The provider's own SDK is still there.** `sbx.native` is the provider's own sandbox object (an E2B `Sandbox`, a Daytona `Sandbox`, a Modal `Sandbox`, ...), already connected, for ports, background processes, snapshots and anything else the router doesn't cover. See [Using a provider's own features](https://sandboxrouter.ai/docs#native).
37
+ - **Same code everywhere.** `create`, streamed `exec`, files and cleanup. Require support for `pause`, preview URLs with `sbx.url(port)`, or background commands with `sbx.start()`. See [Preview URLs and background commands](docs/reference.md#preview-urls-and-background-commands).
38
+ - **The provider's own SDK is still there.** `sbx.native` is the provider's own sandbox object for features such as snapshots and volumes. See [Using a provider's own features](https://sandboxrouter.ai/docs#native).
34
39
  - **Cheapest real cost, then speed, with fallback.** A `maxHourlyUsd` price cap and `quote()` to see where a sandbox would land and what the run costs before starting it. Or `cheapest` for strictly lowest cost for the run, `fastest` by start times, `verified` for tested providers first, or a list of providers you name. `requireVerified` limits a router to providers that passed the real-account check.
35
40
  - **Errors you can act on.** Every failure has a `code` (`no_provider`, `setup`, `all_failed`, `timeout`, ...), an HTTP status, and the list of providers tried.
36
41
  - **Your keys, or one hosted key.** With your own provider keys, sandboxes run on your accounts and nothing passes through anyone else. The optional hosted key (api.sandboxrouter.ai) runs them on sandboxRouter's provider accounts instead, so its requests go through that server; see [Security](https://www.sandboxrouter.ai/security).
@@ -8,12 +8,23 @@ import type { ProviderId } from "./types.js";
8
8
  * Measures, per provider: how often the task was done right, wall time, time spent waiting on the model, the
9
9
  * sandbox CPU used, turns, and what the sandbox was billed (start, minimum, fee, active CPU where it applies).
10
10
  */
11
- export declare const AGENT_TASK_VERSION = "gemini-primes-v1";
11
+ export declare const AGENT_TASK_VERSION = "gemini-primes-v2";
12
12
  export declare const AGENT_TASK: string;
13
+ /** Compare the saved file and the script's output to an independently computed prime sequence. */
14
+ export declare const AGENT_VERIFY = "python3 - <<'SRVERIFY'\nimport pathlib, re, subprocess, sys\n\nwork = pathlib.Path(\"/tmp/work\")\nflags = bytearray([1]) * 48612\nflags[:2] = b\"\\x00\\x00\"\nfor i in range(2, 221):\n if flags[i]:\n flags[i * i::i] = bytes(len(flags[i * i::i]))\nexpected = [i for i, prime in enumerate(flags) if prime]\nif len(expected) != 5000:\n sys.exit(\"invalid verification fixture\")\n\ndef valid_file():\n file = work / \"primes.txt\"\n if not file.is_file() or file.stat().st_size > 64000:\n return False\n return file.read_text().splitlines() == [str(p) for p in expected]\n\nif not valid_file():\n sys.exit(\"incorrect saved prime sequence\")\n(work / \"primes.txt\").unlink()\nresult = subprocess.run(\n [sys.executable, str(work / \"primes.py\")], cwd=work,\n capture_output=True, text=True, timeout=60, check=True,\n)\nif str(sum(expected)) not in re.findall(r\"[0-9]+\", result.stdout) or not valid_file():\n sys.exit(\"incorrect regenerated prime sequence or sum\")\nprint(\"VERIFIED\")\nSRVERIFY";
13
15
  export interface AgentRow {
14
16
  provider: ProviderId;
15
17
  /** Sessions that started (the ones refused for an account limit are counted in `limited` instead). */
16
18
  runs: number;
19
+ /** Requested sessions, including refused requests. */
20
+ requested?: number;
21
+ /** Sessions whose sandbox started, whether or not the task passed. */
22
+ started?: number;
23
+ /** Nominal router shape for this provider. */
24
+ size?: {
25
+ vcpu: number;
26
+ memoryGb: number;
27
+ };
17
28
  /** Sessions the provider refused to start for a limit or quota on the benchmarking account. */
18
29
  limited?: number;
19
30
  /** Runs where the task checked out. */
@@ -12,15 +12,44 @@ import { LIMITED_ERROR } from "./bench.js";
12
12
  * Measures, per provider: how often the task was done right, wall time, time spent waiting on the model, the
13
13
  * sandbox CPU used, turns, and what the sandbox was billed (start, minimum, fee, active CPU where it applies).
14
14
  */
15
- export const AGENT_TASK_VERSION = "gemini-primes-v1";
15
+ export const AGENT_TASK_VERSION = "gemini-primes-v2";
16
16
  export const AGENT_TASK = [
17
17
  "You are working in a fresh Linux sandbox through a tool that runs shell commands.",
18
18
  "Write /tmp/work/primes.py: it computes the first 5000 prime numbers without using the network, writes them to",
19
19
  "/tmp/work/primes.txt one per line, and prints their sum. Run it and fix it until it works.",
20
20
  "When it works, reply with DONE and the sum.",
21
21
  ].join(" ");
22
- /** Checked after the agent stops: the file has 5000 primes ending in 48611, and the script prints the right sum. */
23
- const VERIFY = `test "$(wc -l < /tmp/work/primes.txt)" -eq 5000 && test "$(tail -n 1 /tmp/work/primes.txt)" = 48611 && python3 /tmp/work/primes.py | grep -q 114455259 && echo VERIFIED`;
22
+ /** Compare the saved file and the script's output to an independently computed prime sequence. */
23
+ export const AGENT_VERIFY = `python3 - <<'SRVERIFY'
24
+ import pathlib, re, subprocess, sys
25
+
26
+ work = pathlib.Path("/tmp/work")
27
+ flags = bytearray([1]) * 48612
28
+ flags[:2] = b"\\x00\\x00"
29
+ for i in range(2, 221):
30
+ if flags[i]:
31
+ flags[i * i::i] = bytes(len(flags[i * i::i]))
32
+ expected = [i for i, prime in enumerate(flags) if prime]
33
+ if len(expected) != 5000:
34
+ sys.exit("invalid verification fixture")
35
+
36
+ def valid_file():
37
+ file = work / "primes.txt"
38
+ if not file.is_file() or file.stat().st_size > 64000:
39
+ return False
40
+ return file.read_text().splitlines() == [str(p) for p in expected]
41
+
42
+ if not valid_file():
43
+ sys.exit("incorrect saved prime sequence")
44
+ (work / "primes.txt").unlink()
45
+ result = subprocess.run(
46
+ [sys.executable, str(work / "primes.py")], cwd=work,
47
+ capture_output=True, text=True, timeout=60, check=True,
48
+ )
49
+ if str(sum(expected)) not in re.findall(r"[0-9]+", result.stdout) or not valid_file():
50
+ sys.exit("incorrect regenerated prime sequence or sum")
51
+ print("VERIFIED")
52
+ SRVERIFY`;
24
53
  const STAT = `grep '^cpu' /proc/stat 2> /dev/null | tr '\\n' ';'`;
25
54
  async function gemini(model, apiKey, contents) {
26
55
  const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`, {
@@ -49,11 +78,12 @@ async function gemini(model, apiKey, contents) {
49
78
  return { content: j.candidates?.[0]?.content ?? { role: "model", parts: [] }, tokens: j.usageMetadata?.totalTokenCount ?? 0 };
50
79
  }
51
80
  /** One agent session on one provider. */
52
- async function session(router, id, model, apiKey, maxTurns) {
81
+ async function session(router, id, model, apiKey, maxTurns, onStarted) {
53
82
  const spec = { vcpu: DEFAULT_VCPU, memoryGb: DEFAULT_MEMORY_GB, timeoutMinutes: 15, cpuUtilization: 0.1 };
54
83
  const sized = { ...spec, ...fixedSize(id, spec) };
55
84
  const t0 = performance.now();
56
85
  const box = await router.create(sized, { provider: id, fallback: false, deadlineSeconds: 180 });
86
+ onStarted();
57
87
  const createMs = performance.now() - t0;
58
88
  try {
59
89
  await box.exec("mkdir -p /tmp/work");
@@ -90,7 +120,8 @@ async function session(router, id, model, apiKey, maxTurns) {
90
120
  }
91
121
  const sessionMs = performance.now() - s0;
92
122
  const b = (await box.exec(STAT)).stdout;
93
- const verified = (await box.exec(VERIFY, { timeoutSeconds: 120 })).stdout.includes("VERIFIED");
123
+ const verification = await box.exec(AGENT_VERIFY, { timeoutSeconds: 120 });
124
+ const verified = verification.exitCode === 0 && verification.stdout.trim() === "VERIFIED";
94
125
  const cpu = busyMs(a, b);
95
126
  const plausible = cpu !== undefined && cpu <= sized.vcpu * sessionMs * 1.1;
96
127
  return { verified, createMs, sessionMs, modelMs, turns: turns + 1, tokens, cpuMs: plausible ? cpu : undefined, coreMs: plausible ? maxCoreMs(a, b) : undefined, spec: sized };
@@ -107,15 +138,20 @@ export async function agentBench(opts) {
107
138
  const done = [];
108
139
  let failures = 0;
109
140
  let limited = 0;
141
+ let started = 0;
110
142
  for (let i = 0; i < opts.runs; i++) {
143
+ let ready = false;
111
144
  try {
112
- const s = await session(router, id, opts.model, opts.apiKey, opts.maxTurns ?? 15);
145
+ const s = await session(router, id, opts.model, opts.apiKey, opts.maxTurns ?? 15, () => {
146
+ ready = true;
147
+ started++;
148
+ });
113
149
  done.push(s);
114
150
  log(`${id} run ${i + 1}/${opts.runs}: ${s.verified ? "done" : "not done"} in ${(s.sessionMs / 1000).toFixed(1)} s, ${s.turns} turns`);
115
151
  }
116
152
  catch (err) {
117
153
  failures++;
118
- if (LIMITED_ERROR.test(err.message))
154
+ if (!ready && LIMITED_ERROR.test(err.message))
119
155
  limited++;
120
156
  log(`${id} run ${i + 1}/${opts.runs} failed: ${err.message.slice(0, 160)}`);
121
157
  }
@@ -128,6 +164,9 @@ export async function agentBench(opts) {
128
164
  rows.push({
129
165
  provider: id,
130
166
  runs: opts.runs - limited,
167
+ requested: opts.runs,
168
+ started,
169
+ size,
131
170
  ...(limited ? { limited } : {}),
132
171
  ok: ok.length,
133
172
  medianWallMs: m(done.map((s) => s.sessionMs)),
package/dist/bench.d.ts CHANGED
@@ -1,18 +1,30 @@
1
- import { Router } from "./router.js";
1
+ import { Router, type Size } from "./router.js";
2
2
  import { type TaskKind } from "./task.js";
3
3
  import type { ProviderId, SandboxSpec } from "./types.js";
4
4
  export interface BenchRow {
5
5
  provider: ProviderId;
6
6
  runs: number;
7
+ /** Create or first-command failures. Workload and cleanup outcomes are counted separately. */
7
8
  failures: number;
9
+ /** Shape selected by the router, before any provider-side allocation. */
10
+ size?: Size;
8
11
  medianCreateMs?: number;
9
12
  medianExecMs?: number;
13
+ /** Paired time from request to first successful command. */
14
+ medianReadyMs?: number;
10
15
  hourlyUsd: number;
11
16
  /**
12
17
  * Of the failures, how many the provider refused for a limit or quota on the benchmarking account (a rate limit,
13
18
  * a concurrency or service quota): the account's plan, not the provider's reliability. Success rates leave them out.
14
19
  */
15
20
  limited?: number;
21
+ createFailures?: number;
22
+ commandFailures?: number;
23
+ cleanupFailures?: number;
24
+ /** With a workload: requests whose workload finished and passed its checks. */
25
+ taskOk?: number;
26
+ /** Readiness time of the boxes where the workload succeeded. */
27
+ medianTaskReadyMs?: number;
16
28
  /** With `task`: median time of the standard task (src/task.ts), and of each of its phases. */
17
29
  medianTaskMs?: number;
18
30
  taskPhasesMs?: Record<string, number>;
package/dist/bench.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CATALOG, DEFAULT_MEMORY_GB, DEFAULT_VCPU, fittingSpec, fixedSize, hourlyCost } from "./catalog.js";
2
2
  import { loadBench, median, saveBench } from "./bench-store.js";
3
- import { Router } from "./router.js";
3
+ import { Router, sizeOf } from "./router.js";
4
4
  import { runTask, taskMs, taskUsd, TASKS } from "./task.js";
5
5
  /**
6
6
  * Cold start = time from create() call to a usable sandbox. Exec = round trip of `echo ok`.
@@ -27,10 +27,15 @@ export async function bench(opts) {
27
27
  const stored = loadBench(opts.benchFile);
28
28
  const rows = [];
29
29
  const one = async (id) => {
30
+ const shape = sized(id, spec);
30
31
  const createMs = [];
31
32
  const execMs = [];
33
+ const readyMs = [];
32
34
  const tasks = [];
33
- let failures = 0;
35
+ const taskReadyMs = [];
36
+ let createFailures = 0;
37
+ let commandFailures = 0;
38
+ let cleanupFailures = 0;
34
39
  let limited = 0;
35
40
  let lastError;
36
41
  for (let i = 0; i < runs; i++) {
@@ -38,17 +43,20 @@ export async function bench(opts) {
38
43
  let box;
39
44
  try {
40
45
  const t0 = performance.now();
41
- box = await router.create(sized(id, spec), { provider: id, fallback: false });
42
- createMs.push(Math.round(performance.now() - t0));
46
+ box = await router.create(shape, { provider: id, fallback: false });
43
47
  const t1 = performance.now();
44
48
  const r = await box.exec("echo ok");
45
49
  if (r.exitCode !== 0 || r.stdout.trim() !== "ok")
46
50
  throw new Error(`echo returned ${r.exitCode}: ${r.stdout}${r.stderr}`);
47
- execMs.push(Math.round(performance.now() - t1));
51
+ const done = performance.now();
52
+ const took = Math.max(1, Math.round(done - t0));
53
+ createMs.push(Math.max(1, Math.round(t1 - t0)));
54
+ execMs.push(Math.max(1, Math.round(done - t1)));
55
+ readyMs.push(took);
48
56
  if (kind) {
49
- // A failed task doesn't fail the run: the start time still counts, the task just has no time.
50
57
  try {
51
58
  tasks.push(await runTask(box, kind));
59
+ taskReadyMs.push(took);
52
60
  }
53
61
  catch (err) {
54
62
  lastError = `task: ${err.message.slice(0, 180)}`;
@@ -56,24 +64,38 @@ export async function bench(opts) {
56
64
  }
57
65
  }
58
66
  catch (err) {
59
- failures++;
60
67
  lastError = err.message.slice(0, 200);
61
- if (LIMITED_ERROR.test(lastError))
62
- limited++;
68
+ if (box)
69
+ commandFailures++;
70
+ else {
71
+ createFailures++;
72
+ if (LIMITED_ERROR.test(lastError))
73
+ limited++;
74
+ }
63
75
  }
64
76
  finally {
65
- await box?.kill().catch(() => { });
77
+ await box?.kill().catch((err) => {
78
+ cleanupFailures++;
79
+ log(`${id} cleanup failed: ${err.message.slice(0, 180)}`);
80
+ });
66
81
  }
67
82
  }
83
+ const failures = createFailures + commandFailures;
68
84
  stored[id] = { createMs, execMs, failures, at: new Date().toISOString() };
69
85
  rows.push({
70
86
  provider: id,
71
87
  runs,
72
88
  failures,
89
+ createFailures,
90
+ commandFailures,
91
+ cleanupFailures,
92
+ size: sizeOf(id, shape),
73
93
  medianCreateMs: median(createMs),
74
94
  medianExecMs: median(execMs),
75
- hourlyUsd: hourlyCost(id, sized(id, spec)),
95
+ medianReadyMs: median(readyMs),
96
+ hourlyUsd: hourlyCost(id, shape),
76
97
  ...(limited ? { limited } : {}),
98
+ ...(kind ? { taskOk: tasks.length, medianTaskReadyMs: median(taskReadyMs) } : {}),
77
99
  ...(tasks.length ? taskSummary(tasks, kind) : {}),
78
100
  lastError,
79
101
  });
@@ -107,14 +129,14 @@ function sized(id, spec) {
107
129
  export function benchMarkdown(rows) {
108
130
  const name = (id) => CATALOG.find((c) => c.id === id).name;
109
131
  const ms = (n) => (n === undefined ? "n/a" : `${n} ms`);
110
- const task = rows.some((r) => r.taskPhasesMs);
111
- const cost = (r) => r.medianTaskMs !== undefined && r.medianCreateMs !== undefined
112
- ? `$${taskUsd(r.provider, fittingSpec(r.provider), r.medianCreateMs, r.medianTaskMs, r.medianTaskCpuMs, 1, false, r.medianTaskMaxCoreMs).toFixed(6)}`
132
+ const task = rows.some((r) => r.taskOk !== undefined);
133
+ const cost = (r) => r.medianTaskMs !== undefined && r.medianTaskReadyMs !== undefined
134
+ ? `$${taskUsd(r.provider, r.size ?? fittingSpec(r.provider), r.medianTaskReadyMs, r.medianTaskMs, r.medianTaskCpuMs, 1, false, r.medianTaskMaxCoreMs).toFixed(6)}`
113
135
  : "n/a";
114
136
  const lines = [
115
- `| # | Provider | Cold start (median) | Exec round trip |${task ? " Task (median) | Task cost |" : ""} $/hr (list, size run) | Success |`,
116
- `|---|---|---|---|${task ? "---|---|" : ""}---|---|`,
117
- ...rows.map((r, i) => `| ${i + 1} | ${name(r.provider)} | ${ms(r.medianCreateMs)} | ${ms(r.medianExecMs)} |${task ? ` ${ms(r.medianTaskMs)} | ${cost(r)} |` : ""} $${r.hourlyUsd.toFixed(3)} | ${r.runs - r.failures}/${r.runs} |`),
137
+ `| # | Provider | Create (median) | Ready (median) | Exec round trip |${task ? " Task (median) | Est. task cost | Completed |" : ""} $/hr (list, size run) | Ready |`,
138
+ `|---|---|---|---|---|${task ? "---|---|---|" : ""}---|---|`,
139
+ ...rows.map((r, i) => `| ${i + 1} | ${name(r.provider)} | ${ms(r.medianCreateMs)} | ${ms(r.medianReadyMs)} | ${ms(r.medianExecMs)} |${task ? ` ${ms(r.medianTaskMs)} | ${cost(r)} | ${r.taskOk ?? 0}/${r.runs} |` : ""} $${r.hourlyUsd.toFixed(3)} | ${r.runs - r.failures}/${r.runs}${r.limited ? ` (${r.limited} refused)` : ""} |`),
118
140
  ];
119
141
  return lines.join("\n");
120
142
  }
package/dist/billing.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export const BILLED_VS_LIST = {
2
2
  agent37: { ratio: 0.998, date: "2026-11-14" },
3
- sail: { ratio: 0.495, date: "2026-11-06" },
4
3
  };
package/dist/burst.d.ts CHANGED
@@ -14,6 +14,16 @@ export interface BurstRow {
14
14
  ok: number;
15
15
  /** Of the failures, how many the provider refused for a limit or quota on this account (429, "limit", ...). */
16
16
  limited: number;
17
+ /** Shape selected by the router. Provider-side resources are not independently measured. */
18
+ size?: {
19
+ vcpu: number;
20
+ memoryGb: number;
21
+ };
22
+ /** Stages with a failure, with the limit refusals above included in create failures. */
23
+ createFailures?: number;
24
+ commandFailures?: number;
25
+ taskFailures?: number;
26
+ cleanupFailures?: number;
17
27
  /** Time to interactive across the ready ones: create plus first command, from the burst's start. */
18
28
  p50Ms?: number;
19
29
  p95Ms?: number;
package/dist/burst.js CHANGED
@@ -25,42 +25,53 @@ export async function burst(opts) {
25
25
  log(`${id}: ${opts.n} at once${kind ? `, each running the ${kind} job` : ""}`);
26
26
  const spec = { ...base, ...fixedSize(id, base) };
27
27
  const t0 = performance.now();
28
+ let cleanupFailures = 0;
28
29
  const results = await Promise.all(Array.from({ length: opts.n }, async () => {
29
30
  let box;
31
+ let stage = "create";
30
32
  try {
31
33
  box = await router.create(spec, { provider: id, fallback: false, deadlineSeconds: 240 });
32
- const createMs = performance.now() - t0;
34
+ stage = "command";
33
35
  const r = await box.exec("echo ok");
34
36
  if (r.exitCode !== 0 || r.stdout.trim() !== "ok")
35
37
  throw new Error(`echo returned ${r.exitCode}`);
36
38
  const tti = performance.now() - t0;
39
+ stage = "task";
37
40
  const job = kind ? await runTask(box, kind) : undefined;
38
- return { ok: true, tti, createMs, job, done: performance.now() - t0 };
41
+ return { ok: true, tti, job, done: performance.now() - t0 };
39
42
  }
40
43
  catch (err) {
41
- return { ok: false, error: err.message, done: performance.now() - t0 };
44
+ return { ok: false, stage, error: err.message, done: performance.now() - t0 };
42
45
  }
43
46
  finally {
44
- await box?.kill().catch(() => { });
47
+ await box?.kill().catch((err) => {
48
+ cleanupFailures++;
49
+ log(`${id} cleanup failed: ${err.message.slice(0, 180)}`);
50
+ });
45
51
  }
46
52
  }));
47
53
  const ok = results.filter((r) => r.ok);
48
- const ttis = ok.map((r) => Math.round(r.tti)).sort((a, b) => a - b);
54
+ const ttis = ok.map((r) => Math.max(1, Math.round(r.tti))).sort((a, b) => a - b);
49
55
  const jobs = ok.map((r) => (r.job ? taskMs(r.job.ms) : undefined)).filter((n) => n !== undefined).sort((a, b) => a - b);
50
56
  const size = fittingSpec(id);
51
57
  const ratio = BILLED_VS_LIST[id]?.ratio ?? 1;
52
58
  const usd = ok.reduce((sum, r) => sum +
53
- taskUsd(id, { ...size, ...(spec.cpuUtilization ? { cpuUtilization: spec.cpuUtilization } : {}) }, r.createMs, r.job ? taskMs(r.job.ms) : 0, r.job?.cpuMs, ratio, false, r.job?.maxCoreMs), 0);
59
+ taskUsd(id, { ...size, ...(spec.cpuUtilization ? { cpuUtilization: spec.cpuUtilization } : {}) }, r.tti, r.job ? taskMs(r.job.ms) : 0, r.job?.cpuMs, ratio, false, r.job?.maxCoreMs), 0);
54
60
  const failed = results.filter((r) => !r.ok);
55
61
  rows.push({
56
62
  provider: id,
57
63
  n: opts.n,
58
64
  ok: ok.length,
59
- limited: failed.filter((f) => LIMIT.test(f.error)).length,
65
+ limited: failed.filter((f) => f.stage === "create" && LIMIT.test(f.error)).length,
66
+ size,
67
+ createFailures: failed.filter((f) => f.stage === "create").length,
68
+ commandFailures: failed.filter((f) => f.stage === "command").length,
69
+ taskFailures: failed.filter((f) => f.stage === "task").length,
70
+ cleanupFailures,
60
71
  p50Ms: percentile(ttis, 0.5),
61
72
  p95Ms: percentile(ttis, 0.95),
62
73
  p99Ms: percentile(ttis, 0.99),
63
- wallMs: Math.round(Math.max(...results.map((r) => r.done))),
74
+ wallMs: Math.max(1, Math.round(Math.max(...results.map((r) => r.done)))),
64
75
  ...(jobs.length ? { jobP50Ms: percentile(jobs, 0.5) } : {}),
65
76
  ...(ok.length ? { usd: Math.round(usd * 1e6) / 1e6 } : {}),
66
77
  });
@@ -132,15 +143,15 @@ export async function spreadBurst(opts) {
132
143
  continue;
133
144
  }
134
145
  let box;
146
+ const attemptStarted = performance.now();
135
147
  try {
136
148
  box = await router.create({ ...base, ...fixedSize(id, base) }, { provider: id, fallback: false, deadlineSeconds: 240 });
137
- const createMs = performance.now() - t0;
138
149
  const r = await box.exec("echo ok");
139
150
  if (r.exitCode !== 0 || r.stdout.trim() !== "ok")
140
151
  throw new Error(`echo returned ${r.exitCode}`);
141
152
  const s = stats.get(id);
142
153
  s.ok++;
143
- s.createMs.push(createMs);
154
+ s.createMs.push(performance.now() - attemptStarted);
144
155
  if (moved)
145
156
  s.spilledIn++;
146
157
  return { ok: true, tti: performance.now() - t0, done: performance.now() - t0 };
package/dist/catalog.d.ts CHANGED
@@ -12,6 +12,12 @@ export interface ProviderInfo {
12
12
  incrementSeconds?: number;
13
13
  /** A fixed charge per sandbox created, USD, on top of running time. */
14
14
  perSandboxUsd?: number;
15
+ /** Start fees above a provider's included allowance. Estimates exclude these account-specific charges. */
16
+ conditionalStartFee?: {
17
+ minUsd: number;
18
+ maxUsd: number;
19
+ source: string;
20
+ };
15
21
  /**
16
22
  * Active-CPU billing only: the share of the allocated CPU billed even when idle (Tensorlake bills at
17
23
  * least 20%). Default 0.
@@ -43,6 +49,8 @@ export interface ProviderInfo {
43
49
  limits: {
44
50
  maxVcpu: number;
45
51
  maxMemoryGb: number;
52
+ maxPorts?: number;
53
+ reservedPorts?: number[];
46
54
  };
47
55
  /**
48
56
  * The size every sandbox gets unless a custom image (template, snapshot) is passed, whatever
@@ -286,6 +294,11 @@ export declare function cloudflareInstance(vcpu: number, memoryGb: number): {
286
294
  readonly vcpu: 4;
287
295
  readonly memoryGb: 12;
288
296
  };
297
+ /** The Vercel adapter allocates enough vCPUs to provide the requested RAM, with 2 GB per vCPU. */
298
+ export declare function vercelSandboxSize(spec: SandboxSpec): {
299
+ vcpu: number;
300
+ memoryGb: number;
301
+ };
289
302
  /** How a provider turns running time into a bill: minimum, rounding and fixed per-sandbox charge. */
290
303
  export declare function billingRules(id: ProviderId): {
291
304
  minSeconds: number;
package/dist/catalog.js CHANGED
@@ -45,7 +45,7 @@ const ENTRIES = [
45
45
  source: "https://docs.docker.com/engine/",
46
46
  checked: "2026-11-04",
47
47
  },
48
- capabilities: ["pause", "custom-image"],
48
+ capabilities: ["pause", "custom-image", "ports"],
49
49
  limits: { maxVcpu: 64, maxMemoryGb: 256 },
50
50
  local: true,
51
51
  credentials: [],
@@ -76,7 +76,7 @@ const ENTRIES = [
76
76
  source: "https://e2b.dev/pricing",
77
77
  checked: "2026-11-04",
78
78
  },
79
- capabilities: ["pause", "custom-image"],
79
+ capabilities: ["pause", "custom-image", "ports", "background"],
80
80
  limits: { maxVcpu: 8, maxMemoryGb: 8 },
81
81
  // The default template; a bigger size needs a template built with --cpu-count / --memory-mb.
82
82
  defaultSize: { vcpu: 2, memoryGb: 0.5, measured: "2026-11-06" },
@@ -93,7 +93,7 @@ const ENTRIES = [
93
93
  source: "https://www.daytona.io/pricing",
94
94
  checked: "2026-11-17",
95
95
  },
96
- capabilities: ["pause", "custom-image"],
96
+ capabilities: ["pause", "custom-image", "ports", "background"],
97
97
  limits: { maxVcpu: 4, maxMemoryGb: 8 },
98
98
  // The default snapshot; resources only apply when creating from an image (image.daytona).
99
99
  defaultSize: { vcpu: 1, memoryGb: 1, measured: "2026-11-06" },
@@ -112,7 +112,7 @@ const ENTRIES = [
112
112
  source: "https://modal.com/pricing",
113
113
  checked: "2026-11-17",
114
114
  },
115
- capabilities: ["gpu", "custom-image"],
115
+ capabilities: ["gpu", "custom-image", "ports"],
116
116
  limits: { maxVcpu: 64, maxMemoryGb: 256 },
117
117
  credentials: [["MODAL_TOKEN_ID", "MODAL_TOKEN_SECRET"]],
118
118
  docs: "https://modal.com/docs/guide/sandbox",
@@ -130,8 +130,8 @@ const ENTRIES = [
130
130
  source: "https://vercel.com/docs/vercel-sandbox/pricing",
131
131
  checked: "2026-11-05",
132
132
  },
133
- capabilities: [],
134
- limits: { maxVcpu: 8, maxMemoryGb: 16 },
133
+ capabilities: ["ports", "background"],
134
+ limits: { maxVcpu: 8, maxMemoryGb: 16, maxPorts: 15 },
135
135
  credentials: [["VERCEL_OIDC_TOKEN"], ["VERCEL_TOKEN", "VERCEL_TEAM_ID", "VERCEL_PROJECT_ID"]],
136
136
  docs: "https://vercel.com/docs/vercel-sandbox",
137
137
  },
@@ -176,9 +176,9 @@ const ENTRIES = [
176
176
  source: "https://blaxel.ai/pricing",
177
177
  checked: "2026-11-04",
178
178
  },
179
- capabilities: ["custom-image"],
179
+ capabilities: ["custom-image", "ports", "background"],
180
180
  // Self-serve caps are per-tier and not published; these are conservative.
181
- limits: { maxVcpu: 8, maxMemoryGb: 16 },
181
+ limits: { maxVcpu: 8, maxMemoryGb: 16, reservedPorts: [80, 443, 8080] },
182
182
  credentials: [["BL_API_KEY", "BL_WORKSPACE"]],
183
183
  docs: "https://docs.blaxel.ai/Sandboxes/Overview",
184
184
  noBenchmarks: {
@@ -226,8 +226,9 @@ ENTRIES.push({
226
226
  vcpuHour: 0.009,
227
227
  gbHour: 0,
228
228
  note: "fixed sizes billed per second ($0.018/h for 2 vCPU / 4 GB up to $0.20/h for 16 / 32); needs a plan from $20/mo, paid back as VM time",
229
+ conditionalStartFee: { minUsd: 0.03, maxUsd: 0.07, source: "https://docs.boat.dev/limits.md#extra-starts" },
229
230
  source: "https://docs.boat.dev/pricing.md",
230
- checked: "2026-11-13",
231
+ checked: "2026-11-17",
231
232
  },
232
233
  // "pause" here is Boat's stop: the disk is kept, running processes end.
233
234
  capabilities: ["pause", "custom-image"],
@@ -273,9 +274,9 @@ ENTRIES.push({
273
274
  source: "https://hopx.ai/pricing",
274
275
  checked: "2026-11-04",
275
276
  },
276
- capabilities: ["pause", "custom-image"],
277
+ capabilities: ["pause", "custom-image", "ports"],
277
278
  // HOPX takes no size at create; capped at the default size so bigger requests go elsewhere.
278
- limits: { maxVcpu: 2, maxMemoryGb: 4 },
279
+ limits: { maxVcpu: 2, maxMemoryGb: 4, reservedPorts: [7777] },
279
280
  credentials: [["HOPX_API_KEY"]],
280
281
  docs: "https://docs.hopx.ai",
281
282
  }, {
@@ -479,7 +480,7 @@ ENTRIES.push({
479
480
  source: "https://deno.com/sandbox",
480
481
  checked: "2026-11-17",
481
482
  },
482
- capabilities: ["custom-image"],
483
+ capabilities: ["custom-image", "ports"],
483
484
  limits: { maxVcpu: 2, maxMemoryGb: 4 },
484
485
  credentials: [["DENO_DEPLOY_TOKEN"]],
485
486
  docs: "https://docs.deno.com/sandbox/",
@@ -561,7 +562,7 @@ ENTRIES.push({
561
562
  source: "https://docs.novita.ai/guides/sandbox-pricing",
562
563
  checked: "2026-11-04",
563
564
  },
564
- capabilities: ["pause", "custom-image"],
565
+ capabilities: ["pause", "custom-image", "ports", "background"],
565
566
  limits: { maxVcpu: 8, maxMemoryGb: 8 },
566
567
  credentials: [["NOVITA_API_KEY"]],
567
568
  docs: "https://docs.novita.ai/guides/sandbox-overview",
@@ -675,6 +676,13 @@ export const BOAT_SIZES = [
675
676
  export function cloudflareInstance(vcpu, memoryGb) {
676
677
  return CLOUDFLARE_INSTANCES.find((t) => t.vcpu >= vcpu && t.memoryGb >= memoryGb) ?? CLOUDFLARE_INSTANCES[CLOUDFLARE_INSTANCES.length - 1];
677
678
  }
679
+ /** The Vercel adapter allocates enough vCPUs to provide the requested RAM, with 2 GB per vCPU. */
680
+ export function vercelSandboxSize(spec) {
681
+ const needed = Math.max(spec.vcpu ?? DEFAULT_VCPU, (spec.memoryGb ?? DEFAULT_MEMORY_GB) / 2);
682
+ // Vercel supports one vCPU or an even vCPU count.
683
+ const vcpu = Math.min(8, needed <= 1 ? 1 : Math.ceil(needed / 2) * 2);
684
+ return { vcpu, memoryGb: vcpu * 2 };
685
+ }
678
686
  /** How a provider turns running time into a bill: minimum, rounding and fixed per-sandbox charge. */
679
687
  export function billingRules(id) {
680
688
  const p = CATALOG.find((c) => c.id === id)?.pricing;
@@ -720,9 +728,10 @@ function fullHourlyCost(id, spec = {}) {
720
728
  return fixed.vcpu * pricing.vcpuHour + fixed.memoryGb * pricing.gbHour;
721
729
  const vcpu = spec.vcpu ?? DEFAULT_VCPU;
722
730
  let mem = spec.memoryGb ?? DEFAULT_MEMORY_GB;
723
- // Vercel fixes memory at 2 GB per vCPU.
724
- if (id === "vercel")
725
- mem = Math.max(mem, vcpu * 2);
731
+ if (id === "vercel") {
732
+ const size = vercelSandboxSize(spec);
733
+ return size.vcpu * pricing.vcpuHour + size.memoryGb * pricing.gbHour;
734
+ }
726
735
  // Blaxel sizes by memory, about 2 GB per core.
727
736
  if (id === "blaxel")
728
737
  mem = Math.max(mem, vcpu * 2);
@@ -800,6 +809,8 @@ export function cpuHourlyAtFull(id, spec = {}) {
800
809
  return fixed.vcpu * p.pricing.vcpuHour;
801
810
  const vcpu = spec.vcpu ?? DEFAULT_VCPU;
802
811
  const mem = spec.memoryGb ?? DEFAULT_MEMORY_GB;
812
+ if (id === "vercel")
813
+ return vercelSandboxSize(spec).vcpu * p.pricing.vcpuHour;
803
814
  if (id === "cloudflare")
804
815
  return cloudflareInstance(vcpu, mem).vcpu * p.pricing.vcpuHour;
805
816
  if (id === "upstash")
@@ -818,9 +829,16 @@ export function unfit(id, spec, require = []) {
818
829
  const needs = new Set(require);
819
830
  if (spec.gpu)
820
831
  needs.add("gpu");
832
+ if (spec.ports?.length)
833
+ needs.add("ports");
821
834
  for (const c of needs)
822
835
  if (!p.capabilities.includes(c))
823
836
  return `no ${c} support`;
837
+ if (spec.ports?.length && p.limits.maxPorts !== undefined && spec.ports.length > p.limits.maxPorts)
838
+ return `max ${p.limits.maxPorts} preview ports`;
839
+ const reserved = spec.ports?.find((port) => p.limits.reservedPorts?.includes(port));
840
+ if (reserved !== undefined)
841
+ return `port ${reserved} is reserved by the provider`;
824
842
  if ((spec.vcpu ?? DEFAULT_VCPU) > p.limits.maxVcpu)
825
843
  return `max ${p.limits.maxVcpu} vCPU`;
826
844
  if ((spec.memoryGb ?? DEFAULT_MEMORY_GB) > p.limits.maxMemoryGb)