@sandboxrouter/sdk 0.18.0 → 0.20.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/assistant.d.ts +172 -0
- package/dist/assistant.js +307 -0
- package/dist/bench.d.ts +10 -0
- package/dist/bench.js +17 -7
- package/dist/browser.d.ts +164 -0
- package/dist/browser.js +350 -0
- package/dist/catalog.js +11 -2
- package/dist/cli.js +2 -2
- package/dist/client.d.ts +106 -0
- package/dist/client.js +78 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/leaderboard.d.ts +5 -1
- package/dist/leaderboard.js +7 -0
- package/dist/move.d.ts +5 -0
- package/dist/move.js +4 -3
- package/dist/price-index.d.ts +51 -0
- package/dist/price-index.js +70 -0
- package/dist/providers/runcloud.js +11 -3
- package/dist/providers/vercel.d.ts +6 -0
- package/dist/providers/vercel.js +18 -2
- package/dist/published.js +588 -115
- package/dist/recommend.d.ts +3 -1
- package/dist/recommend.js +4 -0
- package/dist/results.js +136 -1
- package/dist/router.d.ts +22 -0
- package/dist/router.js +28 -0
- package/dist/save.d.ts +120 -0
- package/dist/save.js +276 -0
- package/dist/steady.d.ts +92 -0
- package/dist/steady.js +164 -0
- package/dist/task.d.ts +2 -0
- package/dist/task.js +2 -2
- package/dist/types.d.ts +2 -0
- package/package.json +4 -4
package/dist/steady.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type Router } from "./router.js";
|
|
2
|
+
import type { ProviderId } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Steadiness benchmark: one sandbox kept for several minutes, running the same small piece of work at a fixed
|
|
5
|
+
* interval, the way an agent session does a tool call now and then. Start time and a single job say how fast
|
|
6
|
+
* a provider is; this says whether it stays that fast, which depends on what else shares the machine.
|
|
7
|
+
*
|
|
8
|
+
* Each sample hashes 1 GB on one core (256 MB, four times) and is timed by the sandbox's own clock, so the
|
|
9
|
+
* network between the test machine and the provider is not in the number.
|
|
10
|
+
*/
|
|
11
|
+
export declare const STEADY_VERSION = "steady-v1";
|
|
12
|
+
export declare const STEADY_SAMPLE: string;
|
|
13
|
+
/** Milliseconds between the two clock readings a sample printed, or undefined if they are not there. */
|
|
14
|
+
export declare function sampleMs(stdout: string): number | undefined;
|
|
15
|
+
export interface SteadyRow {
|
|
16
|
+
provider: string;
|
|
17
|
+
size: {
|
|
18
|
+
vcpu: number;
|
|
19
|
+
memoryGb: number;
|
|
20
|
+
};
|
|
21
|
+
/** In-sandbox time of each sample that finished and passed its check, in order, in ms. */
|
|
22
|
+
sampleMs: number[];
|
|
23
|
+
medianMs?: number;
|
|
24
|
+
p95Ms?: number;
|
|
25
|
+
maxMs?: number;
|
|
26
|
+
/** Samples that failed, or were never run because the sandbox stopped answering. */
|
|
27
|
+
failures: number;
|
|
28
|
+
/** List price per hour at this size. */
|
|
29
|
+
hourlyUsd?: number;
|
|
30
|
+
}
|
|
31
|
+
/** A saved steadiness report (results/, tool "sandboxrouter-steady"). */
|
|
32
|
+
export interface SteadyReport {
|
|
33
|
+
tool: "sandboxrouter-steady";
|
|
34
|
+
version: string;
|
|
35
|
+
/** The sample's version: a change to the work makes older reports stop counting. */
|
|
36
|
+
task: string;
|
|
37
|
+
date: string;
|
|
38
|
+
label?: string;
|
|
39
|
+
by?: string;
|
|
40
|
+
spec: {
|
|
41
|
+
vcpu: number;
|
|
42
|
+
memoryGb: number;
|
|
43
|
+
};
|
|
44
|
+
/** Samples asked of each sandbox, and the seconds between their starts. */
|
|
45
|
+
samples: number;
|
|
46
|
+
intervalSeconds: number;
|
|
47
|
+
node: string;
|
|
48
|
+
platform: string;
|
|
49
|
+
rows: SteadyRow[];
|
|
50
|
+
}
|
|
51
|
+
export interface SteadyOptions {
|
|
52
|
+
router: Router;
|
|
53
|
+
providers: ProviderId[];
|
|
54
|
+
samples?: number;
|
|
55
|
+
intervalSeconds?: number;
|
|
56
|
+
spec?: {
|
|
57
|
+
vcpu: number;
|
|
58
|
+
memoryGb: number;
|
|
59
|
+
};
|
|
60
|
+
onProgress?: (message: string) => void;
|
|
61
|
+
/** For tests. */
|
|
62
|
+
sleep?: (ms: number) => Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
/** The numbers a row reports, from its samples. */
|
|
65
|
+
export declare function steadySummary(ms: number[]): Pick<SteadyRow, "medianMs" | "p95Ms" | "maxMs">;
|
|
66
|
+
/** One sandbox per provider, all providers at once: each only runs one core's worth of work every interval. */
|
|
67
|
+
export declare function steady(opts: SteadyOptions): Promise<SteadyRow[]>;
|
|
68
|
+
export declare function loadSteadyReports(dir: string): SteadyReport[];
|
|
69
|
+
/**
|
|
70
|
+
* For the website: per provider, every complete run of the current sample from the 30 days before its newest
|
|
71
|
+
* one. One sandbox is one machine at one time, so the row is the median across runs, and the slowest sample
|
|
72
|
+
* of any of them. Steadiest first: the smallest gap between the 95th percentile and the median.
|
|
73
|
+
*/
|
|
74
|
+
export declare function steadyTable(reports: SteadyReport[]): {
|
|
75
|
+
provider: string;
|
|
76
|
+
name: string;
|
|
77
|
+
size: {
|
|
78
|
+
vcpu: number;
|
|
79
|
+
memoryGb: number;
|
|
80
|
+
};
|
|
81
|
+
medianMs: number;
|
|
82
|
+
maxMs: number;
|
|
83
|
+
/** How much slower the 95th percentile sample was than the median one, as a fraction (0.04 = 4%): the median across runs. */
|
|
84
|
+
spread: number;
|
|
85
|
+
/** Each run's own figure, lowest first. */
|
|
86
|
+
spreads: number[];
|
|
87
|
+
runs: number;
|
|
88
|
+
samples: number;
|
|
89
|
+
intervalSeconds: number;
|
|
90
|
+
hourlyUsd?: number | undefined;
|
|
91
|
+
measuredAt: string;
|
|
92
|
+
}[];
|
package/dist/steady.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { benchmarksPublishable, CATALOG, DEFAULT_MEMORY_GB, DEFAULT_VCPU, fixedSize, hourlyCost } from "./catalog.js";
|
|
4
|
+
import { median } from "./bench-store.js";
|
|
5
|
+
import { percentile } from "./burst.js";
|
|
6
|
+
import { sizeOf } from "./router.js";
|
|
7
|
+
import { hashZeros, phaseCommand, ZERO_256_SHA256 } from "./task.js";
|
|
8
|
+
/**
|
|
9
|
+
* Steadiness benchmark: one sandbox kept for several minutes, running the same small piece of work at a fixed
|
|
10
|
+
* interval, the way an agent session does a tool call now and then. Start time and a single job say how fast
|
|
11
|
+
* a provider is; this says whether it stays that fast, which depends on what else shares the machine.
|
|
12
|
+
*
|
|
13
|
+
* Each sample hashes 1 GB on one core (256 MB, four times) and is timed by the sandbox's own clock, so the
|
|
14
|
+
* network between the test machine and the provider is not in the number.
|
|
15
|
+
*/
|
|
16
|
+
export const STEADY_VERSION = "steady-v1";
|
|
17
|
+
const MARK = "SRSTEADY";
|
|
18
|
+
// The sandbox's own clock: nanoseconds from GNU date where the image has it, else /proc/uptime (seconds, to
|
|
19
|
+
// a hundredth), which busybox images and every Linux kernel have.
|
|
20
|
+
const CLOCK = `t=$(date +%s%N 2> /dev/null); case "$t" in ""|*[!0-9]*) cut -d' ' -f1 /proc/uptime ;; *) echo "$t" ;; esac`;
|
|
21
|
+
export const STEADY_SAMPLE = `a=$(${CLOCK}); (${phaseCommand(hashZeros(268435456, ZERO_256_SHA256), 4)}); rc=$?; b=$(${CLOCK}); echo "${MARK}|$a|$b"; exit $rc`;
|
|
22
|
+
/** Milliseconds between the two clock readings a sample printed, or undefined if they are not there. */
|
|
23
|
+
export function sampleMs(stdout) {
|
|
24
|
+
const line = stdout.split("\n").find((l) => l.startsWith(`${MARK}|`));
|
|
25
|
+
const [, a, b] = line?.trim().split("|") ?? [];
|
|
26
|
+
let ms;
|
|
27
|
+
// Nanoseconds since 1970 are 19 digits; uptime is seconds with two decimals.
|
|
28
|
+
if (/^\d{16,}$/.test(a ?? "") && /^\d{16,}$/.test(b ?? ""))
|
|
29
|
+
ms = Number((BigInt(b) - BigInt(a)) / 1000000n);
|
|
30
|
+
else if (/^\d+\.\d+$/.test(a ?? "") && /^\d+\.\d+$/.test(b ?? ""))
|
|
31
|
+
ms = Math.round((Number(b) - Number(a)) * 1000);
|
|
32
|
+
else
|
|
33
|
+
return undefined;
|
|
34
|
+
return ms >= 1 ? ms : undefined;
|
|
35
|
+
}
|
|
36
|
+
/** The numbers a row reports, from its samples. */
|
|
37
|
+
export function steadySummary(ms) {
|
|
38
|
+
if (!ms.length)
|
|
39
|
+
return {};
|
|
40
|
+
const sorted = [...ms].sort((a, b) => a - b);
|
|
41
|
+
return { medianMs: median(sorted), p95Ms: percentile(sorted, 0.95), maxMs: sorted.at(-1) };
|
|
42
|
+
}
|
|
43
|
+
/** One sandbox per provider, all providers at once: each only runs one core's worth of work every interval. */
|
|
44
|
+
export async function steady(opts) {
|
|
45
|
+
const samples = opts.samples ?? 60;
|
|
46
|
+
const interval = (opts.intervalSeconds ?? 10) * 1000;
|
|
47
|
+
const asked = opts.spec ?? { vcpu: DEFAULT_VCPU, memoryGb: DEFAULT_MEMORY_GB };
|
|
48
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
49
|
+
const minutes = Math.ceil((samples * interval) / 60_000) + 5;
|
|
50
|
+
return Promise.all(opts.providers.map(async (provider) => {
|
|
51
|
+
const spec = { ...asked, ...fixedSize(provider, asked), timeoutMinutes: minutes };
|
|
52
|
+
const ms = [];
|
|
53
|
+
let failures = 0;
|
|
54
|
+
let box;
|
|
55
|
+
try {
|
|
56
|
+
box = await opts.router.create(spec, { provider, fallback: false });
|
|
57
|
+
const t0 = Date.now();
|
|
58
|
+
for (let i = 0; i < samples; i++) {
|
|
59
|
+
const wait = t0 + i * interval - Date.now();
|
|
60
|
+
if (wait > 0)
|
|
61
|
+
await sleep(wait);
|
|
62
|
+
try {
|
|
63
|
+
const r = await box.exec(STEADY_SAMPLE, { timeoutSeconds: 120 });
|
|
64
|
+
const took = r.exitCode === 0 ? sampleMs(r.stdout) : undefined;
|
|
65
|
+
if (took === undefined)
|
|
66
|
+
failures++;
|
|
67
|
+
else
|
|
68
|
+
ms.push(took);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
failures++;
|
|
72
|
+
}
|
|
73
|
+
if ((i + 1) % 10 === 0)
|
|
74
|
+
opts.onProgress?.(`${provider}: ${i + 1}/${samples} samples, ${failures} failed`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
// No sandbox: every sample is missing.
|
|
79
|
+
failures = samples - ms.length;
|
|
80
|
+
opts.onProgress?.(`${provider}: ${e.message.replace(/\s+/g, " ").slice(0, 200)}`);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
await box?.kill().catch(() => { });
|
|
84
|
+
}
|
|
85
|
+
let hourlyUsd;
|
|
86
|
+
try {
|
|
87
|
+
hourlyUsd = hourlyCost(provider, spec);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
/* no price: the row still stands */
|
|
91
|
+
}
|
|
92
|
+
return { provider, size: sizeOf(provider, spec), sampleMs: ms, ...steadySummary(ms), failures, ...(hourlyUsd !== undefined ? { hourlyUsd } : {}) };
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
export function loadSteadyReports(dir) {
|
|
96
|
+
let files;
|
|
97
|
+
try {
|
|
98
|
+
files = readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const out = [];
|
|
104
|
+
for (const f of files.sort()) {
|
|
105
|
+
try {
|
|
106
|
+
const r = JSON.parse(readFileSync(join(dir, f), "utf8"));
|
|
107
|
+
if (r?.tool === "sandboxrouter-steady" && Array.isArray(r.rows))
|
|
108
|
+
out.push(r);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
/* skip unreadable files */
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
const KNOWN = new Set(CATALOG.map((c) => c.id));
|
|
117
|
+
/**
|
|
118
|
+
* For the website: per provider, every complete run of the current sample from the 30 days before its newest
|
|
119
|
+
* one. One sandbox is one machine at one time, so the row is the median across runs, and the slowest sample
|
|
120
|
+
* of any of them. Steadiest first: the smallest gap between the 95th percentile and the median.
|
|
121
|
+
*/
|
|
122
|
+
export function steadyTable(reports) {
|
|
123
|
+
const MONTH = 30 * 86_400_000;
|
|
124
|
+
const by = new Map();
|
|
125
|
+
for (const rep of reports) {
|
|
126
|
+
if (rep.task !== STEADY_VERSION)
|
|
127
|
+
continue;
|
|
128
|
+
for (const row of rep.rows) {
|
|
129
|
+
if (!KNOWN.has(row.provider) || !benchmarksPublishable(row.provider))
|
|
130
|
+
continue;
|
|
131
|
+
by.set(row.provider, [...(by.get(row.provider) ?? []), { row, rep }]);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return [...by.entries()]
|
|
135
|
+
.flatMap(([provider, all]) => {
|
|
136
|
+
const newest = all.reduce((a, b) => (a.rep.date >= b.rep.date ? a : b));
|
|
137
|
+
// Same size and schedule as the newest run, so the runs behind a row are the same test.
|
|
138
|
+
const runs = all.filter(({ row, rep }) => Date.parse(newest.rep.date) - Date.parse(rep.date) <= MONTH &&
|
|
139
|
+
rep.samples === newest.rep.samples && rep.intervalSeconds === newest.rep.intervalSeconds &&
|
|
140
|
+
row.size.vcpu === newest.row.size.vcpu && row.size.memoryGb === newest.row.size.memoryGb);
|
|
141
|
+
// A run with a failed sample keeps the provider off the table: it did not hold for the whole test.
|
|
142
|
+
if (runs.some(({ row, rep }) => row.failures !== 0 || row.sampleMs.length !== rep.samples || row.medianMs === undefined || row.p95Ms === undefined))
|
|
143
|
+
return [];
|
|
144
|
+
const spreads = runs.map(({ row }) => row.p95Ms / row.medianMs - 1).sort((a, b) => a - b);
|
|
145
|
+
const mid = Math.floor(spreads.length / 2);
|
|
146
|
+
return [{
|
|
147
|
+
provider,
|
|
148
|
+
name: CATALOG.find((c) => c.id === provider).name,
|
|
149
|
+
size: newest.row.size,
|
|
150
|
+
medianMs: median(runs.map(({ row }) => row.medianMs)),
|
|
151
|
+
maxMs: Math.max(...runs.map(({ row }) => row.maxMs)),
|
|
152
|
+
/** How much slower the 95th percentile sample was than the median one, as a fraction (0.04 = 4%): the median across runs. */
|
|
153
|
+
spread: spreads.length % 2 ? spreads[mid] : (spreads[mid - 1] + spreads[mid]) / 2,
|
|
154
|
+
/** Each run's own figure, lowest first. */
|
|
155
|
+
spreads,
|
|
156
|
+
runs: runs.length,
|
|
157
|
+
samples: newest.rep.samples,
|
|
158
|
+
intervalSeconds: newest.rep.intervalSeconds,
|
|
159
|
+
...(newest.row.hourlyUsd !== undefined ? { hourlyUsd: newest.row.hourlyUsd } : {}),
|
|
160
|
+
measuredAt: newest.rep.date,
|
|
161
|
+
}];
|
|
162
|
+
})
|
|
163
|
+
.sort((a, b) => a.spread - b.spread || a.medianMs - b.medianMs);
|
|
164
|
+
}
|
package/dist/task.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ export interface TaskPhaseDef {
|
|
|
32
32
|
/** Seconds the phase may take (default 300, or 900 for a repeated phase). */
|
|
33
33
|
timeoutSeconds?: number;
|
|
34
34
|
}
|
|
35
|
+
export declare const ZERO_256_SHA256 = "a6d72ac7690f53be6ae46ba88506bd97302a093f7108472bd9efc3cefda06484";
|
|
36
|
+
export declare const hashZeros: (count: number, hash: string) => string;
|
|
35
37
|
/** `cpuUtilization`: the hint the job's sandboxes start with (the agent loop is mostly idle), which Modal reserves and pricing uses. */
|
|
36
38
|
export declare const TASKS: Record<TaskKind, {
|
|
37
39
|
version: string;
|
package/dist/task.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { billingRules, cpuHourlyAtFull, hourlyCost, info } from "./catalog.js";
|
|
2
|
-
const ZERO_256_SHA256 = "a6d72ac7690f53be6ae46ba88506bd97302a093f7108472bd9efc3cefda06484";
|
|
2
|
+
export const ZERO_256_SHA256 = "a6d72ac7690f53be6ae46ba88506bd97302a093f7108472bd9efc3cefda06484";
|
|
3
3
|
const ZERO_512_SHA256 = "9acca8e8c22201155389f65abbf6bc9723edc7384ead80503839f49dcc56d767";
|
|
4
|
-
const hashZeros = (count, hash) => `hash=$(head -c ${count} /dev/zero | sha256sum) && [ "${'${hash%% *}'}" = "${hash}" ]`;
|
|
4
|
+
export const hashZeros = (count, hash) => `hash=$(head -c ${count} /dev/zero | sha256sum) && [ "${'${hash%% *}'}" = "${hash}" ]`;
|
|
5
5
|
const HASH_DISK = [
|
|
6
6
|
// One core: hash 512 MB of zeros.
|
|
7
7
|
{ id: "cpu", label: "1 core", cmd: hashZeros(536870912, ZERO_512_SHA256) },
|
package/dist/types.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export interface SandboxSpec {
|
|
|
38
38
|
/**
|
|
39
39
|
* Provider-specific image/template, keyed by provider, e.g.
|
|
40
40
|
* { maritime: "python", e2b: "code-interpreter-v1", modal: "python:3.13-slim" }.
|
|
41
|
+
* Once any image is named, only the providers named are routed to: the sandbox never starts on a
|
|
42
|
+
* provider's default image by fallback. Routing picks among them as usual (cheapest, fastest).
|
|
41
43
|
*/
|
|
42
44
|
image?: Partial<Record<ProviderId, string>>;
|
|
43
45
|
/** Free-form tags stored on the sandbox where the provider supports it. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandboxrouter/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "One API for every sandbox provider: route AI agents' code by price, speed or capability, with automatic fallback. Free and open source.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -180,18 +180,18 @@
|
|
|
180
180
|
"@aws-sdk/client-appstream": "^3.1162.0",
|
|
181
181
|
"@aws-sdk/credential-provider-node": "^3.972.93",
|
|
182
182
|
"@blaxel/core": "^0.3.34",
|
|
183
|
-
"@daytonaio/sdk": "^0.
|
|
183
|
+
"@daytonaio/sdk": "^0.234.0",
|
|
184
184
|
"@e2b/desktop": "^2.5.0",
|
|
185
185
|
"@fly/sprites": "^0.2.4",
|
|
186
186
|
"@hopx-ai/sdk": "^0.5.1",
|
|
187
|
-
"@limrun/api": "^0.
|
|
187
|
+
"@limrun/api": "^0.79.6",
|
|
188
188
|
"@mobilerun/sdk": "^6.1.0",
|
|
189
189
|
"@northflank/js-client": "^0.13.0",
|
|
190
190
|
"@runloop/api-client": "^3.0.0",
|
|
191
191
|
"@smithy/signature-v4": "^5.7.5",
|
|
192
192
|
"@tensorlakeai/tensorlake": "^0.5.161",
|
|
193
193
|
"@types/node": "^26.6.6",
|
|
194
|
-
"@vercel/sandbox": "^
|
|
194
|
+
"@vercel/sandbox": "^5.0.0",
|
|
195
195
|
"e2b": "^2.63.0",
|
|
196
196
|
"modal": "^0.11.1",
|
|
197
197
|
"morphcloud": "^0.0.20",
|