@sandboxrouter/sdk 0.9.0 → 0.11.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 +4 -3
  2. package/dist/agent-bench.d.ts +39 -0
  3. package/dist/agent-bench.js +150 -0
  4. package/dist/bench-store.js +11 -2
  5. package/dist/bench.d.ts +22 -0
  6. package/dist/bench.js +59 -7
  7. package/dist/burst.d.ts +81 -0
  8. package/dist/burst.js +183 -0
  9. package/dist/catalog.d.ts +32 -0
  10. package/dist/catalog.js +58 -15
  11. package/dist/check.d.ts +2 -0
  12. package/dist/check.js +8 -0
  13. package/dist/cli.js +217 -5
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +2 -0
  16. package/dist/leaderboard.d.ts +107 -2
  17. package/dist/leaderboard.js +175 -5
  18. package/dist/ledger.d.ts +2 -0
  19. package/dist/ledger.js +12 -1
  20. package/dist/price-index.d.ts +54 -0
  21. package/dist/price-index.js +50 -0
  22. package/dist/providers/beam.js +4 -0
  23. package/dist/providers/blaxel.js +4 -0
  24. package/dist/providers/boat.js +3 -1
  25. package/dist/providers/daytona.js +4 -0
  26. package/dist/providers/deno.js +4 -0
  27. package/dist/providers/e2b.d.ts +2 -0
  28. package/dist/providers/e2b.js +4 -0
  29. package/dist/providers/hopx.js +4 -0
  30. package/dist/providers/langsmith.js +4 -0
  31. package/dist/providers/modal.js +11 -2
  32. package/dist/providers/morph.js +4 -0
  33. package/dist/providers/runloop.js +4 -0
  34. package/dist/providers/sprites.js +4 -0
  35. package/dist/providers/tensorlake.js +4 -0
  36. package/dist/providers/vercel.js +4 -0
  37. package/dist/published.d.ts +2 -0
  38. package/dist/published.js +2087 -0
  39. package/dist/recommend.d.ts +117 -0
  40. package/dist/recommend.js +103 -0
  41. package/dist/results.js +81 -1
  42. package/dist/router.d.ts +50 -0
  43. package/dist/router.js +83 -10
  44. package/dist/submit.d.ts +6 -0
  45. package/dist/submit.js +70 -0
  46. package/dist/task.d.ts +80 -0
  47. package/dist/task.js +173 -0
  48. package/dist/types.d.ts +12 -0
  49. package/dist/util.d.ts +2 -0
  50. package/dist/util.js +2 -0
  51. package/dist/validate.d.ts +1 -1
  52. package/dist/validate.js +4 -1
  53. package/package.json +1 -1
