@sandboxrouter/sdk 0.17.0 → 0.19.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 +4 -3
- 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/catalog.js +19 -0
- package/dist/cli.js +2 -2
- package/dist/client.d.ts +106 -0
- package/dist/client.js +78 -0
- package/dist/image-bench.d.ts +103 -0
- package/dist/image-bench.js +110 -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/price-index.d.ts +51 -0
- package/dist/price-index.js +70 -0
- package/dist/providers/daytona.js +6 -1
- package/dist/providers/northflank.js +2 -1
- package/dist/providers/runcloud.d.ts +15 -0
- package/dist/providers/runcloud.js +238 -0
- package/dist/published.js +258 -25
- package/dist/recommend.d.ts +3 -1
- package/dist/recommend.js +3 -0
- package/dist/results.js +136 -1
- package/dist/router.js +2 -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 +1 -1
- package/package.json +4 -4
package/dist/results.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { steadySummary } from "./steady.js";
|
|
3
|
+
import { assistantSummary } from "./assistant.js";
|
|
2
4
|
import { join, relative } from "node:path";
|
|
3
5
|
import { benchmarksPublishable, CATALOG } from "./catalog.js";
|
|
4
6
|
import { CHECK_STEPS } from "./check.js";
|
|
@@ -53,6 +55,8 @@ const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}
|
|
|
53
55
|
const IPV4 = /\b(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}\b/;
|
|
54
56
|
/** "12 Main Street", "Calle Mayor 5", "Apt 4B": a street or a flat, which a label never needs. */
|
|
55
57
|
const ADDRESS = /\b\d+[A-Za-z]?\s+(?:[A-Za-zÀ-ÿ'.-]+\s+){0,3}(?:street|st|road|rd|avenue|ave|lane|ln|drive|dr|way|court|ct|place|pl|boulevard|blvd|terrace|close)\b\.?|\b(?:calle|carrer|rue|via|avenida|straße|strasse|str)\.?\s+[A-Za-zÀ-ÿ'.-]+(?:\s+[A-Za-zÀ-ÿ'.-]+){0,3}\s+\d+|\b(?:apt|apartment|flat|suite|unit|piso|puerta)\.?\s*#?\d+/i;
|
|
58
|
+
/** A registry image reference: optional host, path, then a tag or digest. No "user:password@". */
|
|
59
|
+
const IMAGE_REF = /^(?=.{1,200}$)[a-z0-9]+(?:[._-][a-z0-9]+)*(?::\d+)?(?:\/[a-z0-9]+(?:[._-][a-z0-9]+)*)*(?::[A-Za-z0-9_][A-Za-z0-9._-]{0,127}|@sha256:[a-f0-9]{64})$/;
|
|
56
60
|
const isNum = (n, min = 0, max = Infinity) => typeof n === "number" && Number.isFinite(n) && n >= min && n <= max;
|
|
57
61
|
const isCount = (n, max) => Number.isInteger(n) && isNum(n, 0, max);
|
|
58
62
|
const isSize = (size) => isNum(size?.vcpu, 0.1, 1024) && isNum(size?.memoryGb, 0.0625, 4096);
|
|
@@ -119,7 +123,7 @@ export function validateResult(j, now = Date.now()) {
|
|
|
119
123
|
out.push(`${r?.provider}: failures must be between 0 and runs`);
|
|
120
124
|
if (r?.limited !== undefined && !isNum(r.limited, 0, r?.failures ?? 0))
|
|
121
125
|
out.push(`${r?.provider}: limited must be between 0 and failures`);
|
|
122
|
-
for (const k of ["medianCreateMs", "medianExecMs", "medianReadyMs", "medianTaskReadyMs"]) {
|
|
126
|
+
for (const k of ["medianCreateMs", "medianExecMs", "medianReadyMs", "medianKillMs", "medianTaskReadyMs"]) {
|
|
123
127
|
if (r?.[k] !== undefined && !isNum(r[k], 1, MAX_MS))
|
|
124
128
|
out.push(`${r?.provider}: ${k} must be between 1 ms and 15 min`);
|
|
125
129
|
}
|
|
@@ -372,6 +376,137 @@ export function validateResult(j, now = Date.now()) {
|
|
|
372
376
|
out.push(`${e?.provider}: command output and deletion must be verified`);
|
|
373
377
|
}
|
|
374
378
|
}
|
|
379
|
+
else if (j.tool === "sandboxrouter-image") {
|
|
380
|
+
add(checkDate(j.date, now));
|
|
381
|
+
add(checkLabel(j.label));
|
|
382
|
+
add(checkBy(j.by));
|
|
383
|
+
// A public reference only: no credentials in it, and nothing that is not a registry path.
|
|
384
|
+
if (typeof j.image !== "string" || !IMAGE_REF.test(j.image))
|
|
385
|
+
out.push("image must be a public registry reference, e.g. python:3.11-bookworm");
|
|
386
|
+
if (typeof j.verify?.command !== "string" || !j.verify.command || typeof j.verify?.contains !== "string" || !j.verify.contains) {
|
|
387
|
+
out.push("verify needs the command run in every sandbox and the text its output must contain");
|
|
388
|
+
}
|
|
389
|
+
if (!isSize(j.spec))
|
|
390
|
+
out.push("spec must record the requested size");
|
|
391
|
+
if (!isNum(j.repeats, 3, 100) || !Number.isInteger(j.repeats))
|
|
392
|
+
out.push("repeats must be at least 3");
|
|
393
|
+
if (!Array.isArray(j.rows) || !j.rows.length)
|
|
394
|
+
out.push("rows is empty");
|
|
395
|
+
for (const r of Array.isArray(j.rows) ? j.rows : []) {
|
|
396
|
+
provider(r?.provider, "row provider");
|
|
397
|
+
if (noBench(r?.provider))
|
|
398
|
+
out.push(`${r.provider}: ${NO_BENCH}`);
|
|
399
|
+
if (!isSize(r?.size))
|
|
400
|
+
out.push(`${r?.provider}: invalid sandbox size`);
|
|
401
|
+
const repeat = Array.isArray(r?.repeatCreateMs) ? r.repeatCreateMs : undefined;
|
|
402
|
+
if (!repeat || repeat.length > j.repeats || repeat.some((ms) => !isNum(ms, 1, MAX_MS))) {
|
|
403
|
+
out.push(`${r?.provider}: repeatCreateMs must list at most ${j.repeats} times, each between 1 ms and 15 min`);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (r.firstCreateMs !== undefined && !isNum(r.firstCreateMs, 1, MAX_MS))
|
|
407
|
+
out.push(`${r.provider}: firstCreateMs must be between 1 ms and 15 min`);
|
|
408
|
+
if (r.firstCreateMs === undefined && repeat.length)
|
|
409
|
+
out.push(`${r.provider}: repeat starts without a first start`);
|
|
410
|
+
const starts = (r.firstCreateMs === undefined ? 0 : 1) + repeat.length;
|
|
411
|
+
if (!isCount(r.verified, 1 + j.repeats) || !isCount(r.failures, 1 + j.repeats) || r.verified !== starts || r.verified + r.failures > 1 + j.repeats) {
|
|
412
|
+
out.push(`${r.provider}: verified must count the timed starts, and verified plus failures cannot exceed the starts made`);
|
|
413
|
+
}
|
|
414
|
+
const sorted = [...repeat].sort((a, b) => a - b);
|
|
415
|
+
const mid = Math.floor(sorted.length / 2);
|
|
416
|
+
const expected = !sorted.length ? undefined : sorted.length % 2 ? sorted[mid] : Math.round((sorted[mid - 1] + sorted[mid]) / 2);
|
|
417
|
+
if (r.medianRepeatCreateMs !== expected)
|
|
418
|
+
out.push(`${r.provider}: medianRepeatCreateMs must be the median of repeatCreateMs`);
|
|
419
|
+
if (r.hourlyUsd !== undefined && !isNum(r.hourlyUsd, 0, 1000))
|
|
420
|
+
out.push(`${r.provider}: hourlyUsd is out of range`);
|
|
421
|
+
if ("error" in r || "lastError" in r)
|
|
422
|
+
out.push(`${r.provider}: errors must not be shared (they can hold account details)`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
else if (j.tool === "sandboxrouter-steady") {
|
|
426
|
+
add(checkDate(j.date, now));
|
|
427
|
+
add(checkLabel(j.label));
|
|
428
|
+
add(checkBy(j.by));
|
|
429
|
+
if (typeof j.task !== "string" || !j.task)
|
|
430
|
+
out.push("task must be the sample version, e.g. \"steady-v1\"");
|
|
431
|
+
if (!isSize(j.spec))
|
|
432
|
+
out.push("spec must record the requested size");
|
|
433
|
+
if (!Number.isInteger(j.samples) || !isNum(j.samples, 30, 1000))
|
|
434
|
+
out.push("samples must be at least 30");
|
|
435
|
+
if (!isNum(j.intervalSeconds, 5, 600))
|
|
436
|
+
out.push("intervalSeconds must be between 5 s and 10 min");
|
|
437
|
+
if (!Array.isArray(j.rows) || !j.rows.length)
|
|
438
|
+
out.push("rows is empty");
|
|
439
|
+
for (const r of Array.isArray(j.rows) ? j.rows : []) {
|
|
440
|
+
provider(r?.provider, "row provider");
|
|
441
|
+
if (noBench(r?.provider))
|
|
442
|
+
out.push(`${r.provider}: ${NO_BENCH}`);
|
|
443
|
+
if (!isSize(r?.size))
|
|
444
|
+
out.push(`${r?.provider}: invalid sandbox size`);
|
|
445
|
+
const ms = Array.isArray(r?.sampleMs) ? r.sampleMs : undefined;
|
|
446
|
+
if (!ms || ms.some((v) => !isNum(v, 1, MAX_MS))) {
|
|
447
|
+
out.push(`${r?.provider}: sampleMs must list each sample's time, between 1 ms and 15 min`);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (!isCount(r.failures, j.samples) || ms.length + r.failures !== j.samples)
|
|
451
|
+
out.push(`${r.provider}: samples timed plus failures must equal the samples asked for`);
|
|
452
|
+
const want = steadySummary(ms);
|
|
453
|
+
for (const k of ["medianMs", "p95Ms", "maxMs"]) {
|
|
454
|
+
if (r[k] !== want[k])
|
|
455
|
+
out.push(`${r.provider}: ${k} does not match sampleMs`);
|
|
456
|
+
}
|
|
457
|
+
if (r.hourlyUsd !== undefined && !isNum(r.hourlyUsd, 0, 1000))
|
|
458
|
+
out.push(`${r.provider}: hourlyUsd is out of range`);
|
|
459
|
+
if ("error" in r || "lastError" in r)
|
|
460
|
+
out.push(`${r.provider}: errors must not be shared (they can hold account details)`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
else if (j.tool === "sandboxrouter-assistant") {
|
|
464
|
+
add(checkDate(j.date, now));
|
|
465
|
+
add(checkLabel(j.label));
|
|
466
|
+
add(checkBy(j.by));
|
|
467
|
+
if (typeof j.task !== "string" || !j.task)
|
|
468
|
+
out.push("task must be the session version, e.g. \"assistant-v1\"");
|
|
469
|
+
if (!isSize(j.spec))
|
|
470
|
+
out.push("spec must record the requested size");
|
|
471
|
+
if (!Number.isInteger(j.runs) || !isNum(j.runs, 3, 100))
|
|
472
|
+
out.push("runs must be at least 3 sessions");
|
|
473
|
+
if (!Number.isInteger(j.calls) || !isNum(j.calls, 10, 1000))
|
|
474
|
+
out.push("calls must be at least 10");
|
|
475
|
+
if (!isNum(j.idleSeconds, 30, 3600))
|
|
476
|
+
out.push("idleSeconds must be between 30 s and an hour");
|
|
477
|
+
if (!isNum(j.uploadBytes, 1, 1e10) || !isNum(j.downloadBytes, 1, 1e10))
|
|
478
|
+
out.push("uploadBytes and downloadBytes must record the file sizes");
|
|
479
|
+
if (!Array.isArray(j.rows) || !j.rows.length)
|
|
480
|
+
out.push("rows is empty");
|
|
481
|
+
for (const r of Array.isArray(j.rows) ? j.rows : []) {
|
|
482
|
+
provider(r?.provider, "row provider");
|
|
483
|
+
if (noBench(r?.provider))
|
|
484
|
+
out.push(`${r.provider}: ${NO_BENCH}`);
|
|
485
|
+
if (!isSize(r?.size))
|
|
486
|
+
out.push(`${r?.provider}: invalid sandbox size`);
|
|
487
|
+
const sessions = Array.isArray(r?.sessions) ? r.sessions : undefined;
|
|
488
|
+
const times = ["createMs", "firstMs", "uploadMs", "analyseMs", "downloadMs", "idleMs", "sessionMs"];
|
|
489
|
+
const whole = (s) => times.every((k) => isNum(s?.[k], 1, MAX_MS)) && Array.isArray(s.callMs) && s.callMs.length === j.calls && s.callMs.every((v) => isNum(v, 1, MAX_MS)) &&
|
|
490
|
+
(s.cpuMs === undefined || isNum(s.cpuMs, 0, MAX_MS * 1024)) && (s.maxCoreMs === undefined || isNum(s.maxCoreMs, 0, MAX_MS));
|
|
491
|
+
if (!sessions || !sessions.every(whole)) {
|
|
492
|
+
out.push(`${r?.provider}: every session must list its times (1 ms to 15 min) and one time per call`);
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
if (!isCount(r.failures, j.runs) || sessions.length + r.failures !== j.runs)
|
|
496
|
+
out.push(`${r.provider}: sessions plus failures must equal the sessions asked for`);
|
|
497
|
+
const want = assistantSummary(sessions);
|
|
498
|
+
for (const k of ["firstAnswerMs", "uploadMs", "analyseMs", "downloadMs", "callMs", "callP95Ms", "idleMs"]) {
|
|
499
|
+
if (r[k] !== want[k])
|
|
500
|
+
out.push(`${r.provider}: ${k} does not match the sessions`);
|
|
501
|
+
}
|
|
502
|
+
if (r.sessionUsd !== undefined && !isNum(r.sessionUsd, 0, 1000))
|
|
503
|
+
out.push(`${r.provider}: sessionUsd is out of range`);
|
|
504
|
+
if (r.hourlyUsd !== undefined && !isNum(r.hourlyUsd, 0, 1000))
|
|
505
|
+
out.push(`${r.provider}: hourlyUsd is out of range`);
|
|
506
|
+
if ("error" in r || "lastError" in r)
|
|
507
|
+
out.push(`${r.provider}: errors must not be shared (they can hold account details)`);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
375
510
|
else {
|
|
376
511
|
out.push(`unknown tool "${String(j.tool)}": expected a benchmark report, saved check, cost run or hosted ledger check`);
|
|
377
512
|
}
|
package/dist/router.js
CHANGED
|
@@ -37,6 +37,7 @@ import { DenoProvider } from "./providers/deno.js";
|
|
|
37
37
|
import { FreestyleProvider } from "./providers/freestyle.js";
|
|
38
38
|
import { KoyebProvider } from "./providers/koyeb.js";
|
|
39
39
|
import { DedalusProvider } from "./providers/dedalus.js";
|
|
40
|
+
import { RunCloudProvider } from "./providers/runcloud.js";
|
|
40
41
|
import { Agent37Provider } from "./providers/agent37.js";
|
|
41
42
|
import { OpenScaleProvider } from "./providers/openscale.js";
|
|
42
43
|
import { SuperserveProvider } from "./providers/superserve.js";
|
|
@@ -98,6 +99,7 @@ export function defaultProviders() {
|
|
|
98
99
|
new NovitaProvider(),
|
|
99
100
|
new LangSmithProvider(),
|
|
100
101
|
new OpenScaleProvider(),
|
|
102
|
+
new RunCloudProvider(),
|
|
101
103
|
new SuperserveProvider(),
|
|
102
104
|
new SailProvider(),
|
|
103
105
|
new UpstashProvider(),
|
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ProviderId = "maritime" | "e2b" | "daytona" | "modal" | "vercel" | "morph" | "sprites" | "blaxel" | "tensorlake" | "runloop" | "hopx" | "cloudflare" | "northflank" | "boat" | "exedev" | "docker" | "novita" | "langsmith" | "alibaba" | "upstash" | "koyeb" | "freestyle" | "deno" | "beam" | "codesandbox" | "azure" | "agentcore" | "lambda" | "dedalus" | "agent37" | "superserve" | "instabox" | "openscale" | "sail" | "digitalocean" | "google";
|
|
1
|
+
export type ProviderId = "maritime" | "e2b" | "daytona" | "modal" | "vercel" | "morph" | "sprites" | "blaxel" | "tensorlake" | "runloop" | "hopx" | "cloudflare" | "northflank" | "boat" | "exedev" | "docker" | "novita" | "langsmith" | "alibaba" | "upstash" | "koyeb" | "freestyle" | "deno" | "beam" | "codesandbox" | "azure" | "agentcore" | "lambda" | "dedalus" | "agent37" | "superserve" | "instabox" | "openscale" | "sail" | "digitalocean" | "google" | "runcloud";
|
|
2
2
|
/** Things a caller can require of a provider. The router skips providers that lack one. */
|
|
3
3
|
export type Capability = "gpu" | "pause" | "ports" | "background" | "custom-image";
|
|
4
4
|
/** What the caller wants. Every field is optional; providers map it to their own knobs. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandboxrouter/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.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,13 +180,13 @@
|
|
|
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.232.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.74.0",
|
|
188
188
|
"@mobilerun/sdk": "^6.1.0",
|
|
189
|
-
"@northflank/js-client": "^0.
|
|
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",
|