@sandboxrouter/sdk 0.10.0 → 0.12.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 +3 -2
  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 +12 -0
  6. package/dist/bench.js +24 -3
  7. package/dist/burst.d.ts +81 -0
  8. package/dist/burst.js +183 -0
  9. package/dist/catalog.d.ts +12 -0
  10. package/dist/catalog.js +15 -11
  11. package/dist/check.d.ts +2 -0
  12. package/dist/check.js +8 -0
  13. package/dist/cli.js +227 -5
  14. package/dist/compare.d.ts +48 -0
  15. package/dist/compare.js +78 -0
  16. package/dist/index.d.ts +3 -0
  17. package/dist/index.js +3 -0
  18. package/dist/leaderboard.d.ts +74 -2
  19. package/dist/leaderboard.js +117 -7
  20. package/dist/ledger.d.ts +2 -0
  21. package/dist/ledger.js +12 -1
  22. package/dist/price-index.d.ts +54 -0
  23. package/dist/price-index.js +50 -0
  24. package/dist/providers/beam.js +4 -0
  25. package/dist/providers/blaxel.js +4 -0
  26. package/dist/providers/boat.js +3 -1
  27. package/dist/providers/daytona.js +4 -0
  28. package/dist/providers/deno.js +4 -0
  29. package/dist/providers/e2b.d.ts +2 -0
  30. package/dist/providers/e2b.js +4 -0
  31. package/dist/providers/hopx.js +4 -0
  32. package/dist/providers/langsmith.js +4 -0
  33. package/dist/providers/modal.js +11 -2
  34. package/dist/providers/morph.js +4 -0
  35. package/dist/providers/runloop.js +4 -0
  36. package/dist/providers/sprites.js +4 -0
  37. package/dist/providers/tensorlake.js +4 -0
  38. package/dist/providers/vercel.js +4 -0
  39. package/dist/published.d.ts +2 -0
  40. package/dist/published.js +2087 -0
  41. package/dist/recommend.d.ts +117 -0
  42. package/dist/recommend.js +103 -0
  43. package/dist/results.js +93 -1
  44. package/dist/router.d.ts +45 -0
  45. package/dist/router.js +69 -4
  46. package/dist/submit.d.ts +6 -0
  47. package/dist/submit.js +70 -0
  48. package/dist/task.d.ts +17 -2
  49. package/dist/task.js +74 -19
  50. package/dist/types.d.ts +5 -0
  51. package/dist/util.d.ts +2 -0
  52. package/dist/util.js +2 -0
  53. package/package.json +1 -1
