@sandboxrouter/sdk 0.8.1 → 0.8.3
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 +1 -1
- package/dist/bench.d.ts +3 -1
- package/dist/bench.js +13 -5
- package/dist/cli.js +9 -4
- package/dist/leaderboard.d.ts +6 -1
- package/dist/leaderboard.js +20 -6
- package/dist/router.d.ts +21 -3
- package/dist/router.js +23 -7
- package/dist/types.d.ts +10 -1
- package/dist/types.js +2 -1
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +2 -2
- package/dist/verified.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ List price while running, 2 vCPU / 4 GB, cheapest first; waitlisted sign-ups fol
|
|
|
43
43
|
| Provider | $/hr | Plan needed | Real-account check | Source |
|
|
44
44
|
|---|---|---|---|---|
|
|
45
45
|
| [Agent37](https://sandboxrouter.ai/providers/agent37) | $0.007 | none | passed (2026-11-13) | [pricing](https://www.agent37.com/docs/agents-api/billing) |
|
|
46
|
-
| [Boat](https://sandboxrouter.ai/providers/boat) | $0.018 | $20/mo (credited) |
|
|
46
|
+
| [Boat](https://sandboxrouter.ai/providers/boat) | $0.018 | $20/mo (credited) | passed (2026-11-14) | [pricing](https://docs.boat.dev/pricing.md) |
|
|
47
47
|
| [Maritime](https://sandboxrouter.ai/providers/maritime) | $0.022 | $20/mo (credited) | passed (2026-11-13) | [pricing](https://maritime.sh/pricing) |
|
|
48
48
|
| [Sailboxes (Sail Research)](https://sandboxrouter.ai/providers/sail) | up to $0.062 | none | passed (2026-11-14) | [pricing](https://docs.sailresearch.com/sailboxes-pricing.md) |
|
|
49
49
|
| [Northflank](https://sandboxrouter.ai/providers/northflank) | $0.067 | none | not run yet | [pricing](https://northflank.com/pricing) |
|
package/dist/bench.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ export interface BenchRow {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Cold start = time from create() call to a usable sandbox. Exec = round trip of `echo ok`.
|
|
14
|
-
* Measured from wherever you run it, so network distance to each provider counts.
|
|
14
|
+
* Measured from wherever you run it, so network distance to each provider counts. Every provider is
|
|
15
|
+
* asked for the same size (2 vCPU / 4 GB unless `spec` says otherwise), except ones whose default
|
|
16
|
+
* image fixes the size, which run at that size.
|
|
15
17
|
*/
|
|
16
18
|
export declare function bench(opts: {
|
|
17
19
|
router?: Router;
|
package/dist/bench.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { CATALOG, fixedSize, hourlyCost } from "./catalog.js";
|
|
1
|
+
import { CATALOG, DEFAULT_MEMORY_GB, DEFAULT_VCPU, fixedSize, hourlyCost } from "./catalog.js";
|
|
2
2
|
import { loadBench, median, saveBench } from "./bench-store.js";
|
|
3
3
|
import { Router } from "./router.js";
|
|
4
4
|
/**
|
|
5
5
|
* Cold start = time from create() call to a usable sandbox. Exec = round trip of `echo ok`.
|
|
6
|
-
* Measured from wherever you run it, so network distance to each provider counts.
|
|
6
|
+
* Measured from wherever you run it, so network distance to each provider counts. Every provider is
|
|
7
|
+
* asked for the same size (2 vCPU / 4 GB unless `spec` says otherwise), except ones whose default
|
|
8
|
+
* image fixes the size, which run at that size.
|
|
7
9
|
*/
|
|
8
10
|
export async function bench(opts) {
|
|
9
11
|
const router = opts.router ?? new Router();
|
|
10
12
|
const runs = opts.runs ?? 3;
|
|
11
|
-
|
|
13
|
+
// The CLI passes unset flags as undefined: drop them so they don't wipe the defaults.
|
|
14
|
+
const given = Object.fromEntries(Object.entries(opts.spec ?? {}).filter(([, v]) => v !== undefined));
|
|
15
|
+
const spec = { vcpu: DEFAULT_VCPU, memoryGb: DEFAULT_MEMORY_GB, timeoutMinutes: 5, ...given };
|
|
12
16
|
const ids = opts.providers ?? router.registered().filter((id) => router.isConfigured(id));
|
|
13
17
|
const log = opts.onProgress ?? (() => { });
|
|
14
18
|
const stored = loadBench(opts.benchFile);
|
|
@@ -23,7 +27,7 @@ export async function bench(opts) {
|
|
|
23
27
|
let box;
|
|
24
28
|
try {
|
|
25
29
|
const t0 = performance.now();
|
|
26
|
-
box = await router.create(
|
|
30
|
+
box = await router.create(sized(id, spec), { provider: id, fallback: false });
|
|
27
31
|
createMs.push(Math.round(performance.now() - t0));
|
|
28
32
|
const t1 = performance.now();
|
|
29
33
|
const r = await box.exec("echo ok");
|
|
@@ -46,13 +50,17 @@ export async function bench(opts) {
|
|
|
46
50
|
failures,
|
|
47
51
|
medianCreateMs: median(createMs),
|
|
48
52
|
medianExecMs: median(execMs),
|
|
49
|
-
hourlyUsd: hourlyCost(id,
|
|
53
|
+
hourlyUsd: hourlyCost(id, sized(id, spec)),
|
|
50
54
|
lastError,
|
|
51
55
|
});
|
|
52
56
|
}
|
|
53
57
|
saveBench(stored, opts.benchFile);
|
|
54
58
|
return rows.sort((a, b) => (a.medianCreateMs ?? Infinity) - (b.medianCreateMs ?? Infinity));
|
|
55
59
|
}
|
|
60
|
+
/** The spec a provider is benched at: the asked size, or its fixed default size if its image has one. */
|
|
61
|
+
function sized(id, spec) {
|
|
62
|
+
return { ...spec, ...fixedSize(id, spec) };
|
|
63
|
+
}
|
|
56
64
|
export function benchMarkdown(rows) {
|
|
57
65
|
const name = (id) => CATALOG.find((c) => c.id === id).name;
|
|
58
66
|
const ms = (n) => (n === undefined ? "n/a" : `${n} ms`);
|
package/dist/cli.js
CHANGED
|
@@ -9,7 +9,7 @@ import { gc, listOpen } from "./gc.js";
|
|
|
9
9
|
import { contributor, publishableCheck } from "./results.js";
|
|
10
10
|
import { loadReports, makeReport, renderLeaderboard } from "./leaderboard.js";
|
|
11
11
|
import { DEFAULT_MEMORY_GB, DEFAULT_VCPU, accessLabel, benchmarksPublishable, hourlyCost, listingOrder, planLabel, unfit } from "./catalog.js";
|
|
12
|
-
import { Router } from "./router.js";
|
|
12
|
+
import { Router, rankUsd, runHours } from "./router.js";
|
|
13
13
|
import { createApp } from "./server.js";
|
|
14
14
|
import { RouterError } from "./types.js";
|
|
15
15
|
const HELP = `sandboxrouter: one API for every sandbox provider
|
|
@@ -40,7 +40,7 @@ Usage:
|
|
|
40
40
|
sandboxrouter screenshot <provider:id> [--out screen.png]
|
|
41
41
|
sandboxrouter serve [--port 8787] [--host 127.0.0.1] [--cors https://site.example,http://localhost:3000]
|
|
42
42
|
|
|
43
|
-
Spec flags: --vcpu N --memory GB --gpu T4 --timeout MIN
|
|
43
|
+
Spec flags: --vcpu N --memory GB --gpu T4 --timeout MIN --expect SEC (how long you'll use it; ranks by the real bill)
|
|
44
44
|
Route flags: --provider e2b[,modal,...] --strategy balanced|verified|cheapest|fastest (default balanced: cheapest real cost, speed breaks near-ties)
|
|
45
45
|
--no-fallback --fallback-any (also on setup errors like a bad key)
|
|
46
46
|
--create-timeout SEC (per provider, default 120) --require gpu,custom-image
|
|
@@ -54,6 +54,7 @@ const { values, positionals } = parseArgs({
|
|
|
54
54
|
memory: { type: "string" },
|
|
55
55
|
gpu: { type: "string" },
|
|
56
56
|
timeout: { type: "string" },
|
|
57
|
+
expect: { type: "string" },
|
|
57
58
|
provider: { type: "string" },
|
|
58
59
|
strategy: { type: "string" },
|
|
59
60
|
"no-fallback": { type: "boolean" },
|
|
@@ -96,6 +97,7 @@ const spec = {
|
|
|
96
97
|
memoryGb: num(values.memory),
|
|
97
98
|
gpu: values.gpu,
|
|
98
99
|
timeoutMinutes: num(values.timeout),
|
|
100
|
+
expectedSeconds: num(values.expect),
|
|
99
101
|
};
|
|
100
102
|
const providers = list(values.provider);
|
|
101
103
|
const by = (() => {
|
|
@@ -165,7 +167,10 @@ async function main() {
|
|
|
165
167
|
const size = `${c.size.vcpu} vCPU / ${c.size.memoryGb} GB`;
|
|
166
168
|
const speed = c.medianCreateMs !== undefined ? `${c.medianCreateMs} ms` : "";
|
|
167
169
|
const fee = c.perSandboxUsd ? ` + $${c.perSandboxUsd}/sandbox` : "";
|
|
168
|
-
|
|
170
|
+
// With --expect, what that run would be billed (minimum charge and fee included): what it's ranked by.
|
|
171
|
+
const hours = runHours(spec);
|
|
172
|
+
const run = spec.expectedSeconds ? ` ≈ $${(rankUsd(c, hours) * hours).toFixed(6)} for ${Math.round(hours * 3600)} s` : "";
|
|
173
|
+
const cols = [`$${c.estimatedHourlyUsd.toFixed(4)}/hr${list}${fee}${run}`, size, speed, tested].filter(Boolean).join(" ");
|
|
169
174
|
console.log(`${mark} ${c.provider.padEnd(11)} ${cols}${c.skip ? ` (skipped: ${c.skip})` : ""}`);
|
|
170
175
|
}
|
|
171
176
|
return;
|
|
@@ -304,7 +309,7 @@ async function main() {
|
|
|
304
309
|
console.error(`\n${r.provider} last error: ${r.lastError}`);
|
|
305
310
|
if (values.share) {
|
|
306
311
|
const version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
307
|
-
const report = makeReport(rows, { version, runs: rows[0].runs, spec, label: values.label, by });
|
|
312
|
+
const report = makeReport(rows, { version, runs: rows[0].runs, spec: { ...spec, vcpu: spec.vcpu ?? DEFAULT_VCPU, memoryGb: spec.memoryGb ?? DEFAULT_MEMORY_GB }, label: values.label, by });
|
|
308
313
|
const left = rows.filter((r) => !benchmarksPublishable(r.provider)).map((r) => r.provider);
|
|
309
314
|
if (left.length)
|
|
310
315
|
console.log(`\nleft out of the shared report: ${left.join(", ")} (their terms don't allow publishing benchmarks)`);
|
package/dist/leaderboard.d.ts
CHANGED
|
@@ -41,8 +41,13 @@ export interface LeaderRow {
|
|
|
41
41
|
vcpu: number;
|
|
42
42
|
memoryGb: number;
|
|
43
43
|
};
|
|
44
|
+
/** Date (ISO) of the newest run behind this row. */
|
|
45
|
+
measuredAt: string;
|
|
44
46
|
}
|
|
45
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Each provider's latest run from each location (report label), then the median across locations, so
|
|
49
|
+
* an old run can't outvote a newer one and one heavy submitter can't skew a provider.
|
|
50
|
+
*/
|
|
46
51
|
export declare function aggregate(reports: BenchReport[]): LeaderRow[];
|
|
47
52
|
/** One self-contained HTML page: a sorted table with an inline bar per measure, each on its own scale. */
|
|
48
53
|
export declare function renderLeaderboard(reports: BenchReport[]): string;
|
package/dist/leaderboard.js
CHANGED
|
@@ -40,14 +40,27 @@ export function loadReports(dir) {
|
|
|
40
40
|
return out;
|
|
41
41
|
}
|
|
42
42
|
const KNOWN = new Set(CATALOG.map((c) => c.id));
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
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.
|
|
46
|
+
*/
|
|
44
47
|
export function aggregate(reports) {
|
|
48
|
+
const latest = new Map();
|
|
49
|
+
for (const rep of reports) {
|
|
50
|
+
for (const r of rep.rows) {
|
|
51
|
+
if (!KNOWN.has(r.provider))
|
|
52
|
+
continue;
|
|
53
|
+
const key = `${r.provider}\u0000${rep.label ?? ""}`;
|
|
54
|
+
const seen = latest.get(key);
|
|
55
|
+
if (!seen || rep.date > seen.date)
|
|
56
|
+
latest.set(key, { row: r, date: rep.date });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
45
59
|
const by = new Map();
|
|
46
|
-
for (const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const rows = [...by.entries()].map(([id, rs]) => {
|
|
60
|
+
for (const x of latest.values())
|
|
61
|
+
by.set(x.row.provider, [...(by.get(x.row.provider) ?? []), x]);
|
|
62
|
+
const rows = [...by.entries()].map(([id, xs]) => {
|
|
63
|
+
const rs = xs.map((x) => x.row);
|
|
51
64
|
const runs = rs.reduce((n, r) => n + r.runs, 0);
|
|
52
65
|
const ok = rs.reduce((n, r) => n + (r.runs - r.failures), 0);
|
|
53
66
|
return {
|
|
@@ -59,6 +72,7 @@ export function aggregate(reports) {
|
|
|
59
72
|
successRate: runs ? ok / runs : 0,
|
|
60
73
|
hourlyUsd: hourlyCost(id, fittingSpec(id)),
|
|
61
74
|
size: fittingSpec(id),
|
|
75
|
+
measuredAt: xs.map((x) => x.date).sort().at(-1),
|
|
62
76
|
};
|
|
63
77
|
});
|
|
64
78
|
return rows.sort((a, b) => (a.medianCreateMs ?? Infinity) - (b.medianCreateMs ?? Infinity));
|
package/dist/router.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface Candidate {
|
|
|
31
31
|
failing: boolean;
|
|
32
32
|
/**
|
|
33
33
|
* A fixed charge per sandbox, USD, on top of `estimatedHourlyUsd` (Sail's free plan: $0.01). Ranking
|
|
34
|
-
* spreads it over the
|
|
34
|
+
* spreads it over the run (`expectedSeconds`, else `timeoutMinutes`, default 30), so it weighs more on short ones.
|
|
35
35
|
*/
|
|
36
36
|
perSandboxUsd?: number;
|
|
37
37
|
/** Why this provider won't be tried, if it won't. */
|
|
@@ -80,6 +80,15 @@ export interface RouterOptions {
|
|
|
80
80
|
factor?: number;
|
|
81
81
|
minSeconds?: number;
|
|
82
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* What a provider's 401 or 403 (or a missing provider package) does to a create. "stop" (default):
|
|
85
|
+
* the create fails, because with your own keys that is a key or setup you need to fix, and moving the
|
|
86
|
+
* work elsewhere would hide it. "fallback": try the next provider. For services that run sandboxes on
|
|
87
|
+
* their own accounts, where a revoked key, a frozen workspace or a provider's creation cap is the
|
|
88
|
+
* service's problem, not the caller's. 400, 404 and 422 still stop: those are usually the request.
|
|
89
|
+
* Either way the failed try is in `attempts`.
|
|
90
|
+
*/
|
|
91
|
+
accountErrors?: "stop" | "fallback";
|
|
83
92
|
}
|
|
84
93
|
/** Desktop-only providers. Filled in as adapters are added. */
|
|
85
94
|
export declare function defaultComputerProviders(): ComputerProvider[];
|
|
@@ -95,6 +104,7 @@ export declare class Router {
|
|
|
95
104
|
private readonly live;
|
|
96
105
|
private computerOnly;
|
|
97
106
|
private readonly quick;
|
|
107
|
+
private readonly accountErrors;
|
|
98
108
|
/** The local record of sandboxes this router created, or undefined when turned off. */
|
|
99
109
|
readonly ledger?: Ledger;
|
|
100
110
|
constructor(opts?: RouterOptions);
|
|
@@ -184,10 +194,18 @@ export declare function parseId(id: string): {
|
|
|
184
194
|
* The default order. Providers whose last real-account check failed go last. The rest go cheapest
|
|
185
195
|
* first by effective price (list price x what the provider really billed, where measured), except that
|
|
186
196
|
* providers within PRICE_TIE of the cheapest remaining one count as a tie and go fastest first (by
|
|
187
|
-
* median create time; unknown speed after known), then cheapest, then alphabetical.
|
|
188
|
-
*
|
|
197
|
+
* median create time; unknown speed after known), then cheapest, then alphabetical. Price is what a run
|
|
198
|
+
* of `lifetimeHours` would be billed (`rankUsd`), as USD per hour.
|
|
189
199
|
*/
|
|
190
200
|
export declare function balanced(list: Candidate[], lifetimeHours?: number): Candidate[];
|
|
201
|
+
/** Hours ranking assumes a sandbox runs: `expectedSeconds` (no longer than the lifetime), else `timeoutMinutes` (default 30). */
|
|
202
|
+
export declare function runHours(spec: SandboxSpec): number;
|
|
203
|
+
/**
|
|
204
|
+
* USD per hour a candidate is ranked by: what a run of `hours` would be billed, divided by `hours`. The
|
|
205
|
+
* run is rounded up to the provider's minimum and billing increment (`billingRules`), and its
|
|
206
|
+
* per-sandbox charge is added, so short runs favor providers that bill by the second without a fee.
|
|
207
|
+
*/
|
|
208
|
+
export declare function rankUsd(c: Candidate, hours: number): number;
|
|
191
209
|
/** Seconds to wait for one provider's create before trying the next (RouteOptions.createTimeoutSeconds). */
|
|
192
210
|
export declare const DEFAULT_CREATE_TIMEOUT_S = 120;
|
|
193
211
|
/** Seconds a whole create may take over every provider it tries (RouteOptions.deadlineSeconds). */
|
package/dist/router.js
CHANGED
|
@@ -104,6 +104,7 @@ export class Router {
|
|
|
104
104
|
live = new Map();
|
|
105
105
|
computerOnly;
|
|
106
106
|
quick;
|
|
107
|
+
accountErrors;
|
|
107
108
|
/** The local record of sandboxes this router created, or undefined when turned off. */
|
|
108
109
|
ledger;
|
|
109
110
|
constructor(opts = {}) {
|
|
@@ -119,6 +120,7 @@ export class Router {
|
|
|
119
120
|
opts.billedVsList ?? Object.fromEntries(Object.entries(BILLED_VS_LIST).map(([id, b]) => [id, b.ratio]));
|
|
120
121
|
this.computerOnly = opts.computers ?? (opts.providers ? [] : defaultComputerProviders());
|
|
121
122
|
this.quick = opts.quickFallback === false ? false : { factor: 5, minSeconds: 10, ...opts.quickFallback };
|
|
123
|
+
this.accountErrors = opts.accountErrors ?? "stop";
|
|
122
124
|
}
|
|
123
125
|
/** Registered and has credentials. False for providers this router doesn't know. */
|
|
124
126
|
isConfigured(id) {
|
|
@@ -181,7 +183,7 @@ export class Router {
|
|
|
181
183
|
// depends on who the provider is, only on its price, what it really billed, how fast it started for
|
|
182
184
|
// this router and whether its last real-account check failed. An explicit list keeps the caller's order.
|
|
183
185
|
if (!explicit) {
|
|
184
|
-
const hours = (spec
|
|
186
|
+
const hours = runHours(spec);
|
|
185
187
|
const byCost = (a, b) => rankUsd(a, hours) - rankUsd(b, hours) || a.provider.localeCompare(b.provider);
|
|
186
188
|
const byList = (a, b) => a.listHourlyUsd - b.listHourlyUsd || a.provider.localeCompare(b.provider);
|
|
187
189
|
if (strategy === "fastest") {
|
|
@@ -271,7 +273,9 @@ export class Router {
|
|
|
271
273
|
const status = errorStatus(err);
|
|
272
274
|
attempts.push({ provider: c.provider, ok: false, ms: Date.now() - t0, error: err.message, ...(status ? { status } : {}) });
|
|
273
275
|
const setup = err instanceof SetupError || (status !== undefined && SETUP_ERRORS.has(status));
|
|
274
|
-
|
|
276
|
+
// On the router's own accounts, a key, permission or install problem is ours: move on.
|
|
277
|
+
const account = err instanceof SetupError || status === 401 || status === 403;
|
|
278
|
+
if (route.fallback !== "any" && setup && !(this.accountErrors === "fallback" && account)) {
|
|
275
279
|
const msg = err.message.replace(/[.\s]+$/, "");
|
|
276
280
|
throw new RouterError(`${msg.startsWith(c.provider) ? msg : `${c.provider}: ${msg}`}. This looks like a setup problem with ${c.provider} (key, image, request or a missing package), ` +
|
|
277
281
|
`so the router stopped instead of moving the work to another provider; pass fallback: "any" to fall back on every error`, attempts, "setup");
|
|
@@ -439,8 +443,8 @@ function round(n) {
|
|
|
439
443
|
* The default order. Providers whose last real-account check failed go last. The rest go cheapest
|
|
440
444
|
* first by effective price (list price x what the provider really billed, where measured), except that
|
|
441
445
|
* providers within PRICE_TIE of the cheapest remaining one count as a tie and go fastest first (by
|
|
442
|
-
* median create time; unknown speed after known), then cheapest, then alphabetical.
|
|
443
|
-
*
|
|
446
|
+
* median create time; unknown speed after known), then cheapest, then alphabetical. Price is what a run
|
|
447
|
+
* of `lifetimeHours` would be billed (`rankUsd`), as USD per hour.
|
|
444
448
|
*/
|
|
445
449
|
export function balanced(list, lifetimeHours = 0.5) {
|
|
446
450
|
const cost = (c) => rankUsd(c, lifetimeHours);
|
|
@@ -460,9 +464,21 @@ export function balanced(list, lifetimeHours = 0.5) {
|
|
|
460
464
|
};
|
|
461
465
|
return [...order(list.filter((c) => !c.failing)), ...order(list.filter((c) => c.failing))];
|
|
462
466
|
}
|
|
463
|
-
/**
|
|
464
|
-
function
|
|
465
|
-
|
|
467
|
+
/** Hours ranking assumes a sandbox runs: `expectedSeconds` (no longer than the lifetime), else `timeoutMinutes` (default 30). */
|
|
468
|
+
export function runHours(spec) {
|
|
469
|
+
const lifetime = (spec.timeoutMinutes ?? 30) * 60;
|
|
470
|
+
return Math.min(spec.expectedSeconds ?? lifetime, lifetime) / 3600;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* USD per hour a candidate is ranked by: what a run of `hours` would be billed, divided by `hours`. The
|
|
474
|
+
* run is rounded up to the provider's minimum and billing increment (`billingRules`), and its
|
|
475
|
+
* per-sandbox charge is added, so short runs favor providers that bill by the second without a fee.
|
|
476
|
+
*/
|
|
477
|
+
export function rankUsd(c, hours) {
|
|
478
|
+
const { minSeconds, incrementSeconds } = billingRules(c.provider);
|
|
479
|
+
const seconds = hours * 3600;
|
|
480
|
+
const billed = Math.max(minSeconds, Math.ceil(seconds / incrementSeconds - 1e-9) * incrementSeconds);
|
|
481
|
+
return (c.estimatedHourlyUsd * billed) / Math.max(seconds, 1) + (c.perSandboxUsd ?? 0) / Math.max(hours, 1 / 3600);
|
|
466
482
|
}
|
|
467
483
|
/** Seconds to wait for one provider's create before trying the next (RouteOptions.createTimeoutSeconds). */
|
|
468
484
|
export const DEFAULT_CREATE_TIMEOUT_S = 120;
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,14 @@ export interface SandboxSpec {
|
|
|
18
18
|
env?: Record<string, string>;
|
|
19
19
|
/** Hard lifetime in minutes (default 30). */
|
|
20
20
|
timeoutMinutes?: number;
|
|
21
|
+
/**
|
|
22
|
+
* How long you expect to use the sandbox, in seconds. Only a ranking hint: the sandbox still lives
|
|
23
|
+
* until you kill it or `timeoutMinutes` runs out. Without it, ranking assumes the whole lifetime.
|
|
24
|
+
* With it, providers are ranked by what that run would really be billed, minimum charge, billing
|
|
25
|
+
* increment and per-sandbox fee included, so a provider that bills per second can beat one that is
|
|
26
|
+
* cheaper per hour but charges a full minute.
|
|
27
|
+
*/
|
|
28
|
+
expectedSeconds?: number;
|
|
21
29
|
/**
|
|
22
30
|
* Provider-specific image/template, keyed by provider, e.g.
|
|
23
31
|
* { maritime: "python", e2b: "code-interpreter-v1", modal: "python:3.13-slim" }.
|
|
@@ -128,7 +136,8 @@ export declare class ProviderError extends Error {
|
|
|
128
136
|
}
|
|
129
137
|
/**
|
|
130
138
|
* A problem with local setup, such as a provider SDK that isn't installed or a missing setting:
|
|
131
|
-
* something to fix here, not a provider being down. The router stops on it instead of falling back
|
|
139
|
+
* something to fix here, not a provider being down. The router stops on it instead of falling back, unless it
|
|
140
|
+
* was made with `accountErrors: "fallback"`.
|
|
132
141
|
*/
|
|
133
142
|
export declare class SetupError extends Error {
|
|
134
143
|
constructor(message: string);
|
package/dist/types.js
CHANGED
|
@@ -21,7 +21,8 @@ export class ProviderError extends Error {
|
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* A problem with local setup, such as a provider SDK that isn't installed or a missing setting:
|
|
24
|
-
* something to fix here, not a provider being down. The router stops on it instead of falling back
|
|
24
|
+
* something to fix here, not a provider being down. The router stops on it instead of falling back, unless it
|
|
25
|
+
* was made with `accountErrors: "fallback"`.
|
|
25
26
|
*/
|
|
26
27
|
export class SetupError extends Error {
|
|
27
28
|
constructor(message) {
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RouteOptions, type SandboxSpec, type Strategy } from "./types.js";
|
|
2
2
|
/** Every key a SandboxSpec can have. Anything else in a request is a mistake (e.g. "memory" for "memoryGb"). */
|
|
3
|
-
export declare const SPEC_KEYS: readonly ["vcpu", "memoryGb", "gpu", "env", "timeoutMinutes", "image", "metadata"];
|
|
3
|
+
export declare const SPEC_KEYS: readonly ["vcpu", "memoryGb", "gpu", "env", "timeoutMinutes", "expectedSeconds", "image", "metadata"];
|
|
4
4
|
/** Every key RouteOptions can have. */
|
|
5
5
|
export declare const ROUTE_KEYS: readonly ["provider", "strategy", "fallback", "require", "createTimeoutSeconds", "deadlineSeconds"];
|
|
6
6
|
export declare const STRATEGIES: readonly Strategy[];
|
package/dist/validate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CATALOG } from "./catalog.js";
|
|
2
2
|
import { RouterError } from "./types.js";
|
|
3
3
|
/** Every key a SandboxSpec can have. Anything else in a request is a mistake (e.g. "memory" for "memoryGb"). */
|
|
4
|
-
export const SPEC_KEYS = ["vcpu", "memoryGb", "gpu", "env", "timeoutMinutes", "image", "metadata"];
|
|
4
|
+
export const SPEC_KEYS = ["vcpu", "memoryGb", "gpu", "env", "timeoutMinutes", "expectedSeconds", "image", "metadata"];
|
|
5
5
|
/** Every key RouteOptions can have. */
|
|
6
6
|
export const ROUTE_KEYS = ["provider", "strategy", "fallback", "require", "createTimeoutSeconds", "deadlineSeconds"];
|
|
7
7
|
export const STRATEGIES = ["default", "balanced", "verified", "cheapest", "fastest"];
|
|
@@ -16,7 +16,7 @@ const stringMap = (v) => typeof v === "object" && v !== null && !Array.isArray(v
|
|
|
16
16
|
* Called by `plan()`, so every create, route and CLI command goes through it.
|
|
17
17
|
*/
|
|
18
18
|
export function validate(spec = {}, route = {}) {
|
|
19
|
-
for (const k of ["vcpu", "memoryGb", "timeoutMinutes"]) {
|
|
19
|
+
for (const k of ["vcpu", "memoryGb", "timeoutMinutes", "expectedSeconds"]) {
|
|
20
20
|
if (spec[k] !== undefined && !positive(spec[k]))
|
|
21
21
|
throw bad(`${k} must be a positive number, got ${show(spec[k])}`);
|
|
22
22
|
}
|
package/dist/verified.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandboxrouter/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
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",
|