@sandboxrouter/sdk 0.11.0 → 0.13.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.
package/dist/cli.js CHANGED
@@ -2,10 +2,11 @@
2
2
  import { parseArgs } from "node:util";
3
3
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { platform, arch } from "node:os";
5
- import { ACCOUNT_ERROR, bench, benchMarkdown, NETWORK_ERROR } from "./bench.js";
5
+ import { bench, benchMarkdown, NETWORK_ERROR } from "./bench.js";
6
6
  import { TASKS } from "./task.js";
7
7
  import { submitReport } from "./submit.js";
8
8
  import { burst, spreadBurst } from "./burst.js";
9
+ import { compare } from "./compare.js";
9
10
  import { agentBench, AGENT_TASK_VERSION } from "./agent-bench.js";
10
11
  /** Errors that mean the network between here and the provider failed, not the provider. */
11
12
  import { costMarkdown, costRun, settle } from "./cost.js";
@@ -29,6 +30,9 @@ Usage:
29
30
  [--reuse] [--provider a,b] [--json]
30
31
  which provider for a job, from the published benchmarks: per successful run, with start
31
32
  times under load for --count 10 and up; --provider limits it to the ones you name
33
+ sandboxrouter compare "<cmd>" [--setup "<cmd>"] [--runs 3] [--provider a,b] [--seconds 600] [--json]
34
+ your own workload on each provider: the same setup and command in a new sandbox, with how
35
+ often it worked, start/setup/command time and the estimated cost; failures are counted
32
36
  sandboxrouter run "<cmd>" [spec flags] [route flags] [--keep]
33
37
  sandboxrouter check --provider ID[,ID] | --all [--json] [--save [dir]] [--retry] [--out FILE] [--by GITHUB_USER]
34
38
  test providers for real: exec, env, UTF-8, streaming, files, timeout, pause,
@@ -99,6 +103,8 @@ const { values, positionals } = parseArgs({
99
103
  priority: { type: "string" },
100
104
  reuse: { type: "boolean" },
101
105
  spread: { type: "boolean" },
106
+ setup: { type: "string" },
107
+ seconds: { type: "string" },
102
108
  even: { type: "boolean" },
103
109
  parallel: { type: "string" },
104
110
  n: { type: "string" },
@@ -197,6 +203,27 @@ async function main() {
197
203
  ].join("\n"));
198
204
  return;
199
205
  }