package/dist/burst.js ADDED
@@ -0,0 +1,183 @@
1
+ import { BILLED_VS_LIST } from "./billing.js";
2
+ import { fittingSpec, fixedSize, DEFAULT_MEMORY_GB, DEFAULT_VCPU } from "./catalog.js";
3
+ import { Router } from "./router.js";
4
+ import { runTask, taskMs, taskUsd, TASKS } from "./task.js";
5
+ import { PUBLISHED } from "./published.js";
6
+ const LIMIT = /\b429\b|\b402\b|rate limit|too many|limit|quota|concurren|capacity|throttl|trial_exhausted|insufficient_credits/i;
7
+ /** The value at percentile `p` (0 to 1) of sorted numbers, nearest-rank. */
8
+ export function percentile(sorted, p) {
9
+ if (!sorted.length)
10
+ return undefined;
11
+ return sorted[Math.min(sorted.length - 1, Math.max(0, Math.ceil(p * sorted.length) - 1))];
12
+ }
13
+ export async function burst(opts) {
14
+ const router = opts.router ?? new Router();
15
+ const kind = opts.task;
16
+ const base = {
17
+ vcpu: DEFAULT_VCPU,
18
+ memoryGb: DEFAULT_MEMORY_GB,
19
+ timeoutMinutes: 10,
20
+ ...(kind && TASKS[kind].cpuUtilization ? { cpuUtilization: TASKS[kind].cpuUtilization } : {}),
21
+ };
22
+ const log = opts.onProgress ?? (() => { });
23
+ const rows = [];
24
+ const one = async (id) => {
25
+ log(`${id}: ${opts.n} at once${kind ? `, each running the ${kind} job` : ""}`);
26
+ const spec = { ...base, ...fixedSize(id, base) };
27
+ const t0 = performance.now();
28
+ const results = await Promise.all(Array.from({ length: opts.n }, async () => {
29
+ let box;
30
+ try {
31
+ box = await router.create(spec, { provider: id, fallback: false, deadlineSeconds: 240 });
32
+ const createMs = performance.now() - t0;
33
+ const r = await box.exec("echo ok");
34
+ if (r.exitCode !== 0 || r.stdout.trim() !== "ok")
35
+ throw new Error(`echo returned ${r.exitCode}`);
36
+ const tti = performance.now() - t0;
37
+ const job = kind ? await runTask(box, kind) : undefined;
38
+ return { ok: true, tti, createMs, job, done: performance.now() - t0 };
39
+ }
40
+ catch (err) {
41
+ return { ok: false, error: err.message, done: performance.now() - t0 };
42
+ }
43
+ finally {
44
+ await box?.kill().catch(() => { });
45
+ }
46
+ }));
47
+ const ok = results.filter((r) => r.ok);
48
+ const ttis = ok.map((r) => Math.round(r.tti)).sort((a, b) => a - b);
49
+ const jobs = ok.map((r) => (r.job ? taskMs(r.job.ms) : undefined)).filter((n) => n !== undefined).sort((a, b) => a - b);
50
+ const size = fittingSpec(id);
51
+ const ratio = BILLED_VS_LIST[id]?.ratio ?? 1;
52
+ 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);
54
+ const failed = results.filter((r) => !r.ok);
55
+ rows.push({
56
+ provider: id,
57
+ n: opts.n,
58
+ ok: ok.length,
59
+ limited: failed.filter((f) => LIMIT.test(f.error)).length,
60
+ p50Ms: percentile(ttis, 0.5),
61
+ p95Ms: percentile(ttis, 0.95),
62
+ p99Ms: percentile(ttis, 0.99),
63
+ wallMs: Math.round(Math.max(...results.map((r) => r.done))),
64
+ ...(jobs.length ? { jobP50Ms: percentile(jobs, 0.5) } : {}),
65
+ ...(ok.length ? { usd: Math.round(usd * 1e6) / 1e6 } : {}),
66
+ });
67
+ const sample = failed[0]?.error;
68
+ log(`${id}: ${ok.length}/${opts.n} ready, p50 ${percentile(ttis, 0.5) ?? "-"} ms, p99 ${percentile(ttis, 0.99) ?? "-"} ms${sample ? `; e.g. ${sample.slice(0, 140)}` : ""}`);
69
+ };
70
+ const queue = [...opts.providers];
71
+ const lanes = Array.from({ length: Math.max(1, Math.min(opts.parallel ?? 1, queue.length)) }, async () => {
72
+ for (let id = queue.shift(); id; id = queue.shift())
73
+ await one(id);
74
+ });
75
+ await Promise.all(lanes);
76
+ return rows.sort((a, b) => b.ok - a.ok || (a.p50Ms ?? Infinity) - (b.p50Ms ?? Infinity));
77
+ }
78
+ /**
79
+ * Ask for `n` sandboxes at once, spread round-robin over `providers`. A provider that refuses for a limit or quota
80
+ * is marked full for the rest of the burst, and that sandbox moves to the next provider with room: what a service
81
+ * running at scale needs when one provider's account limit is smaller than its burst. Time to interactive counts
82
+ * from the burst's start, so moving costs show. Every sandbox is killed after.
83
+ */
84
+ /**
85
+ * How many each provider can take at once, from the published bursts: the most it started at the largest size
86
+ * measured (all of them, if it started all). Unmeasured providers get 10, the size every account allows.
87
+ */
88
+ export function publishedCapacity(ids) {
89
+ const loads = PUBLISHED.load.filter((l) => l.job === "start").sort((a, b) => b.n - a.n);
90
+ return Object.fromEntries(ids.map((id) => [id, loads.find((l) => l.rows[id])?.rows[id]?.ok ?? 10]));
91
+ }
92
+ /** `n` slots dealt out in proportion to `weights`, interleaved so every provider gets work from the first moment. */
93
+ export function deal(ids, n, weights) {
94
+ const total = ids.reduce((t, id) => t + Math.max(1, weights[id] ?? 1), 0);
95
+ const want = new Map(ids.map((id) => [id, (Math.max(1, weights[id] ?? 1) / total) * n]));
96
+ const given = new Map(ids.map((id) => [id, 0]));
97
+ const out = [];
98
+ for (let i = 0; i < n; i++) {
99
+ // The provider furthest behind its share goes next (ties by list order).
100
+ let best = ids[0];
101
+ let gap = -Infinity;
102
+ for (const id of ids) {
103
+ const g = (want.get(id) * (i + 1)) / n - given.get(id);
104
+ if (g > gap) {
105
+ gap = g;
106
+ best = id;
107
+ }
108
+ }
109
+ given.set(best, given.get(best) + 1);
110
+ out.push(best);
111
+ }
112
+ return out;
113
+ }
114
+ export async function spreadBurst(opts) {
115
+ const router = opts.router ?? new Router();
116
+ const log = opts.onProgress ?? (() => { });
117
+ const base = { vcpu: DEFAULT_VCPU, memoryGb: DEFAULT_MEMORY_GB, timeoutMinutes: 10 };
118
+ const full = new Set();
119
+ const stats = new Map(opts.providers.map((p) => [p, { ok: 0, spilledIn: 0, refused: 0, createMs: [] }]));
120
+ const t0 = performance.now();
121
+ const weights = opts.weights === "even" ? Object.fromEntries(opts.providers.map((id) => [id, 1])) : (opts.weights ?? publishedCapacity(opts.providers));
122
+ const first = deal(opts.providers, opts.n, weights);
123
+ log(`${opts.n} at once, spread over ${opts.providers.length} providers by ${opts.weights === "even" ? "equal shares" : "measured capacity"}`);
124
+ const results = await Promise.all(Array.from({ length: opts.n }, async (_, i) => {
125
+ // Start on this sandbox's dealt provider, then walk the rest, biggest capacity first.
126
+ const rest = [...opts.providers].filter((id) => id !== first[i]).sort((a, b) => (weights[b] ?? 1) - (weights[a] ?? 1));
127
+ const order = [first[i], ...rest];
128
+ let moved = false;
129
+ for (const id of order) {
130
+ if (full.has(id)) {
131
+ moved = true;
132
+ continue;
133
+ }
134
+ let box;
135
+ try {
136
+ box = await router.create({ ...base, ...fixedSize(id, base) }, { provider: id, fallback: false, deadlineSeconds: 240 });
137
+ const createMs = performance.now() - t0;
138
+ const r = await box.exec("echo ok");
139
+ if (r.exitCode !== 0 || r.stdout.trim() !== "ok")
140
+ throw new Error(`echo returned ${r.exitCode}`);
141
+ const s = stats.get(id);
142
+ s.ok++;
143
+ s.createMs.push(createMs);
144
+ if (moved)
145
+ s.spilledIn++;
146
+ return { ok: true, tti: performance.now() - t0, done: performance.now() - t0 };
147
+ }
148
+ catch (err) {
149
+ const msg = err.message;
150
+ stats.get(id).refused++;
151
+ if (LIMIT.test(msg)) {
152
+ if (!full.has(id))
153
+ log(`${id}: full (${msg.slice(0, 90)})`);
154
+ full.add(id);
155
+ }
156
+ moved = true;
157
+ }
158
+ finally {
159
+ await box?.kill().catch(() => { });
160
+ }
161
+ }
162
+ return { ok: false, done: performance.now() - t0 };
163
+ }));
164
+ const ttis = results.filter((r) => r.ok).map((r) => Math.round(r.tti)).sort((a, b) => a - b);
165
+ let usd = 0;
166
+ for (const [id, s] of stats) {
167
+ const ratio = BILLED_VS_LIST[id]?.ratio ?? 1;
168
+ for (const c of s.createMs)
169
+ usd += taskUsd(id, fittingSpec(id), c, 0, undefined, ratio, false);
170
+ }
171
+ return {
172
+ n: opts.n,
173
+ ok: ttis.length,
174
+ failed: opts.n - ttis.length,
175
+ p50Ms: percentile(ttis, 0.5),
176
+ p95Ms: percentile(ttis, 0.95),
177
+ p99Ms: percentile(ttis, 0.99),
178
+ wallMs: Math.round(Math.max(...results.map((r) => r.done))),
179
+ usd: Math.round(usd * 1e6) / 1e6,
180
+ byProvider: [...stats].map(([provider, s]) => ({ provider, ok: s.ok, spilledIn: s.spilledIn, refused: s.refused })).sort((a, b) => b.ok - a.ok),
181
+ saturated: [...full],
182
+ };
183
+ }
package/dist/catalog.d.ts CHANGED
@@ -12,6 +12,28 @@ 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
+ /**
16
+ * Active-CPU billing only: the share of the allocated CPU billed even when idle (Tensorlake bills at
17
+ * least 20%). Default 0.
18
+ */
19
+ cpuFloor?: number;
20
+ /**
21
+ * What `minSeconds` applies to. "all" (default): the whole price. "memory": only the non-CPU part, as
22
+ * on Vercel, where provisioned memory has a one-minute minimum and active CPU has none.
23
+ */
24
+ minimumCovers?: "all" | "memory";
25
+ /**
26
+ * Bills the larger of the CPU reserved and the CPU used (Modal). The adapter reserves `cpuUtilization` of
27
+ * the size you ask for (at least `cpuFloor`) and lets the sandbox burst to the full size, so CPU is
28
+ * priced like active CPU when `cpuUtilization` is below 1, and like allocated capacity otherwise.
29
+ */
30
+ reservesCpu?: boolean;
31
+ /**
32
+ * Active CPU is metered for the whole VM: while any core is busy, every vCPU counts (measured on Vercel
33
+ * 2026-11-17: one busy core for 11 s metered 22.7 s on 2 vCPUs; both busy metered 24.1 s for 23.1 s
34
+ * seen inside; idle about 2%). Task pricing then charges vCPUs x the busiest core's time.
35
+ */
36
+ cpuMeteredPerVm?: boolean;
15
37
  note?: string;
