@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.
- package/README.md +3 -2
- package/dist/agent-bench.d.ts +39 -0
- package/dist/agent-bench.js +150 -0
- package/dist/bench-store.js +11 -2
- package/dist/bench.d.ts +12 -0
- package/dist/bench.js +24 -3
- package/dist/burst.d.ts +81 -0
- package/dist/burst.js +183 -0
- package/dist/catalog.d.ts +12 -0
- package/dist/catalog.js +15 -11
- package/dist/check.d.ts +2 -0
- package/dist/check.js +8 -0
- package/dist/cli.js +227 -5
- package/dist/compare.d.ts +48 -0
- package/dist/compare.js +78 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/leaderboard.d.ts +74 -2
- package/dist/leaderboard.js +117 -7
- package/dist/ledger.d.ts +2 -0
- package/dist/ledger.js +12 -1
- package/dist/price-index.d.ts +54 -0
- package/dist/price-index.js +50 -0
- package/dist/providers/beam.js +4 -0
- package/dist/providers/blaxel.js +4 -0
- package/dist/providers/boat.js +3 -1
- package/dist/providers/daytona.js +4 -0
- package/dist/providers/deno.js +4 -0
- package/dist/providers/e2b.d.ts +2 -0
- package/dist/providers/e2b.js +4 -0
- package/dist/providers/hopx.js +4 -0
- package/dist/providers/langsmith.js +4 -0
- package/dist/providers/modal.js +11 -2
- package/dist/providers/morph.js +4 -0
- package/dist/providers/runloop.js +4 -0
- package/dist/providers/sprites.js +4 -0
- package/dist/providers/tensorlake.js +4 -0
- package/dist/providers/vercel.js +4 -0
- package/dist/published.d.ts +2 -0
- package/dist/published.js +2087 -0
- package/dist/recommend.d.ts +117 -0
- package/dist/recommend.js +103 -0
- package/dist/results.js +93 -1
- package/dist/router.d.ts +45 -0
- package/dist/router.js +69 -4
- package/dist/submit.d.ts +6 -0
- package/dist/submit.js +70 -0
- package/dist/task.d.ts +17 -2
- package/dist/task.js +74 -19
- package/dist/types.d.ts +5 -0
- package/dist/util.d.ts +2 -0
- package/dist/util.js +2 -0
- package/package.json +1 -1
package/dist/task.d.ts
CHANGED
|
@@ -15,19 +15,29 @@ import type { ProviderId, ProviderSandbox } from "./types.js";
|
|
|
15
15
|
* provider without it fails the task, which is itself worth knowing.
|
|
16
16
|
* - "download": fetch the 53 MB Node.js release from nodejs.org's CDN, with curl, else wget, else python3:
|
|
17
17
|
* what installing toolchains and packages depends on.
|
|
18
|
+
* - "repo": what a coding agent does first: fetch Node 22 and a pinned commit of a real TypeScript project
|
|
19
|
+
* (sandboxRouter itself, the 0.10.0 release), `npm ci`, then typecheck it. Needs only tar and a way to
|
|
20
|
+
* download (curl, wget or python3), so a bare image can run it.
|
|
21
|
+
* - "agent": an agent loop with simulated model calls: 10 turns of waiting 6 s (the model thinking; the
|
|
22
|
+
* sandbox sits idle) and then a short Python tool call. About a minute, mostly idle, which is where
|
|
23
|
+
* providers that bill active CPU differ from ones that bill what you reserve.
|
|
18
24
|
*
|
|
19
25
|
* Changing a phase changes what the numbers mean: bump that task's version, and older reports stop counting.
|
|
20
26
|
*/
|
|
21
|
-
export type TaskKind = "short" | "long" | "python" | "download";
|
|
27
|
+
export type TaskKind = "short" | "long" | "python" | "download" | "agent" | "repo";
|
|
22
28
|
export interface TaskPhaseDef {
|
|
23
29
|
id: string;
|
|
24
30
|
label: string;
|
|
25
31
|
cmd: string;
|
|
32
|
+
/** Seconds the phase may take (default 300, or 900 for a repeated phase). */
|
|
33
|
+
timeoutSeconds?: number;
|
|
26
34
|
}
|
|
35
|
+
/** `cpuUtilization`: the hint the job's sandboxes start with (the agent loop is mostly idle), which Modal reserves and pricing uses. */
|
|
27
36
|
export declare const TASKS: Record<TaskKind, {
|
|
28
37
|
version: string;
|
|
29
38
|
repeat: number;
|
|
30
39
|
phases: TaskPhaseDef[];
|
|
40
|
+
cpuUtilization?: number;
|
|
31
41
|
}>;
|
|
32
42
|
/** The short task's version and phases, which is what plain `bench --task` records. */
|
|
33
43
|
export declare const TASK_VERSION: string;
|
|
@@ -42,7 +52,11 @@ export declare function phaseCommand(cmd: string, repeat: number): string;
|
|
|
42
52
|
export interface TaskRun {
|
|
43
53
|
ms: PhaseMs;
|
|
44
54
|
cpuMs?: number;
|
|
55
|
+
/** The busiest single core's busy time, summed over the phases: what a per-VM CPU meter scales by vCPUs. */
|
|
56
|
+
maxCoreMs?: number;
|
|
45
57
|
}
|
|
58
|
+
/** The busiest core's busy milliseconds between two readings, or undefined without per-core lines. */
|
|
59
|
+
export declare function maxCoreMs(before: string, after: string): number | undefined;
|
|
46
60
|
/** Busy CPU milliseconds between two /proc/stat "cpu" lines: user, nice, system, irq and softirq (not idle, iowait or steal), at 100 ticks a second. */
|
|
47
61
|
export declare function busyMs(before: string, after: string): number | undefined;
|
|
48
62
|
/** Runs a standard task in `box`: milliseconds per phase (network round trip taken out) and CPU time used. Throws if a phase fails. */
|
|
@@ -62,4 +76,5 @@ export declare const taskMs: (phases: PhaseMs) => number;
|
|
|
62
76
|
export declare function taskUsd(provider: ProviderId, size: {
|
|
63
77
|
vcpu: number;
|
|
64
78
|
memoryGb: number;
|
|
65
|
-
|
|
79
|
+
cpuUtilization?: number;
|
|
80
|
+
}, createMs: number, taskMillis: number, cpuMillis?: number, billedVsList?: number, reused?: boolean, maxCoreMillis?: number): number;
|
package/dist/task.js
CHANGED
|
@@ -20,10 +20,41 @@ const PYTHON = [
|
|
|
20
20
|
// The Node.js 22.11.0 Linux release (53 MB), from nodejs.org's CDN: a real download, like installing a toolchain.
|
|
21
21
|
const DOWNLOAD_URL = "https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-x64.tar.gz";
|
|
22
22
|
const PY_FETCH = `import shutil, urllib.request; shutil.copyfileobj(urllib.request.urlopen('${DOWNLOAD_URL}'), open('/dev/null', 'wb'))`;
|
|
23
|
+
// The real-repo job's sources, pinned so every provider does exactly the same work.
|
|
24
|
+
const REPO_TARBALL = "https://codeload.github.com/gigialc/sandboxrouter/tar.gz/ba2b32a1a403a93acad75a707f55a2eac9368f7a";
|
|
25
|
+
const NODE_BASE = "https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux";
|
|
26
|
+
const FETCH = [
|
|
27
|
+
"set -e",
|
|
28
|
+
'case "$(uname -m)" in aarch64|arm64) A=arm64 ;; *) A=x64 ;; esac',
|
|
29
|
+
`get() { if command -v curl > /dev/null; then curl -sSfL -o "$2" "$1"; elif command -v wget > /dev/null; then wget -q -O "$2" "$1"; else python3 -c "import shutil, sys, urllib.request; shutil.copyfileobj(urllib.request.urlopen(sys.argv[1]), open(sys.argv[2], 'wb'))" "$1" "$2"; fi; }`,
|
|
30
|
+
"rm -rf /tmp/sr-node /tmp/sr-repo && mkdir -p /tmp/sr-node /tmp/sr-repo",
|
|
31
|
+
`get "${NODE_BASE}-$A.tar.gz" /tmp/sr-node.tgz && tar xzf /tmp/sr-node.tgz -C /tmp/sr-node --strip-components=1`,
|
|
32
|
+
`get "${REPO_TARBALL}" /tmp/sr-repo.tgz && tar xzf /tmp/sr-repo.tgz -C /tmp/sr-repo --strip-components=1`,
|
|
33
|
+
"set +e",
|
|
34
|
+
].join("\n");
|
|
35
|
+
const IN_REPO = "cd /tmp/sr-repo && PATH=/tmp/sr-node/bin:$PATH";
|
|
36
|
+
// One tool call in the agent loop: a little real work, like reading files and running a check.
|
|
37
|
+
const TOOL = "import json, hashlib; d = [{'i': i, 'h': hashlib.sha256(str(i).encode()).hexdigest()} for i in range(40000)]; print(len(json.dumps(d)))";
|
|
38
|
+
/** `cpuUtilization`: the hint the job's sandboxes start with (the agent loop is mostly idle), which Modal reserves and pricing uses. */
|
|
23
39
|
export const TASKS = {
|
|
24
40
|
short: { version: "v1", repeat: 1, phases: HASH_DISK },
|
|
25
41
|
long: { version: "v1-long", repeat: 40, phases: HASH_DISK },
|
|
26
42
|
python: { version: "python-v1", repeat: 1, phases: [{ id: "python", label: "Python", cmd: `python3 -c "${PYTHON}"` }] },
|
|
43
|
+
repo: {
|
|
44
|
+
version: "repo-v1",
|
|
45
|
+
repeat: 1,
|
|
46
|
+
phases: [
|
|
47
|
+
{ id: "fetch", label: "fetch Node and the repo", cmd: FETCH, timeoutSeconds: 600 },
|
|
48
|
+
{ id: "install", label: "npm ci", cmd: `${IN_REPO} npm ci --no-audit --no-fund --loglevel=error`, timeoutSeconds: 900 },
|
|
49
|
+
{ id: "typecheck", label: "typecheck", cmd: `${IN_REPO} ./node_modules/.bin/tsc --noEmit -p .`, timeoutSeconds: 600 },
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
agent: {
|
|
53
|
+
version: "agent-v1",
|
|
54
|
+
repeat: 1,
|
|
55
|
+
cpuUtilization: 0.1,
|
|
56
|
+
phases: [{ id: "agent", label: "10 turns", cmd: `n=0; while [ $n -lt 10 ]; do sleep 6; python3 -c "${TOOL}" > /dev/null; n=$((n+1)); done` }],
|
|
57
|
+
},
|
|
27
58
|
download: {
|
|
28
59
|
version: "download-v1",
|
|
29
60
|
repeat: 1,
|
|
@@ -52,18 +83,33 @@ export function phaseCommand(cmd, repeat) {
|
|
|
52
83
|
// Wraps a phase to read /proc/stat's total CPU line before and after it, so the run also reports the CPU
|
|
53
84
|
// time it really used: what providers that bill active CPU charge for.
|
|
54
85
|
const MARK = "SRCPU";
|
|
55
|
-
|
|
86
|
+
// Every "cpu" line (the total, then one per core), joined with ";" so the reading stays on one output line.
|
|
87
|
+
const STAT = `grep '^cpu' /proc/stat 2> /dev/null | tr '\\n' ';'`;
|
|
88
|
+
const withCpu = (cmd) => `a=$(${STAT}); ${cmd}; rc=$?; b=$(${STAT}); echo "${MARK}|$a|$b"; exit $rc`;
|
|
89
|
+
/** Busy ticks on one /proc/stat cpu line: user, nice, system, irq and softirq (not idle, iowait or steal). */
|
|
90
|
+
const lineTicks = (line) => {
|
|
91
|
+
const f = line.trim().split(/\s+/);
|
|
92
|
+
if (!/^cpu\d*$/.test(f[0] ?? "") || f.length < 8)
|
|
93
|
+
return undefined;
|
|
94
|
+
const n = f.slice(1).map(Number);
|
|
95
|
+
return n[0] + n[1] + n[2] + n[5] + n[6];
|
|
96
|
+
};
|
|
97
|
+
const perCpu = (reading) => new Map(reading.split(";").map((l) => [l.trim().split(/\s+/)[0], lineTicks(l)]).filter(([k, v]) => k && v !== undefined));
|
|
98
|
+
/** The busiest core's busy milliseconds between two readings, or undefined without per-core lines. */
|
|
99
|
+
export function maxCoreMs(before, after) {
|
|
100
|
+
const a = perCpu(before);
|
|
101
|
+
const b = perCpu(after);
|
|
102
|
+
const cores = [...b.keys()].filter((k) => k !== "cpu" && a.has(k));
|
|
103
|
+
if (!cores.length)
|
|
104
|
+
return undefined;
|
|
105
|
+
const deltas = cores.map((k) => (b.get(k) - a.get(k)) * 10);
|
|
106
|
+
return deltas.some((d) => !(d >= 0)) ? undefined : Math.max(...deltas);
|
|
107
|
+
}
|
|
56
108
|
/** Busy CPU milliseconds between two /proc/stat "cpu" lines: user, nice, system, irq and softirq (not idle, iowait or steal), at 100 ticks a second. */
|
|
57
109
|
export function busyMs(before, after) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return undefined;
|
|
62
|
-
const n = f.slice(1).map(Number);
|
|
63
|
-
return n[0] + n[1] + n[2] + n[5] + n[6];
|
|
64
|
-
};
|
|
65
|
-
const a = ticks(before);
|
|
66
|
-
const b = ticks(after);
|
|
110
|
+
const total = (reading) => perCpu(reading).get("cpu");
|
|
111
|
+
const a = total(before);
|
|
112
|
+
const b = total(after);
|
|
67
113
|
return a === undefined || b === undefined || !(b >= a) ? undefined : (b - a) * 10;
|
|
68
114
|
}
|
|
69
115
|
/** Runs a standard task in `box`: milliseconds per phase (network round trip taken out) and CPU time used. Throws if a phase fails. */
|
|
@@ -78,17 +124,20 @@ export async function runTask(box, kind = "short") {
|
|
|
78
124
|
const overhead = rtt.sort((a, b) => a - b)[1];
|
|
79
125
|
const out = {};
|
|
80
126
|
let cpuMs = 0;
|
|
127
|
+
let coreMs = 0;
|
|
81
128
|
for (const p of phases) {
|
|
82
129
|
const t = performance.now();
|
|
83
|
-
const r = await box.exec(withCpu(phaseCommand(p.cmd, repeat)), { timeoutSeconds: repeat > 1 ? 900 : 300 });
|
|
130
|
+
const r = await box.exec(withCpu(phaseCommand(p.cmd, repeat)), { timeoutSeconds: p.timeoutSeconds ?? (repeat > 1 ? 900 : 300) });
|
|
84
131
|
if (r.exitCode !== 0)
|
|
85
132
|
throw new Error(`task phase ${p.id} exited ${r.exitCode}: ${(r.stderr || r.stdout).slice(0, 120)}`);
|
|
86
133
|
out[p.id] = Math.max(1, Math.round(performance.now() - t - overhead));
|
|
87
134
|
const line = r.stdout.split("\n").find((l) => l.startsWith(`${MARK}|`));
|
|
88
135
|
const used = line ? busyMs(line.split("|")[1] ?? "", line.split("|")[2] ?? "") : undefined;
|
|
89
136
|
cpuMs = cpuMs === undefined || used === undefined ? undefined : cpuMs + used;
|
|
137
|
+
const core = line ? maxCoreMs(line.split("|")[1] ?? "", line.split("|")[2] ?? "") : undefined;
|
|
138
|
+
coreMs = coreMs === undefined || core === undefined ? undefined : coreMs + core;
|
|
90
139
|
}
|
|
91
|
-
return { ms: out, ...(cpuMs !== undefined ? { cpuMs } : {}) };
|
|
140
|
+
return { ms: out, ...(cpuMs !== undefined ? { cpuMs } : {}), ...(cpuMs !== undefined && coreMs !== undefined ? { maxCoreMs: coreMs } : {}) };
|
|
92
141
|
}
|
|
93
142
|
/** The whole task's time: the phases added up. */
|
|
94
143
|
export const taskMs = (phases) => Object.values(phases).reduce((s, ms) => s + ms, 0);
|
|
@@ -102,17 +151,23 @@ export const taskMs = (phases) => Object.values(phases).reduce((s, ms) => s + ms
|
|
|
102
151
|
* where that's how they bill (Vercel). Without `cpuMillis` they're charged as if every core was busy.
|
|
103
152
|
* `billedVsList` scales the price by what the provider was measured to really bill.
|
|
104
153
|
*/
|
|
105
|
-
export function taskUsd(provider, size, createMs, taskMillis, cpuMillis, billedVsList = 1) {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
154
|
+
export function taskUsd(provider, size, createMs, taskMillis, cpuMillis, billedVsList = 1, reused = false, maxCoreMillis) {
|
|
155
|
+
const rules = billingRules(provider);
|
|
156
|
+
// Reused: the job runs in a sandbox that's already up, so there's no start, minimum, step or per-sandbox
|
|
157
|
+
// fee to pay for it; only its own time.
|
|
158
|
+
const { minSeconds, incrementSeconds, perSandboxUsd } = reused ? { minSeconds: 0, incrementSeconds: 1e-9, perSandboxUsd: 0 } : rules;
|
|
159
|
+
const seconds = (reused ? 0 : createMs) / 1000 + taskMillis / 1000;
|
|
160
|
+
const billed = reused ? seconds : Math.max(minSeconds, Math.ceil(seconds / incrementSeconds - 1e-9) * incrementSeconds);
|
|
161
|
+
// Every core busy: the CPU part is then charged by what was used (cpuMillis), not by the hint.
|
|
162
|
+
const full = hourlyCost(provider, { ...size, cpuUtilization: 1 });
|
|
110
163
|
const cpuFull = cpuHourlyAtFull(provider, size);
|
|
111
164
|
if (cpuFull === 0 || cpuMillis === undefined)
|
|
112
165
|
return (billedVsList * full * billed) / 3600 + perSandboxUsd;
|
|
113
|
-
const { vcpuHour, cpuFloor = 0 } = info(provider).pricing;
|
|
166
|
+
const { vcpuHour, cpuFloor = 0, cpuMeteredPerVm } = info(provider).pricing;
|
|
114
167
|
const vcpus = cpuFull / vcpuHour;
|
|
115
|
-
|
|
168
|
+
// A per-VM meter counts every vCPU while the busiest core works.
|
|
169
|
+
const perVm = cpuMeteredPerVm && maxCoreMillis !== undefined ? (vcpus * maxCoreMillis) / 1000 : 0;
|
|
170
|
+
const cpuSeconds = Math.max(cpuMillis / 1000, cpuFloor * vcpus * seconds, perVm);
|
|
116
171
|
// Memory (and anything else that isn't CPU) is billed for the whole time, minimum included.
|
|
117
172
|
return (billedVsList * ((full - cpuFull) * billed + vcpuHour * cpuSeconds)) / 3600 + perSandboxUsd;
|
|
118
173
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -105,6 +105,11 @@ export interface ExecResult {
|
|
|
105
105
|
/** A live sandbox as one provider sees it. Adapters implement this. */
|
|
106
106
|
export interface ProviderSandbox {
|
|
107
107
|
readonly nativeId: string;
|
|
108
|
+
/**
|
|
109
|
+
* The provider SDK's own sandbox object (an E2B Sandbox, a Daytona Sandbox, a Modal Sandbox, ...), for features
|
|
110
|
+
* the router doesn't cover. Undefined for providers driven over plain HTTP: use `nativeId` with their API.
|
|
111
|
+
*/
|
|
112
|
+
readonly native?: unknown;
|
|
108
113
|
exec(cmd: string, opts?: ExecOptions): Promise<ExecResult>;
|
|
109
114
|
writeFile(path: string, content: string | Uint8Array): Promise<void>;
|
|
110
115
|
readFile(path: string): Promise<Uint8Array>;
|
package/dist/util.d.ts
CHANGED
|
@@ -49,5 +49,7 @@ export declare function errorStatus(err: unknown, depth?: number): number | unde
|
|
|
49
49
|
* sandbox, and the failed attempt stays on `attempts` (the CLI prints it), so it isn't hidden.
|
|
50
50
|
*/
|
|
51
51
|
export declare const SETUP_ERRORS: Set<number>;
|
|
52
|
+
/** A provider saying no for a limit or quota on the account (rate limits, concurrency caps, spent credit). */
|
|
53
|
+
export declare const LIMIT_ERROR: RegExp;
|
|
52
54
|
/** Resolve with `work`, or reject with `onExpire()` after `ms`. A late `work` rejection is swallowed. */
|
|
53
55
|
export declare function withDeadline<T>(work: Promise<T>, ms: number, onExpire: () => Error): Promise<T>;
|
package/dist/util.js
CHANGED
|
@@ -117,6 +117,8 @@ export function errorStatus(err, depth = 0) {
|
|
|
117
117
|
* sandbox, and the failed attempt stays on `attempts` (the CLI prints it), so it isn't hidden.
|
|
118
118
|
*/
|
|
119
119
|
export const SETUP_ERRORS = new Set([400, 401, 403, 404, 422]);
|
|
120
|
+
/** A provider saying no for a limit or quota on the account (rate limits, concurrency caps, spent credit). */
|
|
121
|
+
export const LIMIT_ERROR = /\b429\b|rate.?limit|too many|quota|concurren|capacity|throttl|creation limit|trial_exhausted|insufficient_credits|limit exceeded/i;
|
|
120
122
|
/** Resolve with `work`, or reject with `onExpire()` after `ms`. A late `work` rejection is swallowed. */
|
|
121
123
|
export async function withDeadline(work, ms, onExpire) {
|
|
122
124
|
let timer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandboxrouter/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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",
|