@@ -38,6 +38,8 @@ export interface LeaderRow {
38
38
  medianCreateMs?: number;
39
39
  medianExecMs?: number;
40
40
  successRate: number;
41
+ /** Runs behind the row that the provider was asked to do (refusals for an account limit left out). */
42
+ runs: number;
41
43
  /** List price for the size the bench runs it at (`size`). */
42
44
  hourlyUsd: number;
43
45
  /** The size bench runs: 2 vCPU / 4 GB, or the provider's fixed default size. */
@@ -49,8 +51,10 @@ export interface LeaderRow {
49
51
  measuredAt: string;
50
52
  }
51
53
  /**
52
- * Each provider's latest run from each location (report label), then the median across locations, so
53
- * an old run can't outvote a newer one and one heavy submitter can't skew a provider.
54
+ * Each provider's best-sampled recent run from each location (report label), then the median across
55
+ * locations, so one heavy submitter can't skew a provider. Within the last 30 days of a location's runs,
56
+ * the one with the most runs wins (a 100-run start-time benchmark over a 3-run job that also timed starts);
57
+ * ties go to the newest.
54
58
  */
55
59
  export declare function aggregate(reports: BenchReport[]): LeaderRow[];
56
60
  export interface TaskRow {
@@ -68,6 +72,12 @@ export interface TaskRow {
68
72
  hourlyUsd: number;
69
73
  /** What one task is billed: start plus task, with the minimum charge, billing step and per-sandbox fee; active-CPU providers by the CPU time it used. */
70
74
  taskUsd: number;
75
+ /** What one job costs in a sandbox that's already running (no start, minimum or per-sandbox fee). */
76
+ reusedUsd: number;
77
+ /** Runs behind the medians (refusals for an account limit left out). */
78
+ runs: number;
79
+ /** Share of those runs that finished the job. */
80
+ successRate: number;
71
81
  /** CPU time the task used across all vCPUs (median), where the sandbox shows /proc/stat. */
72
82
  cpuMs?: number;
73
83
  /** True when the provider bills CPU only while busy, so `taskUsd` counts `cpuMs` rather than every core. */
@@ -84,3 +94,65 @@ export interface TaskRow {
84
94
  export declare function taskTable(reports: BenchReport[], version?: string): TaskRow[];
85
95
  /** One self-contained HTML page: a sorted table with an inline bar per measure, each on its own scale. */
86
96
  export declare function renderLeaderboard(reports: BenchReport[]): string;
97
+ /** A saved `sandboxrouter burst` report (results/, tool "sandboxrouter-burst"). */
98
+ export interface BurstReport {
99
+ tool: "sandboxrouter-burst";
100
+ version: string;
101
+ date: string;
102
+ label?: string;
103
+ by?: string;
104
+ n: number;
105
+ /** The job each sandbox ran, if any: a task version (src/task.ts). */
106
+ task?: string;
107
+ node: string;
108
+ platform: string;
109
+ rows: import("./burst.js").BurstRow[];
110
+ }
111
+ export declare function loadBursts(dir: string): BurstReport[];
112
+ /**
113
+ * Each provider's latest burst of each kind (plain, or with a job), newest location wins, for the website:
114
+ * how many started, time to interactive at p50/p95/p99, and what the burst cost. Most started first, then
115
+ * fastest p50.
116
+ */
117
+ export declare function burstTable(reports: BurstReport[], task?: string, n?: number): {
118
+ provider: ProviderId;
119
+ n: number;
120
+ ok: number;
121
+ limited: number;
122
+ p50Ms?: number;
123
+ p95Ms?: number;
124
+ p99Ms?: number;
125
+ wallMs: number;
126
+ jobP50Ms?: number;
127
+ usd?: number;
128
+ name: string;
129
+ measuredAt: string;
130
+ label: string | null;
131
+ }[];
132
+ /** A saved `sandboxrouter agentbench` report (results/, tool "sandboxrouter-agent"). */
133
+ export interface AgentReport {
134
+ tool: "sandboxrouter-agent";
135
+ date: string;
136
+ label?: string;
137
+ task: string;
138
+ model: string;
139
+ runs: number;
140
+ rows: import("./agent-bench.js").AgentRow[];
141
+ }
142
+ export declare function loadAgentReports(dir: string): AgentReport[];
143
+ /** Each provider's latest real-agent result: done right first, then cheapest sandbox per session. */
144
+ export declare function agentTable(reports: AgentReport[]): {
145
+ provider: ProviderId;
146
+ runs: number;
147
+ limited?: number;
148
+ ok: number;
149
+ medianWallMs?: number;
150
+ medianModelMs?: number;
151
+ medianCpuMs?: number;
152
+ medianTurns?: number;
153
+ medianUsd?: number;
154
+ medianTokens?: number;
155
+ name: string;
156
+ measuredAt: string;
157
+ model: string;
158
+ }[];
@@ -44,18 +44,30 @@ export function loadReports(dir) {
44
44
  }
45
45
  const KNOWN = new Set(CATALOG.map((c) => c.id));
46
46
  /**
47
- * Each provider's latest run from each location (report label), then the median across locations, so
48
- * an old run can't outvote a newer one and one heavy submitter can't skew a provider.
47
+ * Each provider's best-sampled recent run from each location (report label), then the median across
48
+ * locations, so one heavy submitter can't skew a provider. Within the last 30 days of a location's runs,
49
+ * the one with the most runs wins (a 100-run start-time benchmark over a 3-run job that also timed starts);
50
+ * ties go to the newest.
49
51
  */
50
52
  export function aggregate(reports) {
51
53
  const latest = new Map();
54
+ const newest = new Map();
55
+ for (const rep of reports)
56
+ for (const r of rep.rows) {
57
+ const key = `${r.provider}\u0000${rep.label ?? ""}`;
58
+ if ((newest.get(key) ?? "") < rep.date)
59
+ newest.set(key, rep.date);
60
+ }
61
+ const MONTH = 30 * 86_400_000;
52
62
  for (const rep of reports) {
53
63
  for (const r of rep.rows) {
54
64
  if (!KNOWN.has(r.provider))
55
65
  continue;
56
66
  const key = `${r.provider}\u0000${rep.label ?? ""}`;
67
+ if (Date.parse(newest.get(key)) - Date.parse(rep.date) > MONTH)
68
+ continue;
57
69
  const seen = latest.get(key);
58
- if (!seen || rep.date > seen.date)
70
+ if (!seen || r.runs > seen.row.runs || (r.runs === seen.row.runs && rep.date > seen.date))
59
71
  latest.set(key, { row: r, date: rep.date });
60
72
  }
61
73
  }
@@ -66,13 +78,16 @@ export function aggregate(reports) {
66
78
  const rs = xs.map((x) => x.row);
67
79
  const runs = rs.reduce((n, r) => n + r.runs, 0);
68
80
  const ok = rs.reduce((n, r) => n + (r.runs - r.failures), 0);
81
+ // Refusals for a limit on the benchmarking account aren't the provider failing: leave them out of the rate.
82
+ const attempted = runs - rs.reduce((n, r) => n + (r.limited ?? 0), 0);
69
83
  return {
70
84
  provider: id,
71
85
  name: CATALOG.find((c) => c.id === id).name,
72
86
  submissions: rs.length,
73
87
  medianCreateMs: median(rs.map((r) => r.medianCreateMs).filter((n) => typeof n === "number")),
74
88
  medianExecMs: median(rs.map((r) => r.medianExecMs).filter((n) => typeof n === "number")),
75
- successRate: runs ? ok / runs : 0,
89
+ successRate: attempted ? ok / attempted : 0,
90
+ runs: attempted,
76
91
  hourlyUsd: hourlyCost(id, fittingSpec(id)),
77
92
  size: fittingSpec(id),
78
93
  measuredAt: xs.map((x) => x.date).sort().at(-1),
@@ -110,15 +125,19 @@ export function taskTable(reports, version = TASK_VERSION) {
110
125
  const createMs = median(rs.map((r) => r.medianCreateMs));
111
126
  const taskMillis = median(rs.map((r) => r.medianTaskMs));
112
127
  const phasesMs = Object.fromEntries(def.phases.map((p) => [p.id, median(rs.map((r) => r.taskPhasesMs[p.id]))]));
113
- const size = fittingSpec(id);
128
+ // The job's own CPU hint (the agent loop's 10%) prices it the way its sandboxes were started.
129
+ const size = { ...fittingSpec(id), ...(def.cpuUtilization ? { cpuUtilization: def.cpuUtilization } : {}) };
114
130
  const ratio = BILLED_VS_LIST[id]?.ratio ?? 1;
115
- const hourlyUsd = hourlyCost(id, size) * ratio;
131
+ const hourlyUsd = hourlyCost(id, fittingSpec(id)) * ratio;
116
132
  const rules = billingRules(id);
117
133
  const cpus = rs.map((r) => r.medianTaskCpuMs).filter((n) => typeof n === "number");
118
134
  // A container can show the whole host's /proc/stat (Daytona does): a reading beyond what the sandbox's
119
135
  // own vCPUs could do in that time isn't the sandbox's, so it's dropped and the task is priced at full CPU.
120
136
  const read = cpus.length === rs.length ? median(cpus) : undefined;
121
137
  const cpuMs = read !== undefined && read <= size.vcpu * taskMillis * 1.1 ? read : undefined;
138
+ const cores = rs.map((r) => r.medianTaskMaxCoreMs).filter((n) => typeof n === "number");
139
+ const coreRead = cores.length === rs.length ? median(cores) : undefined;
140
+ const maxCoreMs = cpuMs !== undefined && coreRead !== undefined && coreRead <= taskMillis * 1.1 ? coreRead : undefined;
122
141
  return {
123
142
  provider: id,
124
143
  name: CATALOG.find((c) => c.id === id).name,
@@ -127,7 +146,13 @@ export function taskTable(reports, version = TASK_VERSION) {
127
146
  taskMs: taskMillis,
128
147
  phasesMs,
129
148
  hourlyUsd,
130
- taskUsd: taskUsd(id, size, createMs, taskMillis, cpuMs, ratio),
149
+ taskUsd: taskUsd(id, size, createMs, taskMillis, cpuMs, ratio, false, maxCoreMs),
150
+ reusedUsd: taskUsd(id, size, createMs, taskMillis, cpuMs, ratio, true, maxCoreMs),
151
+ runs: rs.reduce((n, r) => n + r.runs - (r.limited ?? 0), 0),
152
+ successRate: (() => {
153
+ const tried = rs.reduce((n, r) => n + r.runs - (r.limited ?? 0), 0);
154
+ return tried ? rs.reduce((n, r) => n + r.runs - r.failures, 0) / tried : 0;
155
+ })(),
131
156
  ...(cpuMs !== undefined ? { cpuMs } : {}),
132
157
  activeCpu: cpuHourlyAtFull(id, size) > 0,
133
158
  minimumSeconds: rules.minSeconds,
@@ -259,3 +284,88 @@ ${body || `<tr><td colspan="7" class="muted">No results yet. Run <code>npx @sand
259
284
  </html>
260
285
  `;
261
286
  }
287
+ export function loadBursts(dir) {
288
+ let files;
289
+ try {
290
+ files = readdirSync(dir).filter((f) => f.endsWith(".json"));
291
+ }
292
+ catch {
293
+ return [];
294
+ }
295
+ const out = [];
296
+ for (const f of files.sort()) {
297
+ try {
298
+ const r = JSON.parse(readFileSync(join(dir, f), "utf8"));
299
+ if (r?.tool === "sandboxrouter-burst" && Array.isArray(r.rows))
300
+ out.push(r);
301
+ }
302
+ catch {
303
+ /* skip unreadable files */
304
+ }
305
+ }
306
+ return out;
307
+ }
308
+ /**
309
+ * Each provider's latest burst of each kind (plain, or with a job), newest location wins, for the website:
310
+ * how many started, time to interactive at p50/p95/p99, and what the burst cost. Most started first, then
311
+ * fastest p50.
312
+ */
313
+ export function burstTable(reports, task, n) {
314
+ const latest = new Map();
315
+ for (const rep of reports) {
316
+ if ((rep.task ?? undefined) !== task)
317
+ continue;
318
+ if (n !== undefined && rep.n !== n)
319
+ continue;
320
+ for (const r of rep.rows) {
321
+ // Nothing started (an account blocked outright): nothing measured.
322
+ if (r.ok === 0)
323
+ continue;
324
+ if (!KNOWN.has(r.provider) || !benchmarksPublishable(r.provider))
325
+ continue;
326
+ const seen = latest.get(r.provider);
327
+ if (!seen || rep.date > seen.date)
328
+ latest.set(r.provider, { row: r, date: rep.date, label: rep.label });
329
+ }
330
+ }
331
+ return [...latest.values()]
332
+ .map(({ row, date, label }) => ({ ...row, name: CATALOG.find((c) => c.id === row.provider).name, measuredAt: date, label: label ?? null }))
333
+ .sort((a, b) => b.ok - a.ok || (a.p50Ms ?? Infinity) - (b.p50Ms ?? Infinity));
334
+ }
335
+ export function loadAgentReports(dir) {
336
+ let files;
337
+ try {
338
+ files = readdirSync(dir).filter((f) => f.endsWith(".json"));
339
+ }
340
+ catch {
341
+ return [];
342
+ }
343
+ const out = [];
344
+ for (const f of files.sort()) {
345
+ try {
346
+ const r = JSON.parse(readFileSync(join(dir, f), "utf8"));
347
+ if (r?.tool === "sandboxrouter-agent" && Array.isArray(r.rows))
348
+ out.push(r);
349
+ }
350
+ catch {
351
+ /* skip unreadable files */
352
+ }
353
+ }
354
+ return out;
355
+ }
356
+ /** Each provider's latest real-agent result: done right first, then cheapest sandbox per session. */
357
+ export function agentTable(reports) {
358
+ const latest = new Map();
359
+ for (const rep of reports) {
360
+ for (const r of rep.rows) {
361
+ if (!KNOWN.has(r.provider) || !benchmarksPublishable(r.provider))
362
+ continue;
363
+ const seen = latest.get(r.provider);
364
+ if (!seen || rep.date > seen.date)
365
+ latest.set(r.provider, { row: r, date: rep.date, model: rep.model });
366
+ }
367
+ }
368
+ return [...latest.values()]
369
+ .map(({ row, date, model }) => ({ ...row, name: CATALOG.find((c) => c.id === row.provider).name, measuredAt: date, model }))
370
+ .sort((a, b) => b.ok / b.runs - a.ok / a.runs || (a.medianUsd ?? Infinity) - (b.medianUsd ?? Infinity));
371
+ }
package/dist/ledger.d.ts CHANGED
@@ -37,6 +37,8 @@ export declare class Ledger {
37
37
  constructor(file: string);
38
38
  open(e: LedgerEntry): void;
39
39
  close(id: string, why?: string): void;
40
+ /** Size past which a close rewrites the file with only the open entries. */
41
+ static COMPACT_BYTES: number;
40
42
  /** Open entries, oldest first. */
41
43
  list(): LedgerEntry[];
42
44
  /** Rewrite the file with only the open entries. */
package/dist/ledger.js CHANGED
@@ -1,4 +1,4 @@
1
- import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
1
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { dirname, join } from "node:path";
4
4
  /**
@@ -27,7 +27,18 @@ export class Ledger {
27
27
  }
28
28
  close(id, why = "killed") {
29
29
  this.append({ op: "close", id, at: new Date().toISOString(), why });
30
+ // A long-lived server opens and closes sandboxes all day: once the file is mostly closed entries, rewrite
31
+ // it with only the open ones, so it stays small and `list()` stays fast.
32
+ try {
33
+ if (statSync(this.file).size > Ledger.COMPACT_BYTES)
34
+ this.compact();
35
+ }
36
+ catch {
37
+ /* no file yet, or unreadable: nothing to compact */
38
+ }
30
39
  }
40
+ /** Size past which a close rewrites the file with only the open entries. */
41
+ static COMPACT_BYTES = 256 * 1024;
31
42
  /** Open entries, oldest first. */
32
43
  list() {
33
44
  const open = new Map();
@@ -0,0 +1,54 @@
1
+ import type { ProviderId } from "./types.js";
2
+ /**
3
+ * The price index: what a few standard pieces of sandbox work cost today across the providers that passed
4
+ * the real-account check. Each line is the median of what the router would charge on each of them (list
5
+ * price, corrected by measured bills, with minimum charges and per-sandbox fees over the run), plus the
6
+ * cheapest. It moves only when a provider's price in the catalog changes.
7
+ */
8
+ export declare const INDEX_LINES: readonly [{
9
+ readonly id: "2x4-hour";
10
+ readonly label: "2 vCPU / 4 GB, one hour";
11
+ readonly unit: "per hour";
12
+ readonly spec: {
13
+ readonly vcpu: 2;
14
+ readonly memoryGb: 4;
15
+ readonly timeoutMinutes: 60;
16
+ };
17
+ readonly scale: 1;
18
+ }, {
19
+ readonly id: "agent-hour";
20
+ readonly label: "Agent session, one hour at 10% CPU";
21
+ readonly unit: "per hour";
22
+ readonly spec: {
23
+ readonly vcpu: 2;
24
+ readonly memoryGb: 4;
25
+ readonly timeoutMinutes: 60;
26
+ readonly cpuUtilization: 0.1;
27
+ };
28
+ readonly scale: 1;
29
+ }, {
30
+ readonly id: "calls-1000";
31
+ readonly label: "1,000 tool calls, 10 s each";
32
+ readonly unit: "per 1,000";
33
+ readonly spec: {
34
+ readonly vcpu: 2;
35
+ readonly memoryGb: 4;
36
+ readonly expectedSeconds: 10;
37
+ };
38
+ readonly scale: 1000;
39
+ }];
40
+ export interface IndexLine {
41
+ id: (typeof INDEX_LINES)[number]["id"];
42
+ label: string;
43
+ unit: string;
44
+ /** Median across the providers that fit, USD for the line's unit of work. */
45
+ median: number;
46
+ cheapest: {
47
+ provider: ProviderId;
48
+ name: string;
49
+ usd: number;
50
+ };
51
+ providers: number;
52
+ }
53
+ /** Today's index: one line per standard piece of work. */
54
+ export declare function priceIndex(verified?: readonly ProviderId[]): IndexLine[];
@@ -0,0 +1,50 @@
1
+ import { CATALOG } from "./catalog.js";
2
+ import { median } from "./bench-store.js";
3
+ import { Router, rankUsd, runHours } from "./router.js";
4
+ import { VERIFIED } from "./verified.js";
5
+ /**
6
+ * The price index: what a few standard pieces of sandbox work cost today across the providers that passed
7
+ * the real-account check. Each line is the median of what the router would charge on each of them (list
8
+ * price, corrected by measured bills, with minimum charges and per-sandbox fees over the run), plus the
9
+ * cheapest. It moves only when a provider's price in the catalog changes.
10
+ */
11
+ export const INDEX_LINES = [
12
+ { id: "2x4-hour", label: "2 vCPU / 4 GB, one hour", unit: "per hour", spec: { vcpu: 2, memoryGb: 4, timeoutMinutes: 60 }, scale: 1 },
13
+ {
14
+ id: "agent-hour",
15
+ label: "Agent session, one hour at 10% CPU",
16
+ unit: "per hour",
17
+ spec: { vcpu: 2, memoryGb: 4, timeoutMinutes: 60, cpuUtilization: 0.1 },
18
+ scale: 1,
19
+ },
20
+ { id: "calls-1000", label: "1,000 tool calls, 10 s each", unit: "per 1,000", spec: { vcpu: 2, memoryGb: 4, expectedSeconds: 10 }, scale: 1000 },
21
+ ];
22
+ // Stand-ins with every key "set": the index reads only the catalog, never a provider.
23
+ const stub = (id) => ({
24
+ id,
25
+ configured: () => true,
26
+ create: () => Promise.reject(new Error("the price index never starts sandboxes")),
27
+ connect: () => Promise.reject(new Error("the price index never starts sandboxes")),
28
+ });
29
+ /** Today's index: one line per standard piece of work. */
30
+ export function priceIndex(verified = Object.keys(VERIFIED)) {
31
+ const router = new Router({ providers: verified.map(stub), ledger: false, requireVerified: true, verified: [...verified] });
32
+ return INDEX_LINES.map((line) => {
33
+ const hours = runHours(line.spec);
34
+ const costs = router
35
+ .plan(line.spec, { strategy: "cheapest" })
36
+ .filter((c) => !c.skip)
37
+ // What the unit of work costs: a run of `hours`, times how many runs the line counts.
38
+ .map((c) => ({ provider: c.provider, usd: rankUsd(c, hours) * hours * line.scale }));
39
+ const best = costs[0];
40
+ const round = (n) => Math.round(n * 1e6) / 1e6;
41
+ return {
42
+ id: line.id,
43
+ label: line.label,
44
+ unit: line.unit,
45
+ median: round(median(costs.map((c) => c.usd * 1e6)) / 1e6),
46
+ cheapest: { provider: best.provider, name: CATALOG.find((p) => p.id === best.provider).name, usd: round(best.usd) },
47
+ providers: costs.length,
48
+ };
49
+ });
50
+ }
@@ -95,6 +95,10 @@ async function drain(stream, on) {
95
95
  class BeamBox {
96
96
  sb;
97
97
  env;
98
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
99
+ get native() {
100
+ return this.sb;
101
+ }
98
102
  nativeId;
99
103
  constructor(sb, env) {
100
104
  this.sb = sb;
@@ -72,6 +72,10 @@ export class BlaxelProvider {
72
72
  }
73
73
  class BlaxelBox {
74
74
  sbx;
75
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
76
+ get native() {
77
+ return this.sbx;
78
+ }
75
79
  nativeId;
76
80
  constructor(sbx) {
77
81
  this.sbx = sbx;
@@ -108,7 +108,9 @@ export class BoatProvider {
108
108
  return new BoatSandbox(this, id);
109
109
  }
110
110
  async connect(nativeId) {
111
- await this.ready(nativeId);
111
+ // Check it exists, but don't resume it: a handle may only be wanted to kill the sandbox, and resuming counts as a
112
+ // start against the plan's starts-per-hour. Data calls resume it on demand (call() waits on a 409 sandbox_not_ready).
113
+ await this.json("GET", `/sandboxes/${encodeURIComponent(nativeId)}`);
112
114
  return new BoatSandbox(this, nativeId);
113
115
  }
114
116
  }
@@ -122,6 +122,10 @@ export class DaytonaProvider {
122
122
  }
123
123
  class DaytonaBox {
124
124
  sbx;
125
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
126
+ get native() {
127
+ return this.sbx;
128
+ }
125
129
  nativeId;
126
130
  constructor(sbx) {
127
131
  this.sbx = sbx;
@@ -77,6 +77,10 @@ export class DenoProvider {
77
77
  }
78
78
  class DenoBox {
79
79
  sbx;
80
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
81
+ get native() {
82
+ return this.sbx;
83
+ }
80
84
  nativeId;
81
85
  constructor(sbx) {
82
86
  this.sbx = sbx;
@@ -63,6 +63,8 @@ export interface E2BCommandHandle {
63
63
  export declare class E2BCompatBox implements ProviderSandbox {
64
64
  protected sbx: E2BLikeSandbox;
65
65
  protected provider: ProviderId;
66
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
67
+ get native(): unknown;
66
68
  readonly nativeId: string;
67
69
  constructor(sbx: E2BLikeSandbox, provider?: ProviderId);
68
70
  exec(cmd: string, opts?: ExecOptions): Promise<ExecResult>;
@@ -74,6 +74,10 @@ export class E2BProvider {
74
74
  export class E2BCompatBox {
75
75
  sbx;
76
76
  provider;
77
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
78
+ get native() {
79
+ return this.sbx;
80
+ }
77
81
  nativeId;
78
82
  constructor(sbx, provider = "e2b") {
79
83
  this.sbx = sbx;
@@ -45,6 +45,10 @@ export class HopxProvider {
45
45
  }
46
46
  class HopxBox {
47
47
  sbx;
48
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
49
+ get native() {
50
+ return this.sbx;
51
+ }
48
52
  nativeId;
49
53
  constructor(sbx) {
50
54
  this.sbx = sbx;
@@ -78,6 +78,10 @@ export class LangSmithProvider {
78
78
  }
79
79
  class LangSmithBox {
80
80
  sbx;
81
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
82
+ get native() {
83
+ return this.sbx;
84
+ }
81
85
  constructor(sbx) {
82
86
  this.sbx = sbx;
83
87
  }
@@ -23,9 +23,14 @@ export class ModalProvider {
23
23
  const modal = await this.modal();
24
24
  const app = await modal.apps.fromName(APP_NAME, { createIfMissing: true });
25
25
  const image = modal.images.fromRegistry(spec.image?.modal ?? "python:3.13-slim");
26
+ // Modal's cpu is physical cores (1 core = 2 vCPUs); the catalog and the spec count vCPUs. Modal bills the
27
+ // larger of the reservation and actual use, so with cpuUtilization below 1 only that share is reserved
28
+ // (at least 1/8 core, Modal's own default) and the sandbox may burst to the full size when the host has room.
29
+ const cores = (spec.vcpu ?? DEFAULT_VCPU) / 2;
30
+ const share = Math.min(1, spec.cpuUtilization ?? 1);
26
31
  const sb = await modal.sandboxes.create(app, image, {
27
- // Modal's cpu is physical cores (1 core = 2 vCPUs); the catalog and the spec count vCPUs.
28
- cpu: (spec.vcpu ?? DEFAULT_VCPU) / 2,
32
+ cpu: share < 1 ? Math.max(0.125, cores * share) : cores,
33
+ ...(share < 1 ? { cpuLimit: cores } : {}),
29
34
  memoryMiB: Math.round((spec.memoryGb ?? DEFAULT_MEMORY_GB) * 1024),
30
35
  gpu: spec.gpu,
31
36
  timeoutMs: (spec.timeoutMinutes ?? 30) * 60_000,
@@ -51,6 +56,10 @@ async function drain(stream, on) {
51
56
  }
52
57
  class ModalBox {
53
58
  sb;
59
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
60
+ get native() {
61
+ return this.sb;
62
+ }
54
63
  nativeId;
55
64
  constructor(sb) {
56
65
  this.sb = sb;
@@ -93,6 +93,10 @@ export class MorphProvider {
93
93
  }
94
94
  class MorphBox {
95
95
  inst;
96
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
97
+ get native() {
98
+ return this.inst;
99
+ }
96
100
  nativeId;
97
101
  constructor(inst) {
98
102
  this.inst = inst;
@@ -72,6 +72,10 @@ export class RunloopProvider {
72
72
  }
73
73
  class RunloopBox {
74
74
  box;
75
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
76
+ get native() {
77
+ return this.box;
78
+ }
75
79
  nativeId;
76
80
  constructor(box) {
77
81
  this.box = box;
@@ -49,6 +49,10 @@ export class SpritesProvider {
49
49
  }
50
50
  class SpritesBox {
51
51
  sprite;
52
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
53
+ get native() {
54
+ return this.sprite;
55
+ }
52
56
  nativeId;
53
57
  constructor(sprite) {
54
58
  this.sprite = sprite;
@@ -69,6 +69,10 @@ export class TensorlakeProvider {
69
69
  }
70
70
  class TensorlakeBox {
71
71
  sbx;
72
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
73
+ get native() {
74
+ return this.sbx;
75
+ }
72
76
  nativeId;
73
77
  constructor(sbx) {
74
78
  this.sbx = sbx;
@@ -40,6 +40,10 @@ export class VercelProvider {
40
40
  }
41
41
  class VercelBox {
42
42
  sbx;
43
+ /** The provider SDK's own sandbox object, for what the router doesn't cover (RoutedSandbox.native). */
44
+ get native() {
45
+ return this.sbx;
46
+ }
43
47
  nativeId;
44
48
  constructor(sbx) {
45
49
  this.sbx = sbx;
@@ -0,0 +1,2 @@
1
+ import type { PublishedData } from "./recommend.js";
2
+ export declare const PUBLISHED: PublishedData;