16
38
  source: string;
17
39
  checked: string;
@@ -269,6 +291,7 @@ export declare function billingRules(id: ProviderId): {
269
291
  minSeconds: number;
270
292
  incrementSeconds: number;
271
293
  perSandboxUsd: number;
294
+ minimumCovers: "all" | "memory";
272
295
  };
273
296
  /**
274
297
  * What a provider bills for one sandbox that ran `seconds` at `hourlyUsd`: running time rounded up to
@@ -289,6 +312,15 @@ export declare function fittingSpec(id: ProviderId): {
289
312
  vcpu: number;
290
313
  memoryGb: number;
291
314
  };
315
+ /**
316
+ * Estimated USD per hour for this spec on this provider (list price, while running). For providers that
317
+ * bill CPU only while it's busy ("active-cpu"), the CPU part is scaled by `spec.cpuUtilization` (default
318
+ * 1, every core busy, so the price is the most an hour costs), never below the provider's `cpuFloor`.
319
+ */
292
320
  export declare function hourlyCost(id: ProviderId, spec?: SandboxSpec): number;
321
+ /** The CPU part of the full-use hourly price for an "active-cpu" provider; 0 for providers that bill allocated capacity. */
322
+ export declare function cpuHourlyAtFull(id: ProviderId, spec?: SandboxSpec): number;
323
+ /** Share of an "active-cpu" provider's CPU that gets billed: `cpuUtilization` (default 1), at least its `cpuFloor`. */
324
+ export declare function billedCpuShare(id: ProviderId, spec?: SandboxSpec): number;
293
325
  /** Why a provider can't take this spec, or null if it can. */
