@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
@@ -1,6 +1,8 @@
1
1
  import { readdirSync, readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { benchmarksPublishable, CATALOG, fittingSpec, hourlyCost } from "./catalog.js";
3
+ import { benchmarksPublishable, billingRules, CATALOG, cpuHourlyAtFull, fittingSpec, hourlyCost } from "./catalog.js";
4
+ import { BILLED_VS_LIST } from "./billing.js";
5
+ import { TASK_VERSION, taskByVersion, taskUsd } from "./task.js";
4
6
  import { median } from "./bench-store.js";
5
7
  export function makeReport(rows, opts) {
6
8
  return {
@@ -12,6 +14,7 @@ export function makeReport(rows, opts) {
12
14
  runs: opts.runs,
13
15
  // Only the shape matters for comparison; never ship env or metadata.
14
16
  spec: { vcpu: opts.spec.vcpu, memoryGb: opts.spec.memoryGb },
17
+ ...(opts.task ? { task: opts.task } : {}),
15
18
  node: process.version,
16
19
  platform: `${process.platform}-${process.arch}`,
17
20
  // Providers whose terms forbid publishing benchmarks stay out of anything meant to be shared.
@@ -41,18 +44,30 @@ export function loadReports(dir) {
41
44
  }
42
45
  const KNOWN = new Set(CATALOG.map((c) => c.id));
43
46
  /**
44
- * Each provider's latest run from each location (report label), then the median across locations, so
45
- * 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.
46
51
  */
47
52
  export function aggregate(reports) {
48
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;
49
62
  for (const rep of reports) {
50
63
  for (const r of rep.rows) {
51
64
  if (!KNOWN.has(r.provider))
52
65
  continue;
53
66
  const key = `${r.provider}\u0000${rep.label ?? ""}`;
67
+ if (Date.parse(newest.get(key)) - Date.parse(rep.date) > MONTH)
68
+ continue;
54
69
  const seen = latest.get(key);
55
- if (!seen || rep.date > seen.date)
70
+ if (!seen || r.runs > seen.row.runs || (r.runs === seen.row.runs && rep.date > seen.date))
56
71
  latest.set(key, { row: r, date: rep.date });
57
72
  }
58
73
  }
@@ -63,13 +78,16 @@ export function aggregate(reports) {
63
78
  const rs = xs.map((x) => x.row);
64
79
  const runs = rs.reduce((n, r) => n + r.runs, 0);
65
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);
66
83
  return {
67
84
  provider: id,
68
85
  name: CATALOG.find((c) => c.id === id).name,
69
86
  submissions: rs.length,
70
87
  medianCreateMs: median(rs.map((r) => r.medianCreateMs).filter((n) => typeof n === "number")),
71
88
  medianExecMs: median(rs.map((r) => r.medianExecMs).filter((n) => typeof n === "number")),
72
- successRate: runs ? ok / runs : 0,
89
+ successRate: attempted ? ok / attempted : 0,
90
+ runs: attempted,
73
91
  hourlyUsd: hourlyCost(id, fittingSpec(id)),
74
92
  size: fittingSpec(id),
75
93
  measuredAt: xs.map((x) => x.date).sort().at(-1),
@@ -77,6 +95,73 @@ export function aggregate(reports) {
77
95
  });
78
96
  return rows.sort((a, b) => (a.medianCreateMs ?? Infinity) - (b.medianCreateMs ?? Infinity));
79
97
  }
98
+ /**
99
+ * Cost of the standard task (src/task.ts) per provider, from reports made with `bench --task` at
100
+ * `version` (the short task's by default; TASKS.long.version for `--long`): each provider's latest run
101
+ * from each location, then the median across locations (as `aggregate` does). Cheapest task first.
102
+ */
103
+ export function taskTable(reports, version = TASK_VERSION) {
104
+ const def = taskByVersion(version);
105
+ if (!def)
106
+ return [];
107
+ const latest = new Map();
108
+ for (const rep of reports) {
109
+ if (rep.task !== version)
110
+ continue;
111
+ for (const r of rep.rows) {
112
+ if (!KNOWN.has(r.provider) || !r.taskPhasesMs || r.medianTaskMs === undefined || r.medianCreateMs === undefined)
113
+ continue;
114
+ const key = `${r.provider}\u0000${rep.label ?? ""}`;
115
+ const seen = latest.get(key);
116
+ if (!seen || rep.date > seen.date)
117
+ latest.set(key, { row: r, date: rep.date });
118
+ }
119
+ }
120
+ const by = new Map();
121
+ for (const x of latest.values())
122
+ by.set(x.row.provider, [...(by.get(x.row.provider) ?? []), x]);
123
+ const rows = [...by.entries()].map(([id, xs]) => {
124
+ const rs = xs.map((x) => x.row);
125
+ const createMs = median(rs.map((r) => r.medianCreateMs));
126
+ const taskMillis = median(rs.map((r) => r.medianTaskMs));
127
+ const phasesMs = Object.fromEntries(def.phases.map((p) => [p.id, median(rs.map((r) => r.taskPhasesMs[p.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 } : {}) };
130
+ const ratio = BILLED_VS_LIST[id]?.ratio ?? 1;
131
+ const hourlyUsd = hourlyCost(id, fittingSpec(id)) * ratio;
132
+ const rules = billingRules(id);
133
+ const cpus = rs.map((r) => r.medianTaskCpuMs).filter((n) => typeof n === "number");
134
+ // A container can show the whole host's /proc/stat (Daytona does): a reading beyond what the sandbox's
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.
136
+ const read = cpus.length === rs.length ? median(cpus) : undefined;
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;
141
+ return {
142
+ provider: id,
143
+ name: CATALOG.find((c) => c.id === id).name,
144
+ size,
145
+ createMs,
146
+ taskMs: taskMillis,
147
+ phasesMs,
148
+ hourlyUsd,
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
+ })(),
156
+ ...(cpuMs !== undefined ? { cpuMs } : {}),
157
+ activeCpu: cpuHourlyAtFull(id, size) > 0,
158
+ minimumSeconds: rules.minSeconds,
159
+ perSandboxUsd: rules.perSandboxUsd,
160
+ measuredAt: xs.map((x) => x.date).sort().at(-1),
161
+ };
162
+ });
163
+ return rows.sort((a, b) => a.taskUsd - b.taskUsd || a.provider.localeCompare(b.provider));
164
+ }
80
165
  const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
81
166
  function bar(value, max, text, tip) {
82
167
  if (value === undefined)
@@ -199,3 +284,88 @@ ${body || `<tr><td colspan="7" class="muted">No results yet. Run <code>npx @sand
199
284
  </html>
200
285
  `;
201
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;