@sandboxrouter/sdk 0.13.0 → 0.14.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 +2 -2
- package/dist/billing.js +0 -1
- package/dist/catalog.d.ts +2 -0
- package/dist/catalog.js +19 -12
- package/dist/cli.js +3 -1
- package/dist/client.d.ts +6 -1
- package/dist/client.js +19 -0
- package/dist/cost.d.ts +44 -5
- package/dist/cost.js +54 -24
- package/dist/providers/blaxel.d.ts +1 -0
- package/dist/providers/blaxel.js +56 -1
- package/dist/providers/daytona.js +33 -1
- package/dist/providers/deno.d.ts +3 -0
- package/dist/providers/deno.js +14 -0
- package/dist/providers/docker.d.ts +1 -0
- package/dist/providers/docker.js +17 -0
- package/dist/providers/e2b.d.ts +22 -1
- package/dist/providers/e2b.js +50 -3
- package/dist/providers/hopx.js +12 -0
- package/dist/providers/modal.js +7 -0
- package/dist/providers/novita.js +5 -5
- package/dist/providers/sail.js +4 -4
- package/dist/providers/vercel.js +39 -1
- package/dist/published.js +957 -2
- package/dist/results.d.ts +2 -2
- package/dist/results.js +62 -1
- package/dist/router.d.ts +8 -5
- package/dist/router.js +39 -5
- package/dist/server.d.ts +4 -1
- package/dist/server.js +101 -7
- package/dist/types.d.ts +16 -1
- package/dist/validate.d.ts +4 -2
- package/dist/validate.js +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,8 +34,8 @@ Site and docs: [sandboxrouter.ai](https://sandboxrouter.ai) · npm: [`@sandboxro
|
|
|
34
34
|
|
|
35
35
|
AI agents need a disposable computer to run code a model wrote: install packages, run tests, do an RL rollout. Dozens of providers sell one, each with its own SDK and auth, and the same 2 vCPU / 4 GB sandbox costs from under a cent to over thirty cents an hour. sandboxRouter is one interface over all of them:
|
|
36
36
|
|
|
37
|
-
- **Same code everywhere.** `create`,
|
|
38
|
-
- **The provider's own SDK is still there.** `sbx.native` is the provider's own sandbox object
|
|
37
|
+
- **Same code everywhere.** `create`, streamed `exec`, files and cleanup. Require support for `pause`, preview URLs with `sbx.url(port)`, or background commands with `sbx.start()`. See [Preview URLs and background commands](docs/reference.md#preview-urls-and-background-commands).
|
|
38
|
+
- **The provider's own SDK is still there.** `sbx.native` is the provider's own sandbox object for features such as snapshots and volumes. See [Using a provider's own features](https://sandboxrouter.ai/docs#native).
|
|
39
39
|
- **Cheapest real cost, then speed, with fallback.** A `maxHourlyUsd` price cap and `quote()` to see where a sandbox would land and what the run costs before starting it. Or `cheapest` for strictly lowest cost for the run, `fastest` by start times, `verified` for tested providers first, or a list of providers you name. `requireVerified` limits a router to providers that passed the real-account check.
|
|
40
40
|
- **Errors you can act on.** Every failure has a `code` (`no_provider`, `setup`, `all_failed`, `timeout`, ...), an HTTP status, and the list of providers tried.
|
|
41
41
|
- **Your keys, or one hosted key.** With your own provider keys, sandboxes run on your accounts and nothing passes through anyone else. The optional hosted key (api.sandboxrouter.ai) runs them on sandboxRouter's provider accounts instead, so its requests go through that server; see [Security](https://www.sandboxrouter.ai/security).
|
package/dist/billing.js
CHANGED
package/dist/catalog.d.ts
CHANGED
package/dist/catalog.js
CHANGED
|
@@ -45,7 +45,7 @@ const ENTRIES = [
|
|
|
45
45
|
source: "https://docs.docker.com/engine/",
|
|
46
46
|
checked: "2026-11-04",
|
|
47
47
|
},
|
|
48
|
-
capabilities: ["pause", "custom-image"],
|
|
48
|
+
capabilities: ["pause", "custom-image", "ports"],
|
|
49
49
|
limits: { maxVcpu: 64, maxMemoryGb: 256 },
|
|
50
50
|
local: true,
|
|
51
51
|
credentials: [],
|
|
@@ -76,7 +76,7 @@ const ENTRIES = [
|
|
|
76
76
|
source: "https://e2b.dev/pricing",
|
|
77
77
|
checked: "2026-11-04",
|
|
78
78
|
},
|
|
79
|
-
capabilities: ["pause", "custom-image"],
|
|
79
|
+
capabilities: ["pause", "custom-image", "ports", "background"],
|
|
80
80
|
limits: { maxVcpu: 8, maxMemoryGb: 8 },
|
|
81
81
|
// The default template; a bigger size needs a template built with --cpu-count / --memory-mb.
|
|
82
82
|
defaultSize: { vcpu: 2, memoryGb: 0.5, measured: "2026-11-06" },
|
|
@@ -93,7 +93,7 @@ const ENTRIES = [
|
|
|
93
93
|
source: "https://www.daytona.io/pricing",
|
|
94
94
|
checked: "2026-11-17",
|
|
95
95
|
},
|
|
96
|
-
capabilities: ["pause", "custom-image"],
|
|
96
|
+
capabilities: ["pause", "custom-image", "ports", "background"],
|
|
97
97
|
limits: { maxVcpu: 4, maxMemoryGb: 8 },
|
|
98
98
|
// The default snapshot; resources only apply when creating from an image (image.daytona).
|
|
99
99
|
defaultSize: { vcpu: 1, memoryGb: 1, measured: "2026-11-06" },
|
|
@@ -112,7 +112,7 @@ const ENTRIES = [
|
|
|
112
112
|
source: "https://modal.com/pricing",
|
|
113
113
|
checked: "2026-11-17",
|
|
114
114
|
},
|
|
115
|
-
capabilities: ["gpu", "custom-image"],
|
|
115
|
+
capabilities: ["gpu", "custom-image", "ports"],
|
|
116
116
|
limits: { maxVcpu: 64, maxMemoryGb: 256 },
|
|
117
117
|
credentials: [["MODAL_TOKEN_ID", "MODAL_TOKEN_SECRET"]],
|
|
118
118
|
docs: "https://modal.com/docs/guide/sandbox",
|
|
@@ -130,8 +130,8 @@ const ENTRIES = [
|
|
|
130
130
|
source: "https://vercel.com/docs/vercel-sandbox/pricing",
|
|
131
131
|
checked: "2026-11-05",
|
|
132
132
|
},
|
|
133
|
-
capabilities: [],
|
|
134
|
-
limits: { maxVcpu: 8, maxMemoryGb: 16 },
|
|
133
|
+
capabilities: ["ports", "background"],
|
|
134
|
+
limits: { maxVcpu: 8, maxMemoryGb: 16, maxPorts: 15 },
|
|
135
135
|
credentials: [["VERCEL_OIDC_TOKEN"], ["VERCEL_TOKEN", "VERCEL_TEAM_ID", "VERCEL_PROJECT_ID"]],
|
|
136
136
|
docs: "https://vercel.com/docs/vercel-sandbox",
|
|
137
137
|
},
|
|
@@ -176,9 +176,9 @@ const ENTRIES = [
|
|
|
176
176
|
source: "https://blaxel.ai/pricing",
|
|
177
177
|
checked: "2026-11-04",
|
|
178
178
|
},
|
|
179
|
-
capabilities: ["custom-image"],
|
|
179
|
+
capabilities: ["custom-image", "ports", "background"],
|
|
180
180
|
// Self-serve caps are per-tier and not published; these are conservative.
|
|
181
|
-
limits: { maxVcpu: 8, maxMemoryGb: 16 },
|
|
181
|
+
limits: { maxVcpu: 8, maxMemoryGb: 16, reservedPorts: [80, 443, 8080] },
|
|
182
182
|
credentials: [["BL_API_KEY", "BL_WORKSPACE"]],
|
|
183
183
|
docs: "https://docs.blaxel.ai/Sandboxes/Overview",
|
|
184
184
|
noBenchmarks: {
|
|
@@ -274,9 +274,9 @@ ENTRIES.push({
|
|
|
274
274
|
source: "https://hopx.ai/pricing",
|
|
275
275
|
checked: "2026-11-04",
|
|
276
276
|
},
|
|
277
|
-
capabilities: ["pause", "custom-image"],
|
|
277
|
+
capabilities: ["pause", "custom-image", "ports"],
|
|
278
278
|
// HOPX takes no size at create; capped at the default size so bigger requests go elsewhere.
|
|
279
|
-
limits: { maxVcpu: 2, maxMemoryGb: 4 },
|
|
279
|
+
limits: { maxVcpu: 2, maxMemoryGb: 4, reservedPorts: [7777] },
|
|
280
280
|
credentials: [["HOPX_API_KEY"]],
|
|
281
281
|
docs: "https://docs.hopx.ai",
|
|
282
282
|
}, {
|
|
@@ -480,7 +480,7 @@ ENTRIES.push({
|
|
|
480
480
|
source: "https://deno.com/sandbox",
|
|
481
481
|
checked: "2026-11-17",
|
|
482
482
|
},
|
|
483
|
-
capabilities: ["custom-image"],
|
|
483
|
+
capabilities: ["custom-image", "ports"],
|
|
484
484
|
limits: { maxVcpu: 2, maxMemoryGb: 4 },
|
|
485
485
|
credentials: [["DENO_DEPLOY_TOKEN"]],
|
|
486
486
|
docs: "https://docs.deno.com/sandbox/",
|
|
@@ -562,7 +562,7 @@ ENTRIES.push({
|
|
|
562
562
|
source: "https://docs.novita.ai/guides/sandbox-pricing",
|
|
563
563
|
checked: "2026-11-04",
|
|
564
564
|
},
|
|
565
|
-
capabilities: ["pause", "custom-image"],
|
|
565
|
+
capabilities: ["pause", "custom-image", "ports", "background"],
|
|
566
566
|
limits: { maxVcpu: 8, maxMemoryGb: 8 },
|
|
567
567
|
credentials: [["NOVITA_API_KEY"]],
|
|
568
568
|
docs: "https://docs.novita.ai/guides/sandbox-overview",
|
|
@@ -829,9 +829,16 @@ export function unfit(id, spec, require = []) {
|
|
|
829
829
|
const needs = new Set(require);
|
|
830
830
|
if (spec.gpu)
|
|
831
831
|
needs.add("gpu");
|
|
832
|
+
if (spec.ports?.length)
|
|
833
|
+
needs.add("ports");
|
|
832
834
|
for (const c of needs)
|
|
833
835
|
if (!p.capabilities.includes(c))
|
|
834
836
|
return `no ${c} support`;
|
|
837
|
+
if (spec.ports?.length && p.limits.maxPorts !== undefined && spec.ports.length > p.limits.maxPorts)
|
|
838
|
+
return `max ${p.limits.maxPorts} preview ports`;
|
|
839
|
+
const reserved = spec.ports?.find((port) => p.limits.reservedPorts?.includes(port));
|
|
840
|
+
if (reserved !== undefined)
|
|
841
|
+
return `port ${reserved} is reserved by the provider`;
|
|
835
842
|
if ((spec.vcpu ?? DEFAULT_VCPU) > p.limits.maxVcpu)
|
|
836
843
|
return `max ${p.limits.maxVcpu} vCPU`;
|
|
837
844
|
if ((spec.memoryGb ?? DEFAULT_MEMORY_GB) > p.limits.maxMemoryGb)
|
package/dist/cli.js
CHANGED
|
@@ -70,7 +70,7 @@ Usage:
|
|
|
70
70
|
sandboxrouter serve [--port 8787] [--host 127.0.0.1] [--cors https://site.example,http://localhost:3000]
|
|
71
71
|
|
|
72
72
|
Spec flags: --vcpu N --memory GB --gpu T4 --timeout MIN --expect SEC (how long you'll use it; ranks by the real bill)
|
|
73
|
-
--cpu 0.1 (how busy the CPU is, 0-1; lowers providers that bill active CPU)
|
|
73
|
+
--cpu 0.1 (how busy the CPU is, 0-1; lowers providers that bill active CPU) --ports 3000,8080
|
|
74
74
|
Route flags: --provider e2b[,modal,...] --strategy balanced|verified|cheapest|fastest (default balanced: cheapest real cost, speed breaks near-ties)
|
|
75
75
|
--max-price USD (per hour, for this run: skip providers that would cost more)
|
|
76
76
|
--no-fallback --fallback-any (also on setup errors like a bad key)
|
|
@@ -83,6 +83,7 @@ const { values, positionals } = parseArgs({
|
|
|
83
83
|
options: {
|
|
84
84
|
vcpu: { type: "string" },
|
|
85
85
|
memory: { type: "string" },
|
|
86
|
+
ports: { type: "string" },
|
|
86
87
|
gpu: { type: "string" },
|
|
87
88
|
timeout: { type: "string" },
|
|
88
89
|
expect: { type: "string" },
|
|
@@ -142,6 +143,7 @@ const num = (s) => (s === undefined ? undefined : Number(s));
|
|
|
142
143
|
const spec = {
|
|
143
144
|
vcpu: num(values.vcpu),
|
|
144
145
|
memoryGb: num(values.memory),
|
|
146
|
+
ports: list(values.ports)?.map(Number),
|
|
145
147
|
gpu: values.gpu,
|
|
146
148
|
timeoutMinutes: num(values.timeout),
|
|
147
149
|
expectedSeconds: num(values.expect),
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Candidate, Quote, Size } from "./router.js";
|
|
2
|
-
import type { Attempt, ExecOptions, ExecResult, RouteOptions, RouterErrorCode, SandboxSpec } from "./types.js";
|
|
2
|
+
import type { Attempt, Capability, ExecOptions, ExecResult, RouteOptions, RouterErrorCode, SandboxProcess, SandboxSpec, StartOptions } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Client for the sandboxrouter HTTP API: the hosted service (one key, prepaid credits) or your own
|
|
5
5
|
* `sandboxrouter serve`. Provider keys live on the server; this side only needs the one key.
|
|
@@ -28,6 +28,7 @@ export declare class Client {
|
|
|
28
28
|
estimatedHourlyUsd: number;
|
|
29
29
|
listHourlyUsd: number;
|
|
30
30
|
size: Size;
|
|
31
|
+
capabilities?: Capability[];
|
|
31
32
|
}[]>;
|
|
32
33
|
/** Dry run: which providers would be tried, in order, each with its price, size and any reason it's skipped. */
|
|
33
34
|
route(spec?: SandboxSpec, route?: RouteOptions): Promise<Candidate[]>;
|
|
@@ -78,6 +79,10 @@ export declare class RemoteSandbox {
|
|
|
78
79
|
details?: Partial<CreateResponse>);
|
|
79
80
|
private path;
|
|
80
81
|
exec(cmd: string, opts?: ExecOptions): Promise<ExecResult>;
|
|
82
|
+
/** Get the HTTP preview URL. Some providers need the port declared when creating the sandbox. */
|
|
83
|
+
url(port: number): Promise<string>;
|
|
84
|
+
/** Start a background command. The returned process can be killed without killing its sandbox. */
|
|
85
|
+
start(cmd: string, opts?: StartOptions): Promise<SandboxProcess>;
|
|
81
86
|
writeFile(path: string, content: string | Uint8Array): Promise<void>;
|
|
82
87
|
readFile(path: string): Promise<Uint8Array>;
|
|
83
88
|
readText(path: string): Promise<string>;
|
package/dist/client.js
CHANGED
|
@@ -143,6 +143,25 @@ export class RemoteSandbox {
|
|
|
143
143
|
}
|
|
144
144
|
throw new ClientError(502, "stream ended before the command finished");
|
|
145
145
|
}
|
|
146
|
+
/** Get the HTTP preview URL. Some providers need the port declared when creating the sandbox. */
|
|
147
|
+
async url(port) {
|
|
148
|
+
const response = await this.client.request("GET", this.path(`/ports/${encodeURIComponent(String(port))}`));
|
|
149
|
+
return (await response.json()).url;
|
|
150
|
+
}
|
|
151
|
+
/** Start a background command. The returned process can be killed without killing its sandbox. */
|
|
152
|
+
async start(cmd, opts = {}) {
|
|
153
|
+
const response = await this.client.request("POST", this.path("/processes"), { ...opts, cmd });
|
|
154
|
+
const { id } = (await response.json());
|
|
155
|
+
const path = this.path(`/processes/${encodeURIComponent(id)}`);
|
|
156
|
+
let stopping;
|
|
157
|
+
return {
|
|
158
|
+
id,
|
|
159
|
+
kill: () => stopping ??= this.client.request("DELETE", path).then(() => { }).catch((err) => {
|
|
160
|
+
stopping = undefined;
|
|
161
|
+
throw err;
|
|
162
|
+
}),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
146
165
|
async writeFile(path, content) {
|
|
147
166
|
const data = typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
148
167
|
await this.client.request("PUT", this.path(`/files?path=${encodeURIComponent(path)}`), data);
|
package/dist/cost.d.ts
CHANGED
|
@@ -14,8 +14,11 @@ export interface Delivered {
|
|
|
14
14
|
memoryMb: number;
|
|
15
15
|
}
|
|
16
16
|
export interface Bill {
|
|
17
|
-
/**
|
|
17
|
+
/** Reported USD. The kind distinguishes metered usage from a provider's own estimate. */
|
|
18
18
|
usd?: number;
|
|
19
|
+
kind?: "provider-usage" | "provider-estimate";
|
|
20
|
+
/** Monetary resolution of the underlying report, when it rounds to whole cents. */
|
|
21
|
+
resolutionUsd?: number;
|
|
19
22
|
/** Seconds the provider billed, when it reports them. */
|
|
20
23
|
seconds?: number;
|
|
21
24
|
/** Where the number came from, or why there is none. */
|
|
@@ -42,6 +45,9 @@ export interface CostEntry {
|
|
|
42
45
|
error?: string;
|
|
43
46
|
bill?: Bill;
|
|
44
47
|
}
|
|
48
|
+
/** Older records predate typed evidence. Sail's endpoint reports estimated usage at list rates. */
|
|
49
|
+
export declare function billKind(bill: Bill | undefined): Bill["kind"];
|
|
50
|
+
export declare function billResolutionUsd(bill: Bill | undefined): number | undefined;
|
|
45
51
|
export interface CostRun {
|
|
46
52
|
tool: "sandboxrouter-cost";
|
|
47
53
|
version: string;
|
|
@@ -52,6 +58,40 @@ export interface CostRun {
|
|
|
52
58
|
by?: string;
|
|
53
59
|
entries: CostEntry[];
|
|
54
60
|
}
|
|
61
|
+
export interface HostedLedgerEntry {
|
|
62
|
+
provider: ProviderId;
|
|
63
|
+
requested: {
|
|
64
|
+
vcpu: number;
|
|
65
|
+
memoryGb: number;
|
|
66
|
+
};
|
|
67
|
+
size: {
|
|
68
|
+
vcpu: number;
|
|
69
|
+
memoryGb: number;
|
|
70
|
+
};
|
|
71
|
+
expectedSeconds: number;
|
|
72
|
+
runtimeSeconds: number;
|
|
73
|
+
quoteUsd: number;
|
|
74
|
+
quoteAtRecordedRuntimeUsd?: number;
|
|
75
|
+
chargeUsd: number;
|
|
76
|
+
balanceDeltaUsd: number;
|
|
77
|
+
keySpendDeltaUsd?: number;
|
|
78
|
+
minimumSeconds?: number;
|
|
79
|
+
minimumCovers?: "all" | "memory";
|
|
80
|
+
incrementSeconds?: number;
|
|
81
|
+
feePct: number;
|
|
82
|
+
checkedAt?: string;
|
|
83
|
+
createMs?: number;
|
|
84
|
+
commandMs?: number;
|
|
85
|
+
belowQuotedCapRejected?: boolean;
|
|
86
|
+
commandVerified: true;
|
|
87
|
+
deleted: true;
|
|
88
|
+
}
|
|
89
|
+
export interface HostedLedgerRun {
|
|
90
|
+
tool: "sandboxrouter-hosted-ledger";
|
|
91
|
+
date: string;
|
|
92
|
+
keySpendDeltaUsd?: number;
|
|
93
|
+
entries: HostedLedgerEntry[];
|
|
94
|
+
}
|
|
55
95
|
/**
|
|
56
96
|
* The size the sandbox really has, as "<vcpus> <memoryMb>". nproc and MemTotal can show the whole host
|
|
57
97
|
* (Daytona's containers report 64 CPUs and 755 GB while limited to 1 vCPU and 1 GB), so the cgroup limits
|
|
@@ -75,10 +115,9 @@ export declare const BILL_READERS: Partial<Record<ProviderId, Reader>>;
|
|
|
75
115
|
export declare function settle(run: CostRun): Promise<CostRun>;
|
|
76
116
|
export declare function costMarkdown(run: CostRun): string;
|
|
77
117
|
/**
|
|
78
|
-
* Billed / predicted
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* forbid publishing benchmarks are left out, like everywhere else results are published.
|
|
118
|
+
* Billed / predicted for the latest loaded run of at least ten minutes with metered provider usage.
|
|
119
|
+
* A bill rounded to whole cents only counts when the prediction is at least $1, so rounding can't
|
|
120
|
+
* move the ratio by more than 1%. Providers that forbid publishing benchmarks are left out.
|
|
82
121
|
*/
|
|
83
122
|
export declare function billedVsList(dir?: string): {
|
|
84
123
|
provider: ProviderId;
|
package/dist/cost.js
CHANGED
|
@@ -2,6 +2,15 @@ import { readdirSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { benchmarksPublishable, billingRules, fittingSpec, hourlyCost } from "./catalog.js";
|
|
4
4
|
import { Router } from "./router.js";
|
|
5
|
+
/** Older records predate typed evidence. Sail's endpoint reports estimated usage at list rates. */
|
|
6
|
+
export function billKind(bill) {
|
|
7
|
+
if (bill?.usd === undefined)
|
|
8
|
+
return undefined;
|
|
9
|
+
return bill.kind ?? (/estimate at list rates/i.test(bill.source) ? "provider-estimate" : "provider-usage");
|
|
10
|
+
}
|
|
11
|
+
export function billResolutionUsd(bill) {
|
|
12
|
+
return bill?.resolutionUsd ?? (bill?.usd !== undefined && /integer cents/i.test(bill.source) ? 0.01 : undefined);
|
|
13
|
+
}
|
|
5
14
|
/**
|
|
6
15
|
* The size the sandbox really has, as "<vcpus> <memoryMb>". nproc and MemTotal can show the whole host
|
|
7
16
|
* (Daytona's containers report 64 CPUs and 755 GB while limited to 1 vCPU and 1 GB), so the cgroup limits
|
|
@@ -34,13 +43,15 @@ export async function costRun(opts) {
|
|
|
34
43
|
entry.startedAt = new Date(t0).toISOString();
|
|
35
44
|
box = await router.create({ vcpu, memoryGb, timeoutMinutes: opts.minutes + 10 }, { provider, fallback: false });
|
|
36
45
|
entry.sandboxId = box.nativeId;
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
const probe = await box.exec(PROBE);
|
|
47
|
+
const [cpus, mem, extra] = probe.stdout.trim().split(/\s+/).map(Number);
|
|
48
|
+
if (probe.exitCode !== 0 || !Number.isFinite(cpus) || !Number.isFinite(mem) || cpus <= 0 || mem <= 0 || extra !== undefined) {
|
|
49
|
+
throw new Error("size probe failed or returned invalid output");
|
|
41
50
|
}
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
entry.delivered = { vcpu: cpus, memoryMb: mem };
|
|
52
|
+
entry.deliveredUsdHour = round(hourlyCost(provider, { vcpu: cpus, memoryGb: mem / 1024 }));
|
|
53
|
+
if (load && (await box.exec(LOAD)).exitCode !== 0)
|
|
54
|
+
throw new Error("CPU load command failed");
|
|
44
55
|
log(`${provider}: running ${box.nativeId} for ${opts.minutes} min`);
|
|
45
56
|
await sleep(opts.minutes * 60_000 - (Date.now() - t0));
|
|
46
57
|
}
|
|
@@ -65,7 +76,7 @@ export async function costRun(opts) {
|
|
|
65
76
|
async function getJson(url, headers) {
|
|
66
77
|
const r = await fetch(url, { headers, signal: AbortSignal.timeout(30_000) });
|
|
67
78
|
if (!r.ok)
|
|
68
|
-
throw new Error(
|
|
79
|
+
throw new Error(`billing HTTP ${r.status}`);
|
|
69
80
|
return r.json();
|
|
70
81
|
}
|
|
71
82
|
const hourFloor = (iso) => new Date(Math.floor(Date.parse(iso) / 3_600_000) * 3_600_000).toISOString();
|
|
@@ -82,7 +93,10 @@ export const BILL_READERS = {
|
|
|
82
93
|
if (!row)
|
|
83
94
|
return { source: "daytona usage API: not posted yet (can take up to 48 h)" };
|
|
84
95
|
const seconds = row.firstStart && row.lastEnd ? Math.round((Date.parse(row.lastEnd) - Date.parse(row.firstStart)) / 1000) : undefined;
|
|
85
|
-
|
|
96
|
+
if (typeof row.totalPrice !== "number" || !Number.isFinite(row.totalPrice) || row.totalPrice < 0) {
|
|
97
|
+
return { source: "daytona analytics /usage/sandbox: no valid totalPrice yet" };
|
|
98
|
+
}
|
|
99
|
+
return { usd: round(row.totalPrice), kind: "provider-usage", seconds, source: "daytona analytics /usage/sandbox totalPrice" };
|
|
86
100
|
},
|
|
87
101
|
async blaxel(e) {
|
|
88
102
|
const h = { Authorization: `Bearer ${process.env.BL_API_KEY}` };
|
|
@@ -94,7 +108,10 @@ export const BILL_READERS = {
|
|
|
94
108
|
const row = (j.data ?? []).find((d) => d.resourceName === e.sandboxId);
|
|
95
109
|
if (!row)
|
|
96
110
|
return { source: "blaxel metrics API: not posted yet (lags a few minutes)" };
|
|
97
|
-
|
|
111
|
+
if (typeof row.summary?.cost !== "number" || !Number.isFinite(row.summary.cost) || row.summary.cost < 0) {
|
|
112
|
+
return { source: "blaxel /metrics: no valid cost yet" };
|
|
113
|
+
}
|
|
114
|
+
return { usd: round(row.summary.cost), kind: "provider-usage", source: "blaxel /metrics cost (USD)" };
|
|
98
115
|
},
|
|
99
116
|
async maritime(e) {
|
|
100
117
|
const h = { Authorization: `Bearer ${process.env.MARITIME_API_KEY}` };
|
|
@@ -103,10 +120,13 @@ export const BILL_READERS = {
|
|
|
103
120
|
const days = j.byMachineDay?.[`sandbox:${e.sandboxId}`] ?? [];
|
|
104
121
|
if (!days.length)
|
|
105
122
|
return { source: "maritime metered-usage: not posted yet" };
|
|
106
|
-
|
|
123
|
+
if (!days.every((d) => Number.isInteger(d.cents) && d.cents >= 0)) {
|
|
124
|
+
return { source: "maritime metered-usage: no valid cents field yet" };
|
|
125
|
+
}
|
|
126
|
+
const cents = days.reduce((n, d) => n + d.cents, 0);
|
|
107
127
|
const seconds = days.reduce((n, d) => n + (d.seconds ?? 0), 0);
|
|
108
128
|
const model = j.plan ? `plan ${j.plan}` : "no usage plan on this account";
|
|
109
|
-
return { usd: round(cents / 100), seconds: Math.round(seconds), source: `maritime metered-usage (integer cents; ${model})` };
|
|
129
|
+
return { usd: round(cents / 100), kind: "provider-usage", resolutionUsd: 0.01, seconds: Math.round(seconds), source: `maritime metered-usage (integer cents; ${model})` };
|
|
110
130
|
},
|
|
111
131
|
async sail(e) {
|
|
112
132
|
const h = { Authorization: `Bearer ${process.env.SAIL_API_KEY}` };
|
|
@@ -116,9 +136,13 @@ export const BILL_READERS = {
|
|
|
116
136
|
const row = (j.sailboxes ?? []).find((s) => s.sailbox_id === e.sandboxId);
|
|
117
137
|
if (!row)
|
|
118
138
|
return { source: "sail /sailboxes/spend: not posted yet (a few minutes)" };
|
|
139
|
+
if (!Number.isInteger(row.cost_usd_nanos) || row.cost_usd_nanos < 0) {
|
|
140
|
+
return { source: "sail /sailboxes/spend: no valid cost_usd_nanos yet" };
|
|
141
|
+
}
|
|
119
142
|
const fees = j.creation_fees_waived ? "creation fee waived" : `${row.creation_count ?? 0} creation charge`;
|
|
120
143
|
return {
|
|
121
|
-
usd: round(
|
|
144
|
+
usd: round(row.cost_usd_nanos / 1e9),
|
|
145
|
+
kind: "provider-estimate",
|
|
122
146
|
seconds: Math.round(row.running_seconds ?? 0),
|
|
123
147
|
source: `sail /sailboxes/spend cost_usd_nanos (estimate at list rates; ${fees}; ${Math.round(row.vcpu_seconds ?? 0)} vCPU-s, ${Math.round(row.memory_gib_seconds ?? 0)} GiB-s)`,
|
|
124
148
|
};
|
|
@@ -132,8 +156,12 @@ export const BILL_READERS = {
|
|
|
132
156
|
const row = (j.instances ?? []).find((i) => i.id === id);
|
|
133
157
|
if (!row)
|
|
134
158
|
return { source: "agent37 /v1/usage: not posted yet" };
|
|
159
|
+
if (!Number.isInteger(row.total_micros) || row.total_micros < 0) {
|
|
160
|
+
return { source: "agent37 /v1/usage: no valid total_micros yet" };
|
|
161
|
+
}
|
|
135
162
|
return {
|
|
136
|
-
usd: round(
|
|
163
|
+
usd: round(row.total_micros / 1e6),
|
|
164
|
+
kind: "provider-usage",
|
|
137
165
|
seconds: (row.awake_minutes ?? 0) * 60,
|
|
138
166
|
source: `agent37 /v1/usage total_micros (billed in whole minutes: ${row.awake_minutes ?? 0} awake)`,
|
|
139
167
|
};
|
|
@@ -166,25 +194,25 @@ export async function settle(run) {
|
|
|
166
194
|
}
|
|
167
195
|
return run;
|
|
168
196
|
}
|
|
169
|
-
const usd = (n) =>
|
|
197
|
+
const usd = (n, resolution) => n === undefined ? "n/a" : `$${n.toFixed(resolution === 0.01 ? 2 : 6)}`;
|
|
170
198
|
export function costMarkdown(run) {
|
|
171
199
|
const lines = [
|
|
172
|
-
"| Provider | Asked for | Got | Ran | Predicted (list × time) |
|
|
200
|
+
"| Provider | Asked for | Got | Ran | Predicted (list × time) | Reported | Usage ÷ predicted | Source |",
|
|
173
201
|
"|---|---|---|---|---|---|---|---|",
|
|
174
202
|
];
|
|
175
203
|
for (const e of run.entries) {
|
|
176
204
|
const got = e.delivered ? `${e.delivered.vcpu} vCPU / ${(e.delivered.memoryMb / 1024).toFixed(1)} GB` : "n/a";
|
|
177
|
-
const ratio = e.bill?.usd !== undefined && e.predictedUsd
|
|
205
|
+
const ratio = billKind(e.bill) === "provider-usage" && e.bill?.usd !== undefined && e.predictedUsd && !billResolutionUsd(e.bill)
|
|
206
|
+
? `${((e.bill.usd / e.predictedUsd) * 100).toFixed(0)}%` : "n/a";
|
|
178
207
|
const ran = e.seconds !== undefined ? `${e.seconds} s${e.bill?.seconds !== undefined ? ` (billed ${e.bill.seconds} s)` : ""}` : "n/a";
|
|
179
|
-
lines.push(`| ${e.provider} | ${e.requested.vcpu} vCPU / ${e.requested.memoryGb} GB | ${got} | ${ran} | ${usd(e.predictedUsd)} | ${usd(e.bill?.usd)} | ${ratio} | ${e.error ? `error: ${e.error}` : (e.bill?.source ?? "not settled")} |`);
|
|
208
|
+
lines.push(`| ${e.provider} | ${e.requested.vcpu} vCPU / ${e.requested.memoryGb} GB | ${got} | ${ran} | ${usd(e.predictedUsd)} | ${usd(e.bill?.usd, billResolutionUsd(e.bill))} | ${ratio} | ${e.error ? `error: ${e.error}` : (e.bill?.source ?? "not settled")} |`);
|
|
180
209
|
}
|
|
181
210
|
return lines.join("\n");
|
|
182
211
|
}
|
|
183
212
|
/**
|
|
184
|
-
* Billed / predicted
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* forbid publishing benchmarks are left out, like everywhere else results are published.
|
|
213
|
+
* Billed / predicted for the latest loaded run of at least ten minutes with metered provider usage.
|
|
214
|
+
* A bill rounded to whole cents only counts when the prediction is at least $1, so rounding can't
|
|
215
|
+
* move the ratio by more than 1%. Providers that forbid publishing benchmarks are left out.
|
|
188
216
|
*/
|
|
189
217
|
export function billedVsList(dir = "results/cost") {
|
|
190
218
|
let files;
|
|
@@ -203,19 +231,21 @@ export function billedVsList(dir = "results/cost") {
|
|
|
203
231
|
catch {
|
|
204
232
|
continue;
|
|
205
233
|
}
|
|
206
|
-
if (run?.tool !== "sandboxrouter-cost" || !Array.isArray(run.entries))
|
|
234
|
+
if (run?.tool !== "sandboxrouter-cost" || !run.load || !Array.isArray(run.entries))
|
|
207
235
|
continue;
|
|
208
236
|
for (const e of run.entries) {
|
|
209
237
|
const usd = e.bill?.usd;
|
|
210
238
|
const predicted = e.predictedUsd;
|
|
211
|
-
if (
|
|
239
|
+
if (e.error || (e.seconds ?? 0) < 600 || billKind(e.bill) !== "provider-usage" ||
|
|
240
|
+
!usd || !predicted || usd <= 0 || predicted <= 0 || !benchmarksPublishable(e.provider))
|
|
212
241
|
continue;
|
|
213
242
|
// A fixed per-sandbox charge (Sail's $0.01) isn't an hourly rate: take it out, or a 10-minute run
|
|
214
243
|
// turns it into "bills 46% over list" for every hour after.
|
|
215
244
|
const running = usd - billingRules(e.provider).perSandboxUsd;
|
|
216
245
|
if (running <= 0)
|
|
217
246
|
continue;
|
|
218
|
-
|
|
247
|
+
const resolution = billResolutionUsd(e.bill);
|
|
248
|
+
if (resolution !== undefined && predicted < 100 * resolution)
|
|
219
249
|
continue;
|
|
220
250
|
const date = run.date.slice(0, 10);
|
|
221
251
|
const prev = latest.get(e.provider);
|
|
@@ -6,6 +6,7 @@ import { type Provider, type ProviderSandbox, type SandboxSpec } from "../types.
|
|
|
6
6
|
* wake on the next call. No pause(): archiving is a preview Blaxel enables per workspace (others
|
|
7
7
|
* get 403 "Archiving a sandbox is in preview and is not enabled for this workspace", 2026-11-05).
|
|
8
8
|
* kill() waits until the sandbox is gone, because Blaxel deletes asynchronously.
|
|
9
|
+
* Preview URLs create private previews on demand and carry a short-lived Blaxel preview token.
|
|
9
10
|
*/
|
|
10
11
|
export declare class BlaxelProvider implements Provider {
|
|
11
12
|
private apiKey;
|
package/dist/providers/blaxel.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { DEFAULT_MEMORY_GB, DEFAULT_VCPU } from "../catalog.js";
|
|
1
|
+
import { DEFAULT_MEMORY_GB, DEFAULT_VCPU, info } from "../catalog.js";
|
|
2
2
|
import { ProviderError } from "../types.js";
|
|
3
3
|
import { DEFAULT_EXEC_TIMEOUT_S, errorStatus, optionalImport, timeoutError, toBytes } from "../util.js";
|
|
4
4
|
/** Blaxel's public base image (the SDK's own default). Set image.blaxel for another image or a `bl deploy` template. */
|
|
5
5
|
const DEFAULT_IMAGE = "blaxel/base-image:latest";
|
|
6
6
|
/** Blaxel rejects a max-age ttl under 5 minutes. */
|
|
7
7
|
const MIN_TTL_MINUTES = 5;
|
|
8
|
+
const PREVIEW_TTL_MS = 30 * 60_000;
|
|
8
9
|
/**
|
|
9
10
|
* Blaxel sandboxes via `@blaxel/core`. Auth: BL_API_KEY + BL_WORKSPACE (or `bl login`).
|
|
10
11
|
* Region: BL_REGION, else us-pdx-1. Blaxel sizes by memory only and gives 1 vCPU per 2 GB,
|
|
@@ -12,6 +13,7 @@ const MIN_TTL_MINUTES = 5;
|
|
|
12
13
|
* wake on the next call. No pause(): archiving is a preview Blaxel enables per workspace (others
|
|
13
14
|
* get 403 "Archiving a sandbox is in preview and is not enabled for this workspace", 2026-11-05).
|
|
14
15
|
* kill() waits until the sandbox is gone, because Blaxel deletes asynchronously.
|
|
16
|
+
* Preview URLs create private previews on demand and carry a short-lived Blaxel preview token.
|
|
15
17
|
*/
|
|
16
18
|
export class BlaxelProvider {
|
|
17
19
|
apiKey;
|
|
@@ -118,6 +120,59 @@ class BlaxelBox {
|
|
|
118
120
|
// A nonzero exit is a result (status "failed"), not an error.
|
|
119
121
|
return { exitCode: r.exitCode, stdout: r.stdout ?? "", stderr: r.stderr ?? "", durationMs: Date.now() - t0 };
|
|
120
122
|
}
|
|
123
|
+
async url(port) {
|
|
124
|
+
if (info("blaxel").limits.reservedPorts?.includes(port))
|
|
125
|
+
throw new ProviderError("blaxel", `port ${port} is reserved`, 400);
|
|
126
|
+
try {
|
|
127
|
+
const preview = await this.sbx.previews.createIfNotExists({
|
|
128
|
+
metadata: { name: `sandboxrouter-${port}` },
|
|
129
|
+
spec: { port, public: false },
|
|
130
|
+
});
|
|
131
|
+
// Never reuse a conflicting preview or turn even a previously created one public.
|
|
132
|
+
if (preview.spec.port !== port || preview.spec.public === true) {
|
|
133
|
+
throw new ProviderError("blaxel", `existing preview for port ${port} has different access or routing settings`, 409);
|
|
134
|
+
}
|
|
135
|
+
const url = new URL(preview.url);
|
|
136
|
+
if (url.protocol !== "https:")
|
|
137
|
+
throw new ProviderError("blaxel", "preview did not return an HTTPS URL");
|
|
138
|
+
const expiresAt = new Date(Date.now() + PREVIEW_TTL_MS);
|
|
139
|
+
const token = typeof preview.tokens.createIfExpired === "function"
|
|
140
|
+
? await preview.tokens.createIfExpired(expiresAt, 60_000)
|
|
141
|
+
: await preview.tokens.create(expiresAt);
|
|
142
|
+
url.searchParams.set("bl_preview_token", token.value);
|
|
143
|
+
return url.toString();
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
throw wrap(err);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async start(cmd, opts = {}) {
|
|
150
|
+
try {
|
|
151
|
+
const process = await this.sbx.process.exec({
|
|
152
|
+
command: cmd,
|
|
153
|
+
workingDir: opts.cwd,
|
|
154
|
+
env: opts.env,
|
|
155
|
+
waitForCompletion: false,
|
|
156
|
+
keepAlive: true,
|
|
157
|
+
timeout: 0,
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
kill: async () => {
|
|
161
|
+
try {
|
|
162
|
+
await this.sbx.process.kill(process.pid);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
const error = wrap(err);
|
|
166
|
+
if (error.status !== 404)
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
throw wrap(err);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
121
176
|
async writeFile(path, content) {
|
|
122
177
|
try {
|
|
123
178
|
await this.sbx.fs.writeBinary(path, toBytes(content));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { ProviderError } from "../types.js";
|
|
3
|
-
import { DEFAULT_EXEC_TIMEOUT_S, optionalImport, timeoutError, toBytes, wrapCommand } from "../util.js";
|
|
3
|
+
import { DEFAULT_EXEC_TIMEOUT_S, errorStatus, optionalImport, timeoutError, toBytes, wrapCommand } from "../util.js";
|
|
4
4
|
/**
|
|
5
5
|
* Daytona via `@daytonaio/sdk`. Default snapshot; set image.daytona to start from an image.
|
|
6
6
|
*
|
|
@@ -205,6 +205,38 @@ class DaytonaBox {
|
|
|
205
205
|
await proc.deleteSession(session).catch(() => { });
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
+
async url(port) {
|
|
209
|
+
// A port-scoped signed URL works in a browser without revealing a sandbox-wide preview token.
|
|
210
|
+
return (await this.sbx.getSignedPreviewUrl(port, 3600)).url;
|
|
211
|
+
}
|
|
212
|
+
async start(cmd, opts = {}) {
|
|
213
|
+
const session = `sbr-${randomUUID()}`;
|
|
214
|
+
const process = this.sbx.process;
|
|
215
|
+
try {
|
|
216
|
+
await process.createSession(session);
|
|
217
|
+
await process.executeSessionCommand(session, {
|
|
218
|
+
command: wrapCommand(`(\n${cmd}\n)`, opts),
|
|
219
|
+
runAsync: true,
|
|
220
|
+
suppressInputEcho: true,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
await process.deleteSession(session).catch(() => { });
|
|
225
|
+
throw new ProviderError("daytona", err instanceof Error ? err.message : String(err), errorStatus(err));
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
async kill() {
|
|
229
|
+
try {
|
|
230
|
+
await process.deleteSession(session);
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
const status = errorStatus(err);
|
|
234
|
+
if (status !== 404)
|
|
235
|
+
throw new ProviderError("daytona", err instanceof Error ? err.message : String(err), status);
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
208
240
|
async writeFile(path, content) {
|
|
209
241
|
await this.sbx.fs.uploadFile(Buffer.from(toBytes(content)), path);
|
|
210
242
|
}
|
package/dist/providers/deno.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ interface DenoChild {
|
|
|
14
14
|
interface DenoSdkSandbox {
|
|
15
15
|
readonly id: string;
|
|
16
16
|
spawn(command: string, options?: Record<string, unknown>): Promise<DenoChild>;
|
|
17
|
+
exposeHttp(target: {
|
|
18
|
+
port: number;
|
|
19
|
+
}): Promise<string>;
|
|
17
20
|
fs: {
|
|
18
21
|
writeFile(path: string, data: Uint8Array): Promise<void>;
|
|
19
22
|
readFile(path: string): Promise<Uint8Array>;
|
package/dist/providers/deno.js
CHANGED
|
@@ -13,6 +13,7 @@ import { dirname, optionalImport, toBytes } from "../util.js";
|
|
|
13
13
|
* The default timeout ("session") would end the VM when this process disconnects, so the adapter
|
|
14
14
|
* always passes a duration, which is what lets connect() reattach. exec streams stdout/stderr from
|
|
15
15
|
* a spawned `/bin/sh -c`. No pause.
|
|
16
|
+
* url() explicitly opens a public HTTP preview; Deno serves it through the sandbox lifetime.
|
|
16
17
|
* Docs: https://docs.deno.com/sandbox/, https://docs.deno.com/sandbox/create/,
|
|
17
18
|
* https://docs.deno.com/sandbox/timeouts/, https://docs.deno.com/sandbox/security/,
|
|
18
19
|
* https://deno.com/sandbox (pricing), https://jsr.io/@deno/sandbox
|
|
@@ -82,6 +83,7 @@ class DenoBox {
|
|
|
82
83
|
return this.sbx;
|
|
83
84
|
}
|
|
84
85
|
nativeId;
|
|
86
|
+
previews = new Map();
|
|
85
87
|
constructor(sbx) {
|
|
86
88
|
this.sbx = sbx;
|
|
87
89
|
this.nativeId = sbx.id;
|
|
@@ -125,6 +127,18 @@ class DenoBox {
|
|
|
125
127
|
clearTimeout(giveUp);
|
|
126
128
|
}
|
|
127
129
|
}
|
|
130
|
+
url(port) {
|
|
131
|
+
// exposeHttp allocates a fresh public hostname on each call.
|
|
132
|
+
const existing = this.previews.get(port);
|
|
133
|
+
if (existing)
|
|
134
|
+
return existing;
|
|
135
|
+
const pending = sdk(() => this.sbx.exposeHttp({ port })).catch((err) => {
|
|
136
|
+
this.previews.delete(port);
|
|
137
|
+
throw err;
|
|
138
|
+
});
|
|
139
|
+
this.previews.set(port, pending);
|
|
140
|
+
return pending;
|
|
141
|
+
}
|
|
128
142
|
async writeFile(path, content) {
|
|
129
143
|
const dir = dirname(path);
|
|
130
144
|
if (dir !== "/" && dir !== path)
|