294
326
  export declare function unfit(id: ProviderId, spec: SandboxSpec, require?: Capability[]): string | null;
package/dist/catalog.js CHANGED
@@ -91,7 +91,7 @@ const ENTRIES = [
91
91
  gbHour: 0.0162,
92
92
  note: "per second, plus disk above 5 GiB",
93
93
  source: "https://www.daytona.io/pricing",
94
- checked: "2026-11-13",
94
+ checked: "2026-11-17",
95
95
  },
96
96
  capabilities: ["pause", "custom-image"],
97
97
  limits: { maxVcpu: 4, maxMemoryGb: 8 },
@@ -105,10 +105,12 @@ const ENTRIES = [
105
105
  name: "Modal",
106
106
  pricing: {
107
107
  vcpuHour: 0.070956,
108
+ reservesCpu: true,
109
+ cpuFloor: 0.125,
108
110
  gbHour: 0.024012,
109
111
  note: "sandbox rates, per second ($0.00003942 per physical core = 2 vCPUs); GPUs extra; region pinning x1.15-1.75; Starter includes $30/mo credit",
110
112
  source: "https://modal.com/pricing",
111
- checked: "2026-11-05",
113
+ checked: "2026-11-17",
112
114
  },
113
115
  capabilities: ["gpu", "custom-image"],
114
116
  limits: { maxVcpu: 64, maxMemoryGb: 256 },
@@ -120,9 +122,11 @@ const ENTRIES = [
120
122
  name: "Vercel Sandbox",
121
123
  pricing: {
122
124
  minSeconds: 60,
125
+ minimumCovers: "memory",
126
+ cpuMeteredPerVm: true,
123
127
  vcpuHour: 0.128,
124
128
  gbHour: 0.0212,
125
- note: "iad1; active CPU, provisioned RAM in minimum 1-minute increments (2 GB/vCPU); full-CPU estimate; Hobby free within quotas, Pro $20/mo usage credit; creations $0.60/million and retained snapshots $0.08/GB-month extra",
129
+ note: "iad1; active CPU (I/O wait free), provisioned RAM in minimum 1-minute increments (2 GB/vCPU); listed at full CPU, cpuUtilization lowers it; Hobby free within quotas, Pro $20/mo usage credit; creations $0.60/million and retained snapshots $0.08/GB-month extra",
126
130
  source: "https://vercel.com/docs/vercel-sandbox/pricing",
127
131
  checked: "2026-11-05",
128
132
  },
@@ -189,7 +193,8 @@ const ENTRIES = [
189
193
  pricing: {
190
194
  vcpuHour: 0.07,
191
195
  gbHour: 0.015,
192
- note: "bills active CPU (floor 20% of allocation); this is the full-use price; Pro plan is lower",
196
+ cpuFloor: 0.2,
197
+ note: "bills active CPU (floor 20% of allocation); listed at full CPU, cpuUtilization lowers it; Pro plan is lower",
193
198
  source: "https://www.tensorlake.ai/pricing",
194
199
  checked: "2026-11-04",
195
200
  },
@@ -315,7 +320,7 @@ ENTRIES.push({
315
320
  gbHour: 0,
316
321
  note: "flat $0.03 per session-hour (built-in Shell pools), billed per allocated session in 1-hour increments, East US; needs a session pool you create once",
317
322
  source: "https://learn.microsoft.com/en-us/azure/container-apps/billing#dynamic-sessions",
318
- checked: "2026-11-04",
323
+ checked: "2026-11-17",
319
324
  },
320
325
  capabilities: [],
321
326
  // Per-session size isn't published; placeholder until measured with nproc / free.
@@ -366,7 +371,7 @@ ENTRIES.push({
366
371
  gbHour: 0.008928,
367
372
  note: "per second; Default QoS, Hong Kong and regions outside mainland China; disk separately $0.00025308/GiB-h; code-interpreter-v1 template is 2 vCPU / 2 GiB with 10 GiB disk (E2B-compatible API)",
368
373
  source: "https://www.alibabacloud.com/help/en/agent-sandbox/product-overview/billing-overview",
369
- checked: "2026-11-05",
374
+ checked: "2026-11-17",
370
375
  },
371
376
  capabilities: ["custom-image"],
372
377
  // No published maximum; the default template is 2 vCPU / 2 GB, so bigger requests go elsewhere.
@@ -441,7 +446,7 @@ ENTRIES.push({
441
446
  gbHour: 0.001,
442
447
  note: "per second on allocated size; no platform fee or minimum; paused = free; size comes from the template (E2B-compatible API); Singapore only; needs a pay-as-you-go key",
443
448
  source: "https://openscale.so/sandboxes",
444
- checked: "2026-11-05",
449
+ checked: "2026-11-17",
445
450
  },
446
451
  capabilities: ["pause", "custom-image"],
447
452
  limits: { maxVcpu: 8, maxMemoryGb: 16 },
@@ -472,7 +477,7 @@ ENTRIES.push({
472
477
  gbHour: 0.025,
473
478
  note: "billed on CPU time, not wall clock (estimate assumes both vCPUs busy); fixed 2 vCPU, 0.75-4 GB, max 30 min lifetime; needs a paid Deno Deploy plan",
474
479
  source: "https://deno.com/sandbox",
475
- checked: "2026-11-04",
480
+ checked: "2026-11-17",
476
481
  },
477
482
  capabilities: ["custom-image"],
478
483
  limits: { maxVcpu: 2, maxMemoryGb: 4 },
@@ -500,7 +505,7 @@ ENTRIES.push({
500
505
  gbHour: 0.00225,
501
506
  note: "per second while running on fixed sizes (2/4, 4/8, 8/16); paused or stopped boxes bill only /data beyond the included disk ($0.00011/GiB-h); Pro $20/mo includes $20 credits; free plan: 1 box at 4/8",
502
507
  source: "https://instabox.sh/docs/pricing.md",
503
- checked: "2026-11-05",
508
+ checked: "2026-11-17",
504
509
  },
505
510
  capabilities: ["pause", "custom-image"],
506
511
  limits: { maxVcpu: 8, maxMemoryGb: 16 },
@@ -534,7 +539,7 @@ ENTRIES.push({
534
539
  gbHour: 0.01845,
535
540
  note: "per second; memory must be 2 to 6 GiB per vCPU; storage $0.000123/GiB-h; 8 LSU ($8) of sandbox usage a month included; Developer plan max 10 sandboxes",
536
541
  source: "https://www.langchain.com/pricing",
537
- checked: "2026-11-05",
542
+ checked: "2026-11-17",
538
543
  },
539
544
  capabilities: ["pause", "custom-image"],
540
545
  // Not published; 16 vCPU / 96 GiB stays inside the 6 GiB per vCPU band. Real runs will tell.
@@ -566,9 +571,9 @@ ENTRIES.push({
566
571
  pricing: {
567
572
  vcpuHour: 0.1,
568
573
  gbHour: 0,
569
- note: "billed per active CPU core-hour only (memory and idle time free); estimate assumes every core of the box busy; fixed sizes 2/4, 4/8, 8/16",
574
+ note: "billed per active CPU core-hour only (memory and idle time free); estimate assumes every core of the box busy at the Small rate; fixed sizes 2/4, 4/8, 8/16, and the pricing page lists $0.20 (4/8) and $0.40 (8/16) per active CPU hour without saying whether that is per core or per box",
570
575
  source: "https://upstash.com/pricing/box",
571
- checked: "2026-11-04",
576
+ checked: "2026-11-17",
572
577
  },
573
578
  capabilities: [],
574
579
  limits: { maxVcpu: 8, maxMemoryGb: 16 },
@@ -610,7 +615,8 @@ const BILLING = {
610
615
  lambda: { billing: "allocated" },
611
616
  langsmith: { billing: "allocated" },
612
617
  maritime: { billing: "allocated", plan: { usdMonth: 20, credited: true, note: "Starter plan; no free tier; 7-day trial needs a card", checked: P } },
613
- modal: { billing: "active-cpu" },
618
+ // Modal bills the larger of the reservation and actual use, and the adapter reserves the size you ask for.
619
+ modal: { billing: "allocated" },
614
620
  morph: { billing: "allocated" },
615
621
  northflank: { billing: "allocated" },
616
622
  novita: { billing: "allocated" },
@@ -672,7 +678,12 @@ export function cloudflareInstance(vcpu, memoryGb) {
672
678
  /** How a provider turns running time into a bill: minimum, rounding and fixed per-sandbox charge. */
673
679
  export function billingRules(id) {
674
680
  const p = CATALOG.find((c) => c.id === id)?.pricing;
675
- return { minSeconds: p?.minSeconds ?? 0, incrementSeconds: p?.incrementSeconds ?? 1, perSandboxUsd: p?.perSandboxUsd ?? 0 };
681
+ return {
682
+ minSeconds: p?.minSeconds ?? 0,
683
+ incrementSeconds: p?.incrementSeconds ?? 1,
684
+ perSandboxUsd: p?.perSandboxUsd ?? 0,
685
+ minimumCovers: p?.minimumCovers ?? "all",
686
+ };
676
687
  }
677
688
  /**
678
689
  * What a provider bills for one sandbox that ran `seconds` at `hourlyUsd`: running time rounded up to
@@ -701,7 +712,7 @@ export function fixedSize(id, spec = {}) {
701
712
  export function fittingSpec(id) {
702
713
  return fixedSize(id) ?? { vcpu: DEFAULT_VCPU, memoryGb: DEFAULT_MEMORY_GB };
703
714
  }
704
- export function hourlyCost(id, spec = {}) {
715
+ function fullHourlyCost(id, spec = {}) {
705
716
  const { pricing } = info(id);
706
717
  // You get, and pay for, the default image's size whatever you asked for.
707
718
  const fixed = fixedSize(id, spec);
@@ -769,6 +780,38 @@ export function hourlyCost(id, spec = {}) {
769
780
  return Math.max(vcpu, Math.ceil(mem / 4)) * pricing.vcpuHour;
770
781
  return vcpu * pricing.vcpuHour + mem * pricing.gbHour;
771
782
  }
783
+ /**
784
+ * Estimated USD per hour for this spec on this provider (list price, while running). For providers that
785
+ * bill CPU only while it's busy ("active-cpu"), the CPU part is scaled by `spec.cpuUtilization` (default
786
+ * 1, every core busy, so the price is the most an hour costs), never below the provider's `cpuFloor`.
787
+ */
788
+ export function hourlyCost(id, spec = {}) {
789
+ const cpu = cpuHourlyAtFull(id, spec);
790
+ return fullHourlyCost(id, spec) - cpu * (1 - billedCpuShare(id, spec));
791
+ }
792
+ /** The CPU part of the full-use hourly price for an "active-cpu" provider; 0 for providers that bill allocated capacity. */
793
+ export function cpuHourlyAtFull(id, spec = {}) {
794
+ const p = info(id);
795
+ const reserved = p.pricing.reservesCpu && (spec.cpuUtilization ?? 1) < 1;
796
+ if (p.billing !== "active-cpu" && !reserved)
797
+ return 0;
798
+ const fixed = fixedSize(id, spec);
799
+ if (fixed)
800
+ return fixed.vcpu * p.pricing.vcpuHour;
801
+ const vcpu = spec.vcpu ?? DEFAULT_VCPU;
802
+ const mem = spec.memoryGb ?? DEFAULT_MEMORY_GB;
803
+ if (id === "cloudflare")
804
+ return cloudflareInstance(vcpu, mem).vcpu * p.pricing.vcpuHour;
805
+ if (id === "upstash")
806
+ return fullHourlyCost(id, spec);
807
+ if (id === "deno")
808
+ return 2 * p.pricing.vcpuHour;
809
+ return vcpu * p.pricing.vcpuHour;
810
+ }
811
+ /** Share of an "active-cpu" provider's CPU that gets billed: `cpuUtilization` (default 1), at least its `cpuFloor`. */
812
+ export function billedCpuShare(id, spec = {}) {
813
+ return Math.min(1, Math.max(spec.cpuUtilization ?? 1, info(id).pricing.cpuFloor ?? 0));
814
+ }
772
815
  /** Why a provider can't take this spec, or null if it can. */
773
816
  export function unfit(id, spec, require = []) {
774
817
  const p = info(id);
package/dist/check.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { Router } from "./router.js";
2
2
  import type { ProviderId, SandboxSpec } from "./types.js";
3
3
  /** Every step `check` runs, in order. Each provider's saved report is scored against this list. */
4
+ /** An account that can't start sandboxes at all: no credit, a frozen workspace, or a key or plan without access. */
5
+ export declare const ACCOUNT_BLOCKED: RegExp;
4
6
  export declare const CHECK_STEPS: readonly ["create", "exec: stdout, stderr, exit code", "exec: env and cwd", "exec: UTF-8 output", "exec: streaming", "files: binary round-trip", "files: 1 MB round-trip", "files: missing file is an error", "files: visible to commands", "exec: command timeout", "exec: timed-out command was stopped", "pause and resume", "kill", "killed sandbox is gone"];
5
7
  export type CheckStatus = "pass" | "fail" | "skip" | "info";
6
8
  export interface CheckResult {
package/dist/check.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { fixedSize } from "./catalog.js";
2
2
  /** Every step `check` runs, in order. Each provider's saved report is scored against this list. */
3
+ /** An account that can't start sandboxes at all: no credit, a frozen workspace, or a key or plan without access. */
4
+ export const ACCOUNT_BLOCKED = /insufficient_credits|insufficient credit|workspace has been frozen|spending limit|HTTP 403|\b403\b.*Forbidden|Payment Required/i;
3
5
  export const CHECK_STEPS = [
4
6
  "create",
5
7
  "exec: stdout, stderr, exit code",
@@ -53,6 +55,12 @@ export async function checkProvider(router, provider, opts = {}) {
53
55
  notRun = "the account running the check can't pay (402)";
54
56
  return { status: "skip", detail: `the account can't pay (402), so this run says nothing about ${provider}: ${msg}` };
55
57
  }
58
+ // The account itself can't start sandboxes (no credit, a frozen workspace, a plan without sandboxes): that's the
59
+ // account running the check, not the provider.
60
+ if (ACCOUNT_BLOCKED.test(msg)) {
61
+ notRun = "the account running the check can't start sandboxes (credit, plan or a frozen workspace)";
62
+ return { status: "skip", detail: `${notRun}, so this run says nothing about ${provider}: ${msg}` };
63
+ }
56
64
  // The provider's SDK isn't installed where the check runs: that says nothing about the provider.
57
65
  const pkg = /needs the "([^"]+)" package/.exec(msg)?.[1];
58
66
  if (!pkg)