206
+ if (cmd === "compare") {
207
+ const command = rest[0];
208
+ if (!command)
209
+ throw new RouterError('usage: sandboxrouter compare "<cmd>" [--setup "<cmd>"] [--runs 3] [--provider a,b]');
210
+ const ids = providers ?? router.registered().filter((id) => router.isConfigured(id));
211
+ const rows = await compare({ router, providers: ids, command, setup: values.setup, runs: num(values.runs), timeoutSeconds: num(values.seconds), parallel: num(values.parallel), onProgress: (m) => console.error(m) });
212
+ if (values.json)
213
+ return console.log(JSON.stringify(rows, null, 2));
214
+ const s = (v) => (v === undefined ? "n/a" : `${(v / 1000).toFixed(1)} s`);
215
+ const usd = (v) => (v === undefined ? "n/a" : v >= 0.01 ? `$${v.toFixed(3)}` : `$${v.toPrecision(2)}`);
216
+ console.log(`\nsandboxrouter compare: ${JSON.stringify(command)}${values.setup ? `, after setup ${JSON.stringify(values.setup)}` : ""}\n`);
217
+ console.log("| Provider | Worked | Start | Setup | Command | Total | Est. cost per run |\n|---|---|---|---|---|---|---|");
218
+ for (const r of rows) {
219
+ console.log(`| ${r.provider} | ${r.ok}/${r.runs} | ${s(r.medianStartMs)} | ${values.setup ? s(r.medianSetupMs) : "-"} | ${s(r.medianCommandMs)} | ${s(r.medianTotalMs)} | ${usd(r.estimatedUsd)}${r.billMeasured ? " (bill measured)" : ""} |`);
220
+ }
221
+ const bad = rows.filter((r) => r.error);
222
+ if (bad.length)
223
+ console.log(`\nFailures:\n${bad.map((r) => `- ${r.provider}: ${r.startFailed} didn't start, ${r.setupFailed} failed setup, ${r.commandFailed} failed the command. ${r.error}`).join("\n")}`);
224
+ console.log("\nTimes are measured medians of the runs that worked. Costs are estimates from each provider's billing rules for the sandbox's whole life (start, setup, command), not bills.");
225
+ return;
226
+ }
200
227
  if (cmd === "recommend") {
201
228
  const jobs = ["start", "short", "long", "python", "download", "agent", "repo"];
202
229
  const priorities = ["value", "cost", "speed"];
@@ -227,13 +254,18 @@ async function main() {
227
254
  if (values.json)
228
255
  return console.log(JSON.stringify({ ...q, candidates: undefined }, null, 2));
229
256
  const rules = [
230
- q.minimumSeconds ? `at least ${q.minimumSeconds} s billed` : "",
257
+ q.minimumSeconds ? `at least ${q.minimumSeconds} s billed${q.minimumCovers === "memory" ? " for memory" : ""}` : "",
231
258
  q.billedInSecondsOf ? `billed in steps of ${q.billedInSecondsOf} s` : "",
232
259
  q.perSandboxUsd ? `$${q.perSandboxUsd} per sandbox` : "",
233
260
  ].filter(Boolean);
234
261
  console.log(`${q.provider}, ${q.size.vcpu} vCPU / ${q.size.memoryGb} GB`);
235
262
  console.log(`price $${q.hourlyUsd.toFixed(4)}/hr${rules.length ? ` (${rules.join(", ")})` : ""}`);
236
263
  console.log(`this run ${q.runSeconds} s ≈ $${q.estimatedUsd.toFixed(6)} ($${q.runHourlyUsd.toFixed(4)}/hr)`);
264
+ const extra = q.conditionalStartFee;
265
+ if (extra)
266
+ console.log(`Excludes $${extra.minUsd}–$${extra.maxUsd} per start above your allowance. ${extra.source}`);
267
+ if (q.excludesGpuCost)
268
+ console.log("The estimate excludes GPU charges. Check your provider's GPU rates.");
237
269
  const next = q.candidates.filter((c) => !c.skip && c.provider !== q.provider).slice(0, 3).map((c) => c.provider);
238
270
  if (next.length)
239
271
  console.log(`fallback ${next.join(" → ")}`);
@@ -255,7 +287,10 @@ async function main() {
255
287
  // With --expect, what that run would be billed (minimum charge and fee included): what it's ranked by.
256
288
  const hours = runHours(spec);
257
289
  const run = spec.expectedSeconds ? ` ≈ $${(rankUsd(c, hours) * hours).toFixed(6)} for ${Math.round(hours * 3600)} s` : "";
258
- const cols = [`$${c.estimatedHourlyUsd.toFixed(4)}/hr${list}${fee}${run}`, size, speed, tested].filter(Boolean).join(" ");
290
+ const extra = c.conditionalStartFee;
291
+ const feeNote = extra ? `excludes $${extra.minUsd}–$${extra.maxUsd} per start above allowance` : "";
292
+ const gpuNote = c.excludesGpuCost ? "excludes GPU charges" : "";
293
+ const cols = [`$${c.estimatedHourlyUsd.toFixed(4)}/hr${list}${fee}${run}`, size, speed, tested, feeNote, gpuNote].filter(Boolean).join(" ");
259
294
  console.log(`${mark} ${c.provider.padEnd(11)} ${cols}${c.skip ? ` (skipped: ${c.skip})` : ""}`);
260
295
  }
261
296
  return;
@@ -274,7 +309,7 @@ async function main() {
274
309
  process.once("SIGINT", stop);
275
310
  for (const a of sbx.attempts.filter((a) => !a.ok))
276
311
  console.error(`! ${a.provider} failed, fell back: ${a.error}`);
277
- console.error(`> ${sbx.id} on ${sbx.provider} (~$${sbx.estimatedHourlyUsd}/hr, started in ${sbx.attempts.at(-1)?.ms} ms)`);
312
+ console.error(`> ${sbx.id} on ${sbx.provider} (~$${sbx.estimatedHourlyUsd}/hr${spec.gpu ? " excluding GPU charges" : ""}, started in ${sbx.attempts.at(-1)?.ms} ms)`);
278
313
  try {
279
314
  const r = await sbx.exec(command, {
280
315
  timeoutSeconds: 600,
@@ -294,9 +329,15 @@ async function main() {
294
329
  if (cmd === "check") {
295
330
  const ids = values.all ? router.registered().filter((id) => router.isConfigured(id)) : providers;
296
331
  if (!ids?.length) {
297
- if (values.all)
298
- return console.log("No providers configured: set at least one provider's keys (sandboxrouter providers lists them).");
299
- throw new RouterError("usage: sandboxrouter check --provider <id>[,<id>...] | --all");
332
+ if (!values.all)
333
+ throw new RouterError("usage: sandboxrouter check --provider <id>[,<id>...] | --all");
334
+ console.error("No providers configured: set at least one provider's keys (sandboxrouter providers lists them).");
335
+ if (values.out)
336
+ writeFileSync(values.out, "[]\n");
337
+ if (values.json)
338
+ console.log("[]");
339
+ process.exitCode = 1;
340
+ return;
300
341
  }
301
342
  const version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
302
343
  const saveDir = values.save ? (rest[0] ?? "results/conformance") : undefined;
@@ -332,16 +373,16 @@ async function main() {
332
373
  writeFileSync(`${saveDir}/${p}.json`, JSON.stringify(saved, null, 2) + "\n");
333
374
  }
334
375
  }
376
+ const ran = reports.filter((r) => !r.inconclusive);
335
377
  if (values.out)
336
378
  writeFileSync(values.out, JSON.stringify(reports, null, 2) + "\n");
337
379
  if (values.json)
338
380
  console.log(JSON.stringify(reports, null, 2));
339
381
  else {
340
- const unpaid = reports.filter((r) => r.inconclusive).length;
341
- const ran = reports.length - unpaid;
342
- console.log(`\n${reports.filter((r) => r.ok).length}/${ran} passed${unpaid ? `; ${unpaid} not run (the account can't pay, or the provider's package isn't installed)` : ""}`);
382
+ const skipped = reports.length - ran.length;
383
+ console.log(`\n${ran.filter((r) => r.ok).length}/${ran.length} passed${skipped ? `; ${skipped} not run (the account can't pay, or the provider's package isn't installed)` : ""}`);
343
384
  }
344
- if (reports.some((r) => !r.ok && !r.inconclusive))
385
+ if (!ran.length || ran.some((r) => !r.ok))
345
386
  process.exitCode = 1;
346
387
  return;
347
388
  }
@@ -378,10 +419,22 @@ async function main() {
378
419
  }
379
420
  if (cmd === "agentbench") {
380
421
  const apiKey = process.env.GEMINI_API_KEY;
381
- if (!apiKey)
382
- return console.error("agentbench needs GEMINI_API_KEY (it stays on this machine; only shell commands reach the sandbox)");
422
+ if (!apiKey) {
423
+ console.error("agentbench needs GEMINI_API_KEY (it stays on this machine; only shell commands reach the sandbox)");
424
+ if (values.json)
425
+ console.log("[]");
426
+ process.exitCode = 1;
427
+ return;
428
+ }
383
429
  const model = values.model ?? "gemini-3.5-flash";
384
430
  const ids = providers ?? router.registered().filter((id) => router.isConfigured(id));
431
+ if (!ids.length) {
432
+ console.error("agentbench has no configured providers (sandboxrouter providers lists them).");
433
+ if (values.json)
434
+ console.log("[]");
435
+ process.exitCode = 1;
436
+ return;
437
+ }
385
438
  const rows = await agentBench({ router, providers: ids, runs: num(values.runs) ?? 5, apiKey, model, parallel: num(values.parallel), onProgress: (m) => console.error(m) });
386
439
  if (values.json)
387
440
  return console.log(JSON.stringify(rows, null, 2));
@@ -389,14 +442,8 @@ async function main() {
389
442
  console.log("| Provider | Done right | Wall | Waiting on model | Sandbox CPU | Turns | Sandbox cost |\n|---|---|---|---|---|---|---|");
390
443
  const s = (v) => (v === undefined ? "n/a" : `${(v / 1000).toFixed(1)} s`);
391
444
  for (const r of rows)
392
- console.log(`| ${r.provider} | ${r.ok}/${r.runs} | ${s(r.medianWallMs)} | ${s(r.medianModelMs)} | ${s(r.medianCpuMs)} | ${r.medianTurns ?? "n/a"} | ${r.medianUsd === undefined ? "n/a" : `$${r.medianUsd.toFixed(6)}`} |`);
445
+ console.log(`| ${r.provider} | ${r.ok}/${r.requested ?? r.runs}${r.limited ? ` (${r.limited} refused)` : ""} | ${s(r.medianWallMs)} | ${s(r.medianModelMs)} | ${s(r.medianCpuMs)} | ${r.medianTurns ?? "n/a"} | ${r.medianUsd === undefined ? "n/a" : `$${r.medianUsd.toFixed(6)}`} |`);
393
446
  if (values.share || values.submit) {
394
- const started = rows.filter((r) => r.medianWallMs !== undefined);
395
- if (rows.length - started.length >= 3) {
396
- console.error(`\nnot writing a report: ${rows.length - started.length} providers never started a session, which looks like this machine lost its connection. Run it again.`);
397
- process.exitCode = 1;
398
- return;
399
- }
400
447
  const version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
401
448
  const report = {
402
449
  tool: "sandboxrouter-agent",
@@ -409,7 +456,7 @@ async function main() {
409
456
  runs: num(values.runs) ?? 5,
410
457
  node: process.version,
411
458
  platform: `${platform()}-${arch()}`,
412
- rows: started.filter((r) => benchmarksPublishable(r.provider)),
459
+ rows: rows.filter((r) => benchmarksPublishable(r.provider)),
413
460
  };
414
461
  const file = values.out ?? `sandboxrouter-agent-${report.date.slice(0, 10)}-${Math.random().toString(36).slice(2, 8)}.json`;
415
462
  writeFileSync(file, JSON.stringify(report, null, 2) + "\n");
@@ -437,7 +484,7 @@ async function main() {
437
484
  // One burst over all of them: round-robin, and a provider that says no hands its sandboxes to the next.
438
485
  const r = await spreadBurst({ router, providers: ids, n, weights: values.even ? "even" : undefined, onProgress: (m) => console.error(m) });
439
486
  if (values.out)
440
- writeFileSync(values.out, JSON.stringify({ tool: "sandboxrouter-spread", date: new Date().toISOString(), label: values.label, ...r }, null, 2) + "\n");
487
+ writeFileSync(values.out, JSON.stringify({ tool: "sandboxrouter-spread", version: JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version, date: new Date().toISOString(), label: values.label, by: values.by, ...r }, null, 2) + "\n");
441
488
  if (values.json)
442
489
  return console.log(JSON.stringify(r, null, 2));
443
490
  const ms = (v) => (v === undefined ? "n/a" : `${v} ms`);
@@ -453,14 +500,12 @@ async function main() {
453
500
  if (values.json)
454
501
  return console.log(JSON.stringify(rows, null, 2));
455
502
  console.log(`\nsandboxrouter burst: ${n} at once${job ? `, each running the ${job} job` : ""}\n`);
456
- console.log("| Provider | Started | p50 | p95 | p99 | All done | Burst cost |\n|---|---|---|---|---|---|---|");
503
+ console.log(`| Provider | ${job ? "Completed jobs" : "Ready"} | p50 ready | p95 ready | p99 ready | Last outcome | Est. cost of successes |\n|---|---|---|---|---|---|---|`);
457
504
  for (const r of rows) {
458
505
  const ms = (v) => (v === undefined ? "n/a" : `${v} ms`);
459
506
  console.log(`| ${r.provider} | ${r.ok}/${r.n}${r.limited ? ` (${r.limited} limited)` : ""} | ${ms(r.p50Ms)} | ${ms(r.p95Ms)} | ${ms(r.p99Ms)} | ${(r.wallMs / 1000).toFixed(1)} s | ${r.usd === undefined ? "n/a" : `$${r.usd.toFixed(4)}`} |`);
460
507
  }
461
508
  if (values.share || values.submit) {
462
- // As with bench: nothing from a run where this machine lost its connection, and no provider that never answered.
463
- const shared = rows.filter((r) => r.ok > 0 || r.limited > 0);
464
509
  const version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
465
510
  const report = {
466
511
  tool: "sandboxrouter-burst",
@@ -472,13 +517,8 @@ async function main() {
472
517
  ...(job ? { task: TASKS[job].version } : {}),
473
518
  node: process.version,
474
519
  platform: `${platform()}-${arch()}`,
475
- rows: shared.filter((r) => benchmarksPublishable(r.provider)),
520
+ rows: rows.filter((r) => benchmarksPublishable(r.provider)),
476
521
  };
477
- if (rows.length - shared.length >= 3) {
478
- console.error(`\nnot writing a report: ${rows.length - shared.length} providers started nothing, which looks like this machine lost its connection. Run it again.`);
479
- process.exitCode = 1;
480
- return;
481
- }
482
522
  const file = values.out ?? `sandboxrouter-burst-${report.date.slice(0, 10)}-${Math.random().toString(36).slice(2, 8)}.json`;
483
523
  writeFileSync(file, JSON.stringify(report, null, 2) + "\n");
484
524
  if (values.submit) {
@@ -525,12 +565,7 @@ async function main() {
525
565
  }
526
566
  else if (values.share || values.submit) {
527
567
  const version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
528
- // A provider whose every run failed on the submitter's own account (bad key, no credit, a limit hit) says
529
- // nothing about the provider: leave it out of what's shared, and say so.
530
- const account = rows.filter((r) => r.failures === r.runs && r.lastError && ACCOUNT_ERROR.test(r.lastError));
531
- if (account.length)
532
- console.error(`\nleft out of the shared report, every run failed on your account: ${account.map((r) => r.provider).join(", ")}`);
533
- const report = makeReport(rows.filter((r) => !account.includes(r)), { version, runs: rows[0].runs, spec: { ...spec, vcpu: spec.vcpu ?? DEFAULT_VCPU, memoryGb: spec.memoryGb ?? DEFAULT_MEMORY_GB }, label: values.label, by, task: values.task ? TASKS[job].version : undefined });
568
+ const report = makeReport(rows, { version, runs: rows[0].runs, spec: { ...spec, vcpu: spec.vcpu ?? DEFAULT_VCPU, memoryGb: spec.memoryGb ?? DEFAULT_MEMORY_GB }, label: values.label, by, task: values.task ? TASKS[job].version : undefined });
534
569
  const left = rows.filter((r) => !benchmarksPublishable(r.provider)).map((r) => r.provider);
535
570
  if (left.length)
536
571
  console.log(`\nleft out of the shared report: ${left.join(", ")} (their terms don't allow publishing benchmarks)`);
@@ -0,0 +1,48 @@
1
+ import { Router } from "./router.js";
2
+ import type { ProviderId, SandboxSpec } from "./types.js";
3
+ /**
4
+ * Your own workload on several providers: the same setup and command in a new sandbox on each, a few times.
5
+ * Times are measured; the cost is an estimate from each provider's billing rules for the time the sandbox lived
6
+ * (start, setup and run), with every core priced as busy. Failed attempts count: a provider that can't run your
7
+ * setup, or fails the command, says so instead of dropping out.
8
+ */
9
+ export interface CompareRow {
10
+ provider: ProviderId;
11
+ runs: number;
12
+ /** Runs where the sandbox started, setup exited 0 and the command exited 0. */
13
+ ok: number;
14
+ /** Of the failures: the sandbox didn't start / setup failed / the command failed or timed out. */
15
+ startFailed: number;
16
+ setupFailed: number;
17
+ commandFailed: number;
18
+ /** Medians over the successful runs, in milliseconds. */
19
+ medianStartMs?: number;
20
+ medianSetupMs?: number;
21
+ medianCommandMs?: number;
22
+ medianTotalMs?: number;
23
+ /** Estimated cost of one successful run (not a bill). */
24
+ estimatedUsd?: number;
25
+ /** The estimate uses what this provider really billed against its list price, where we measured it. */
26
+ billMeasured: boolean;
27
+ /** The size it ran at. */
28
+ size: {
29
+ vcpu: number;
30
+ memoryGb: number;
31
+ };
32
+ /** The first failure's message, shortened. */
33
+ error?: string;
34
+ }
35
+ export declare function compare(opts: {
36
+ router?: Router;
37
+ providers: ProviderId[];
38
+ command: string;
39
+ /** Run once in each sandbox before the command: installs, clones. Timed and reported apart. */
40
+ setup?: string;
41
+ runs?: number;
42
+ /** Seconds the setup and the command may each take (default 600). */
43
+ timeoutSeconds?: number;
44
+ /** Providers measured at once (default 4). */
45
+ parallel?: number;
46
+ spec?: SandboxSpec;
47
+ onProgress?: (msg: string) => void;
48
+ }): Promise<CompareRow[]>;
@@ -0,0 +1,78 @@
1
+ import { BILLED_VS_LIST } from "./billing.js";
2
+ import { DEFAULT_MEMORY_GB, DEFAULT_VCPU, fittingSpec, fixedSize } from "./catalog.js";
3
+ import { median } from "./bench-store.js";
4
+ import { Router } from "./router.js";
5
+ import { taskUsd } from "./task.js";
6
+ export async function compare(opts) {
7
+ const router = opts.router ?? new Router();
8
+ const runs = Math.max(1, opts.runs ?? 3);
9
+ const timeoutSeconds = opts.timeoutSeconds ?? 600;
10
+ const log = opts.onProgress ?? (() => { });
11
+ const base = { vcpu: DEFAULT_VCPU, memoryGb: DEFAULT_MEMORY_GB, timeoutMinutes: Math.ceil((timeoutSeconds * 2) / 60) + 5, ...opts.spec };
12
+ const rows = [];
13
+ const lastLine = (r) => (r.stderr || r.stdout).trim().split("\n").at(-1) ?? "";
14
+ const one = async (id) => {
15
+ const spec = { ...base, ...fixedSize(id, base) };
16
+ const good = [];
17
+ const row = { provider: id, runs, ok: 0, startFailed: 0, setupFailed: 0, commandFailed: 0, billMeasured: BILLED_VS_LIST[id] !== undefined, size: fittingSpec(id) };
18
+ const fail = (kind, msg) => {
19
+ row[kind]++;
20
+ row.error ??= msg.replace(/\s+/g, " ").slice(0, 200);
21
+ };
22
+ for (let i = 0; i < runs; i++) {
23
+ let box;
24
+ const t0 = performance.now();
25
+ try {
26
+ box = await router.create(spec, { provider: id, fallback: false });
27
+ }
28
+ catch (err) {
29
+ fail("startFailed", err.message);
30
+ continue;
31
+ }
32
+ try {
33
+ const start = performance.now() - t0;
34
+ let setup = 0;
35
+ if (opts.setup) {
36
+ const t1 = performance.now();
37
+ const r = await box.exec(opts.setup, { timeoutSeconds }).catch((e) => ({ exitCode: -1, stdout: "", stderr: e.message }));
38
+ setup = performance.now() - t1;
39
+ if (r.exitCode !== 0) {
40
+ fail("setupFailed", `setup exited ${r.exitCode}: ${lastLine(r)}`);
41
+ continue;
42
+ }
43
+ }
44
+ const t2 = performance.now();
45
+ const r = await box.exec(opts.command, { timeoutSeconds }).catch((e) => ({ exitCode: -1, stdout: "", stderr: e.message }));
46
+ const command = performance.now() - t2;
47
+ if (r.exitCode !== 0) {
48
+ fail("commandFailed", `command exited ${r.exitCode}: ${lastLine(r)}`);
49
+ continue;
50
+ }
51
+ good.push({ start, setup, command });
52
+ row.ok++;
53
+ }
54
+ finally {
55
+ await box.kill().catch(() => { });
56
+ }
57
+ }
58
+ if (good.length) {
59
+ const m = (f) => Math.round(median(good.map(f)));
60
+ row.medianStartMs = m((g) => g.start);
61
+ if (opts.setup)
62
+ row.medianSetupMs = m((g) => g.setup);
63
+ row.medianCommandMs = m((g) => g.command);
64
+ row.medianTotalMs = m((g) => g.start + g.setup + g.command);
65
+ row.estimatedUsd = taskUsd(id, row.size, row.medianStartMs, (row.medianSetupMs ?? 0) + row.medianCommandMs, undefined, BILLED_VS_LIST[id]?.ratio ?? 1, false);
66
+ }
67
+ rows.push(row);
68
+ log(`${id}: ${row.ok}/${runs} worked${row.medianTotalMs !== undefined ? `, ${(row.medianTotalMs / 1000).toFixed(1)} s in total` : ""}${row.error ? `; ${row.error.slice(0, 120)}` : ""}`);
69
+ };
70
+ const queue = [...opts.providers];
71
+ await Promise.all(Array.from({ length: Math.max(1, Math.min(opts.parallel ?? 4, queue.length)) }, async () => {
72
+ for (let id = queue.shift(); id; id = queue.shift())
73
+ await one(id);
74
+ }));
75
+ // Most reliable first, then cheapest per successful run.
76
+ const perSuccess = (r) => (r.estimatedUsd === undefined || !r.ok ? Infinity : r.estimatedUsd / (r.ok / r.runs));
77
+ return rows.sort((a, b) => b.ok / b.runs - a.ok / a.runs || perSuccess(a) - perSuccess(b) || a.provider.localeCompare(b.provider));
78
+ }
@@ -119,7 +119,7 @@ export declare class RoutedComputer {
119
119
  screenshot(opts?: {
120
120
  format?: "png" | "jpeg";
121
121
  quality?: number;
122
- }): Promise<Uint8Array<ArrayBufferLike>>;
122
+ }): Promise<Uint8Array>;
123
123
  /** Run a shell command (max 30 s). The second argument is `{ timeoutSeconds }`, or the number alone. */
124
124
  exec(command: string, opts?: number | {
125
125
  timeoutSeconds?: number;
@@ -128,7 +128,7 @@ export declare class RoutedComputer {
128
128
  stdout: string;
129
129
  stderr: string;
130
130
  }>;
131
- readFile(path: string): Promise<Uint8Array<ArrayBufferLike>>;
131
+ readFile(path: string): Promise<Uint8Array>;
132
132
  writeFile(path: string, content: string | Uint8Array): Promise<void>;
133
133
  /** What this computer's provider supports beyond the core actions. */
134
134
  get supports(): {
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { gc, listOpen, isGone, type GcResult, type OpenSandbox } from "./gc.js";
5
5
  export { Router, RoutedSandbox, defaultProviders, defaultComputerProviders, parseId, balanced, sizeOf, PRICE_TIE, DEFAULT_CREATE_TIMEOUT_S, DEFAULT_CREATE_DEADLINE_S, rankUsd, runHours, usdPerHour, type Candidate, type Quote, type RouterOptions, type SandboxPrice, type Size, } from "./router.js";
6
6
  export { VERIFIED, FAILING } from "./verified.js";
7
7
  export { PUBLISHED } from "./published.js";
8
+ export { compare, type CompareRow } from "./compare.js";
8
9
  export { recommend, type RecJob, type RecPriority, type RecommendOptions, type Recommendation, type RecommendResult, type PublishedData, } from "./recommend.js";
9
10
  export { KEYED_PROVIDERS, providerWithKey } from "./keyed.js";
10
11
  export { BILLED_VS_LIST } from "./billing.js";
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { gc, listOpen, isGone } from "./gc.js";
5
5
  export { Router, RoutedSandbox, defaultProviders, defaultComputerProviders, parseId, balanced, sizeOf, PRICE_TIE, DEFAULT_CREATE_TIMEOUT_S, DEFAULT_CREATE_DEADLINE_S, rankUsd, runHours, usdPerHour, } from "./router.js";
6
6
  export { VERIFIED, FAILING } from "./verified.js";
7
7
  export { PUBLISHED } from "./published.js";
8
+ export { compare } from "./compare.js";
8
9
  export { recommend, } from "./recommend.js";
9
10
  export { KEYED_PROVIDERS, providerWithKey } from "./keyed.js";
10
11
  export { BILLED_VS_LIST } from "./billing.js";
@@ -1,5 +1,6 @@
1
1
  import { type PhaseMs } from "./task.js";
2
2
  import type { BenchRow } from "./bench.js";
3
+ import { type Size } from "./router.js";
3
4
  import type { ProviderId, SandboxSpec } from "./types.js";
4
5
  /**
5
6
  * A shareable bench result. People submit these as PRs to results/, and `sandboxrouter
@@ -37,6 +38,7 @@ export interface LeaderRow {
37
38
  submissions: number;
38
39
  medianCreateMs?: number;
39
40
  medianExecMs?: number;
41
+ medianReadyMs?: number;
40
42
  successRate: number;
41
43
  /** Runs behind the row that the provider was asked to do (refusals for an account limit left out). */
42
44
  runs: number;
@@ -56,7 +58,7 @@ export interface LeaderRow {
56
58
  * the one with the most runs wins (a 100-run start-time benchmark over a 3-run job that also timed starts);
57
59
  * ties go to the newest.
58
60
  */
59
- export declare function aggregate(reports: BenchReport[]): LeaderRow[];
61
+ export declare function aggregate(reports: BenchReport[], cohort?: Size): LeaderRow[];
60
62
  export interface TaskRow {
61
63
  provider: ProviderId;
62
64
  name: string;
@@ -74,8 +76,10 @@ export interface TaskRow {
74
76
  taskUsd: number;
75
77
  /** What one job costs in a sandbox that's already running (no start, minimum or per-sandbox fee). */
76
78
  reusedUsd: number;
77
- /** Runs behind the medians (refusals for an account limit left out). */
79
+ /** All requests in the comparison, including failed starts and limits. */
78
80
  runs: number;
81
+ ok: number;
82
+ limited: number;
79
83
  /** Share of those runs that finished the job. */
80
84
  successRate: number;
81
85
  /** CPU time the task used across all vCPUs (median), where the sandbox shows /proc/stat. */
@@ -86,12 +90,16 @@ export interface TaskRow {
86
90
  perSandboxUsd: number;
87
91
  measuredAt: string;
88
92
  }
89
- /**
90
- * Cost of the standard task (src/task.ts) per provider, from reports made with `bench --task` at
91
- * `version` (the short task's by default; TASKS.long.version for `--long`): each provider's latest run
92
- * from each location, then the median across locations (as `aggregate` does). Cheapest task first.
93
- */
94
- export declare function taskTable(reports: BenchReport[], version?: string): TaskRow[];
93
+ export declare function taskOutcomes(reports: BenchReport[], version: string, cohort?: Size): {
94
+ provider: ProviderId;
95
+ name: string;
96
+ requested: number;
97
+ completed: number;
98
+ limited: number;
99
+ failures: number;
100
+ taskFailures: number;
101
+ }[];
102
+ export declare function taskTable(reports: BenchReport[], version?: string, cohort?: Size): TaskRow[];
95
103
  /** One self-contained HTML page: a sorted table with an inline bar per measure, each on its own scale. */
96
104
  export declare function renderLeaderboard(reports: BenchReport[]): string;
97
105
  /** A saved `sandboxrouter burst` report (results/, tool "sandboxrouter-burst"). */
@@ -119,6 +127,14 @@ export declare function burstTable(reports: BurstReport[], task?: string, n?: nu
119
127
  n: number;
120
128
  ok: number;
121
129
  limited: number;
130
+ size?: {
131
+ vcpu: number;
132
+ memoryGb: number;
133
+ };
134
+ createFailures?: number;
135
+ commandFailures?: number;
136
+ taskFailures?: number;
137
+ cleanupFailures?: number;
122
138
  p50Ms?: number;
123
139
  p95Ms?: number;
124
140
  p99Ms?: number;
@@ -144,6 +160,12 @@ export declare function loadAgentReports(dir: string): AgentReport[];
144
160
  export declare function agentTable(reports: AgentReport[]): {
145
161
  provider: ProviderId;
146
162
  runs: number;
163
+ requested?: number;
164
+ started?: number;
165
+ size?: {
166
+ vcpu: number;
167
+ memoryGb: number;
168
+ };
147
169
  limited?: number;
148
170
  ok: number;
149
171
  medianWallMs?: number;