@sandboxrouter/sdk 0.17.0 → 0.18.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # sandboxRouter
2
2
 
3
- **One API for every sandbox.** A free, open-source router for the places an AI agent can run code: Agent37, Alibaba Cloud, AWS (Bedrock AgentCore and Lambda MicroVMs), Azure Container Apps, Beam, Blaxel, Boat, Cloudflare, CodeSandbox, Daytona, Dedalus Machines, Deno, DigitalOcean Harness Runtime, E2B, exe.dev, Fly.io Sprites, Freestyle, Google Cloud Agent Platform, HOPX, InstaBox, Koyeb, Maritime, Modal, Morph, Northflank, Novita, OpenScale, Runloop, Sail, Superserve, Tensorlake, Upstash Box and Vercel, plus Docker on your own machine. It picks a provider by price, speed or capability, and falls back to the next one when a provider is down or rate-limited.
3
+ **One API for every sandbox.** A free, open-source router for the places an AI agent can run code: Agent37, Alibaba Cloud, AWS (Bedrock AgentCore and Lambda MicroVMs), Azure Container Apps, Beam, Blaxel, Boat, Cloudflare, CodeSandbox, Daytona, Dedalus Machines, Deno, DigitalOcean Harness Runtime, E2B, exe.dev, Fly.io Sprites, Freestyle, Google Cloud Agent Platform, HOPX, InstaBox, Koyeb, Maritime, Modal, Morph, Northflank, Novita, OpenScale, Run Cloud, Runloop, Sail, Superserve, Tensorlake, Upstash Box and Vercel, plus Docker on your own machine. It picks a provider by price, speed or capability, and falls back to the next one when a provider is down or rate-limited.
4
4
 
5
5
  E2B quickstart (Node 22.19+ and an E2B API key):
6
6
 
@@ -51,11 +51,11 @@ List price while running, 2 vCPU / 4 GB, cheapest first; waitlisted sign-ups fol
51
51
  | [Agent37](https://sandboxrouter.ai/providers/agent37) | $0.007 | none | passed (2026-11-13) | [pricing](https://www.agent37.com/docs/agents-api/billing) |
52
52
  | [Boat](https://sandboxrouter.ai/providers/boat) | $0.018 | $20/mo (credited) | passed (2026-11-14) | [pricing](https://docs.boat.dev/pricing.md) |
53
53
  | [Maritime](https://sandboxrouter.ai/providers/maritime) | $0.022 | $20/mo (credited) | passed (2026-11-13) | [pricing](https://maritime.sh/pricing) |
54
+ | [Run Cloud](https://sandboxrouter.ai/providers/runcloud) | $0.030 | none | not run yet | [pricing](https://run.cloud/pricing) |
54
55
  | [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) |
55
56
  | [Northflank](https://sandboxrouter.ai/providers/northflank) | $0.067 | none | passed (2026-11-18) | [pricing](https://northflank.com/pricing) |
56
57
  | [Morph Cloud](https://sandboxrouter.ai/providers/morph) | $0.100 | none | passed (2026-11-18) | [pricing](https://cloud.morph.so/web/pricing) |
57
58
  | [exe.dev](https://sandboxrouter.ai/providers/exedev) | $0.105 | $15/mo | not run yet | [pricing](https://exe.dev/docs/standalone-vms.md) |
58
- | [Novita AI Agent Sandbox](https://sandboxrouter.ai/providers/novita) | $0.117 | none | passed (2026-11-13) | [pricing](https://docs.novita.ai/guides/sandbox-pricing) |
59
59
  | [DigitalOcean Harness Runtime](https://sandboxrouter.ai/providers/digitalocean) | up to $0.126 | none | not run yet | [pricing](https://docs.digitalocean.com/products/managed-agents/agent-harness-runtime/details/pricing/) |
60
60
  | [Freestyle](https://sandboxrouter.ai/providers/freestyle) | $0.134 | none | passed (2026-11-13) | [pricing](https://www.freestyle.sh/docs/vms/pricing-and-limits) |
61
61
  | [Beam](https://sandboxrouter.ai/providers/beam) | $0.140 | $20/mo (credited) | passed (2026-11-18) | [pricing](https://www.beam.cloud/pricing) |
@@ -81,11 +81,12 @@ List price while running, 2 vCPU / 4 GB, cheapest first; waitlisted sign-ups fol
81
81
  | [Azure Container Apps dynamic sessions](https://sandboxrouter.ai/providers/azure) | skipped (max 1 vCPU) | none | not run yet | [pricing](https://learn.microsoft.com/en-us/azure/container-apps/billing#dynamic-sessions) |
82
82
  | [Daytona](https://sandboxrouter.ai/providers/daytona) | skipped (default image is 1 vCPU / 1 GB; a bigger size needs image.daytona) | none | passed (2026-11-13) | [pricing](https://www.daytona.io/pricing) |
83
83
  | [Alibaba Cloud Agent Sandbox](https://sandboxrouter.ai/providers/alibaba) | skipped (max 2 GB memory) | none | not run yet | [pricing](https://www.alibabacloud.com/help/en/agent-sandbox/product-overview/billing-overview) |
84
+ | [Novita AI Agent Sandbox](https://sandboxrouter.ai/providers/novita) | skipped (default image is 2 vCPU / 1 GB; a bigger size needs image.novita) | none | passed (2026-11-13) | [pricing](https://docs.novita.ai/guides/sandbox-pricing) |
84
85
  | [Google Cloud Agent Platform](https://sandboxrouter.ai/providers/google) | skipped (max 1 vCPU) | none | passed (2026-11-18) | [pricing](https://cloud.google.com/products/gemini-enterprise-agent-platform/pricing) |
85
86
  | [E2B](https://sandboxrouter.ai/providers/e2b) | skipped (default image is 2 vCPU / 0.5 GB; a bigger size needs image.e2b) | none | passed (2026-11-13) | [pricing](https://e2b.dev/pricing) |
86
87
  | [Docker (local)](https://sandboxrouter.ai/providers/docker) | free | none | passed (2026-11-13) | [pricing](https://docs.docker.com/engine/) |
87
88
 
88
- Checked 2026-11-04 to 2026-11-18.
89
+ Checked 2026-11-04 to 2026-11-27.
89
90
 
90
91
  ## Install
91
92
 
package/dist/catalog.js CHANGED
@@ -514,6 +514,20 @@ ENTRIES.push({
514
514
  credentials: [["DEDALUS_API_KEY"]],
515
515
  docs: "https://docs.dedaluslabs.ai/dcs/dm/quickstart",
516
516
  access: { status: "waitlist", note: "private beta: your organization has to be admitted before keys work", checked: "2026-11-05" },
517
+ }, {
518
+ id: "runcloud",
519
+ name: "Run Cloud",
520
+ pricing: {
521
+ vcpuHour: 0.008856,
522
+ gbHour: 0.0029943,
523
+ note: "per second ($0.00000492 per physical core = 2 vCPUs, $0.00000083175 per GiB); the reservation is the floor, CPU and memory used above it bill at the same rates; $5 to start without a card, then the first $15 a month free with one",
524
+ source: "https://run.cloud/pricing",
525
+ checked: "2026-11-27",
526
+ },
527
+ capabilities: ["pause", "ports", "custom-image"],
528
+ limits: { maxVcpu: 32, maxMemoryGb: 112 },
529
+ credentials: [["RUN_CLOUD_API_KEY"]],
530
+ docs: "https://docs.run.cloud/sandboxes",
517
531
  }, {
518
532
  id: "deno",
519
533
  name: "Deno Sandbox",
@@ -608,6 +622,8 @@ ENTRIES.push({
608
622
  },
609
623
  capabilities: ["pause", "custom-image", "ports", "background"],
610
624
  limits: { maxVcpu: 8, maxMemoryGb: 8 },
625
+ // The default "base" template; a bigger size needs a template built with cpuCount / memoryMB.
626
+ defaultSize: { vcpu: 2, memoryGb: 1, measured: "2026-11-26" },
611
627
  credentials: [["NOVITA_API_KEY"]],
612
628
  docs: "https://docs.novita.ai/guides/sandbox-overview",
613
629
  }, {
@@ -669,6 +685,7 @@ const BILLING = {
669
685
  novita: { billing: "allocated" },
670
686
  openscale: { billing: "allocated" },
671
687
  runloop: { billing: "allocated" },
688
+ runcloud: { billing: "allocated" },
672
689
  sprites: { billing: "active-cpu" },
673
690
  sail: { billing: "active-cpu" },
674
691
  superserve: {
@@ -0,0 +1,103 @@
1
+ import type { Router } from "./router.js";
2
+ import type { ProviderId } from "./types.js";
3
+ /**
4
+ * Image boot benchmark: start a sandbox straight from a public registry image reference, with no template,
5
+ * snapshot or rebuild step in between, and time it.
6
+ *
7
+ * The first start includes the provider pulling and preparing the image, and happens once per image and
8
+ * account, so it is one observation. The repeat starts come after it. Every sandbox runs a command whose
9
+ * output must contain an expected text, so a provider that starts some other image is not counted.
10
+ */
11
+ export interface ImageVerify {
12
+ /** Run in every sandbox. */
13
+ command: string;
14
+ /** Its output must contain this, e.g. "Python 3.11". */
15
+ contains: string;
16
+ }
17
+ export interface ImageRow {
18
+ provider: string;
19
+ size: {
20
+ vcpu: number;
21
+ memoryGb: number;
22
+ };
23
+ /** Create time of the first start from this image, in ms. Missing when the first start failed. */
24
+ firstCreateMs?: number;
25
+ /** Create time of each later start that was verified, in ms. */
26
+ repeatCreateMs: number[];
27
+ medianRepeatCreateMs?: number;
28
+ /** Starts whose sandbox ran the verify command and printed the expected text. */
29
+ verified: number;
30
+ /** Starts that failed, or whose sandbox was not the image asked for. */
31
+ failures: number;
32
+ /** List price per hour at this size. */
33
+ hourlyUsd?: number;
34
+ }
35
+ /** A saved image boot report (results/, tool "sandboxrouter-image"). */
36
+ export interface ImageReport {
37
+ tool: "sandboxrouter-image";
38
+ version: string;
39
+ date: string;
40
+ label?: string;
41
+ by?: string;
42
+ /** The registry reference every provider was given. */
43
+ image: string;
44
+ verify: ImageVerify;
45
+ spec: {
46
+ vcpu: number;
47
+ memoryGb: number;
48
+ };
49
+ /** Starts after the first one. */
50
+ repeats: number;
51
+ node: string;
52
+ platform: string;
53
+ rows: ImageRow[];
54
+ }
55
+ export interface ImageBenchOptions {
56
+ router: Router;
57
+ providers: ProviderId[];
58
+ image: string;
59
+ verify: ImageVerify;
60
+ spec: {
61
+ vcpu: number;
62
+ memoryGb: number;
63
+ };
64
+ repeats?: number;
65
+ /** Seconds to wait for one create. The first start of a large image can take minutes. */
66
+ createTimeoutSeconds?: number;
67
+ onProgress?: (message: string) => void;
68
+ }
69
+ /** One provider at a time per image, providers in parallel. */
70
+ export declare function imageBench(opts: ImageBenchOptions): Promise<ImageRow[]>;
71
+ export declare function loadImageReports(dir: string): ImageReport[];
72
+ /**
73
+ * For the website: one table per image, each provider's latest run of that image. Only providers whose every
74
+ * start was verified get a row with times; fastest repeat start first.
75
+ */
76
+ export declare function imageTable(reports: ImageReport[]): {
77
+ image: string;
78
+ spec: {
79
+ vcpu: number;
80
+ memoryGb: number;
81
+ };
82
+ repeats: number;
83
+ rows: {
84
+ provider: string;
85
+ size: {
86
+ vcpu: number;
87
+ memoryGb: number;
88
+ };
89
+ /** Create time of the first start from this image, in ms. Missing when the first start failed. */
90
+ firstCreateMs?: number;
91
+ /** Create time of each later start that was verified, in ms. */
92
+ repeatCreateMs: number[];
93
+ medianRepeatCreateMs?: number;
94
+ /** Starts whose sandbox ran the verify command and printed the expected text. */
95
+ verified: number;
96
+ /** Starts that failed, or whose sandbox was not the image asked for. */
97
+ failures: number;
98
+ /** List price per hour at this size. */
99
+ hourlyUsd?: number;
100
+ name: string;
101
+ measuredAt: string;
102
+ }[];
103
+ }[];
@@ -0,0 +1,110 @@
1
+ import { readdirSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { benchmarksPublishable, CATALOG } from "./catalog.js";
4
+ import { median } from "./bench-store.js";
5
+ /** One provider at a time per image, providers in parallel. */
6
+ export async function imageBench(opts) {
7
+ const repeats = opts.repeats ?? 3;
8
+ const timeout = opts.createTimeoutSeconds ?? 900;
9
+ const start = async (provider) => {
10
+ let sbx;
11
+ try {
12
+ const t0 = Date.now();
13
+ sbx = await opts.router.create({ ...opts.spec, timeoutMinutes: 15, image: { [provider]: opts.image } }, { provider, fallback: false, createTimeoutSeconds: timeout, deadlineSeconds: timeout });
14
+ const createMs = Date.now() - t0;
15
+ const r = await sbx.exec(opts.verify.command, { timeoutSeconds: 60 });
16
+ if (!`${r.stdout}${r.stderr}`.includes(opts.verify.contains))
17
+ return { error: "the sandbox is not the image asked for" };
18
+ return { createMs, size: sbx.size };
19
+ }
20
+ catch (e) {
21
+ return { error: e.message.replace(/\s+/g, " ").slice(0, 200) };
22
+ }
23
+ finally {
24
+ await sbx?.kill().catch(() => { });
25
+ }
26
+ };
27
+ return Promise.all(opts.providers.map(async (provider) => {
28
+ const first = await start(provider);
29
+ opts.onProgress?.(`${provider}: first start ${first.error ?? `${first.createMs} ms`}`);
30
+ const later = [];
31
+ if (!first.error) {
32
+ for (let i = 0; i < repeats; i++) {
33
+ const r = await start(provider);
34
+ later.push(r);
35
+ opts.onProgress?.(`${provider}: repeat start ${r.error ?? `${r.createMs} ms`}`);
36
+ }
37
+ }
38
+ const ok = later.filter((r) => r.createMs !== undefined).map((r) => r.createMs);
39
+ let hourlyUsd;
40
+ try {
41
+ const plan = await opts.router.plan({ ...opts.spec, image: { [provider]: opts.image } }, { provider, fallback: false });
42
+ hourlyUsd = plan[0]?.listHourlyUsd;
43
+ }
44
+ catch {
45
+ /* no price: the row still stands */
46
+ }
47
+ return {
48
+ provider,
49
+ size: first.size ?? opts.spec,
50
+ ...(first.createMs !== undefined ? { firstCreateMs: first.createMs } : {}),
51
+ repeatCreateMs: ok,
52
+ ...(ok.length ? { medianRepeatCreateMs: median(ok) } : {}),
53
+ verified: (first.error ? 0 : 1) + ok.length,
54
+ failures: (first.error ? 1 : 0) + later.length - ok.length,
55
+ ...(hourlyUsd !== undefined ? { hourlyUsd } : {}),
56
+ };
57
+ }));
58
+ }
59
+ export function loadImageReports(dir) {
60
+ let files;
61
+ try {
62
+ files = readdirSync(dir).filter((f) => f.endsWith(".json"));
63
+ }
64
+ catch {
65
+ return [];
66
+ }
67
+ const out = [];
68
+ for (const f of files.sort()) {
69
+ try {
70
+ const r = JSON.parse(readFileSync(join(dir, f), "utf8"));
71
+ if (r?.tool === "sandboxrouter-image" && Array.isArray(r.rows))
72
+ out.push(r);
73
+ }
74
+ catch {
75
+ /* skip unreadable files */
76
+ }
77
+ }
78
+ return out;
79
+ }
80
+ const KNOWN = new Set(CATALOG.map((c) => c.id));
81
+ /**
82
+ * For the website: one table per image, each provider's latest run of that image. Only providers whose every
83
+ * start was verified get a row with times; fastest repeat start first.
84
+ */
85
+ export function imageTable(reports) {
86
+ const images = new Map();
87
+ for (const rep of reports) {
88
+ const entry = images.get(rep.image) ?? { spec: rep.spec, repeats: rep.repeats, latest: new Map() };
89
+ images.set(rep.image, entry);
90
+ for (const r of rep.rows) {
91
+ if (!KNOWN.has(r.provider) || !benchmarksPublishable(r.provider))
92
+ continue;
93
+ const seen = entry.latest.get(r.provider);
94
+ if (!seen || rep.date > seen.date)
95
+ entry.latest.set(r.provider, { row: r, date: rep.date });
96
+ }
97
+ }
98
+ return [...images.entries()]
99
+ .map(([image, { spec, repeats, latest }]) => ({
100
+ image,
101
+ spec,
102
+ repeats,
103
+ rows: [...latest.values()]
104
+ .filter(({ row }) => row.failures === 0 && row.medianRepeatCreateMs !== undefined && row.firstCreateMs !== undefined)
105
+ .map(({ row, date }) => ({ ...row, name: CATALOG.find((c) => c.id === row.provider).name, measuredAt: date }))
106
+ .sort((a, b) => a.medianRepeatCreateMs - b.medianRepeatCreateMs),
107
+ }))
108
+ .filter((t) => t.rows.length)
109
+ .sort((a, b) => a.image.localeCompare(b.image));
110
+ }
package/dist/index.d.ts CHANGED
@@ -45,6 +45,7 @@ export { DenoProvider } from "./providers/deno.js";
45
45
  export { FreestyleProvider } from "./providers/freestyle.js";
46
46
  export { KoyebProvider } from "./providers/koyeb.js";
47
47
  export { DedalusProvider } from "./providers/dedalus.js";
48
+ export { RunCloudProvider } from "./providers/runcloud.js";
48
49
  export { OpenScaleProvider } from "./providers/openscale.js";
49
50
  export { SuperserveProvider } from "./providers/superserve.js";
50
51
  export { SailProvider } from "./providers/sail.js";
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ export { DenoProvider } from "./providers/deno.js";
45
45
  export { FreestyleProvider } from "./providers/freestyle.js";
46
46
  export { KoyebProvider } from "./providers/koyeb.js";
47
47
  export { DedalusProvider } from "./providers/dedalus.js";
48
+ export { RunCloudProvider } from "./providers/runcloud.js";
48
49
  export { OpenScaleProvider } from "./providers/openscale.js";
49
50
  export { SuperserveProvider } from "./providers/superserve.js";
50
51
  export { SailProvider } from "./providers/sail.js";
@@ -1,6 +1,8 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { ProviderError } from "../types.js";
3
3
  import { DEFAULT_EXEC_TIMEOUT_S, errorStatus, optionalImport, timeoutError, toBytes, wrapCommand } from "../util.js";
4
+ /** Seconds the Daytona SDK waits for a sandbox started from an image (its default, 60, is too short for a first pull). */
5
+ const IMAGE_CREATE_TIMEOUT_S = 600;
4
6
  /**
5
7
  * Daytona via `@daytonaio/sdk`. Default snapshot; set image.daytona to start from an image.
6
8
  *
@@ -49,7 +51,10 @@ export class DaytonaProvider {
49
51
  ...base,
50
52
  image: spec.image.daytona,
51
53
  resources: { cpu: spec.vcpu, memory: spec.memoryGb },
52
- })
54
+ },
55
+ // Daytona pulls and prepares an image the first time it sees it: about a minute for a 1 GB
56
+ // image, against the SDK's 60 s default. The router's createTimeoutSeconds is the real limit.
57
+ { timeout: IMAGE_CREATE_TIMEOUT_S })
53
58
  : await d.create(base);
54
59
  return new DaytonaBox(sbx);
55
60
  }
@@ -7,7 +7,8 @@ const DEFAULT_IMAGE = "ubuntu:22.04";
7
7
  const MIN_EXPIRY_SECONDS = 300;
8
8
  const MAX_EXPIRY_SECONDS = 604_800;
9
9
  const READY_TIMEOUT_MS = 5 * 60_000;
10
- const DELETE_TIMEOUT_MS = 60_000;
10
+ /** A deleted service takes about 62 s to disappear (measured, any size or image), so 60 s reported every kill as failed. */
11
+ const DELETE_TIMEOUT_MS = 180_000;
11
12
  /**
12
13
  * Northflank sandboxes via `@northflank/js-client`. Auth: NORTHFLANK_API_TOKEN plus
13
14
  * NORTHFLANK_PROJECT_ID (the project every sandbox is created in; its region is fixed at
@@ -0,0 +1,15 @@
1
+ import { type Provider, type ProviderSandbox, type SandboxSpec } from "../types.js";
2
+ export declare class RunCloudProvider implements Provider {
3
+ private apiKey;
4
+ private baseUrl;
5
+ readonly id: "runcloud";
6
+ constructor(apiKey?: string | undefined, baseUrl?: string);
7
+ configured(): boolean;
8
+ /** @internal */
9
+ api<T>(method: string, path: string, json?: unknown, timeoutMs?: number): Promise<{
10
+ status: number;
11
+ body: T;
12
+ }>;
13
+ create(spec: SandboxSpec): Promise<ProviderSandbox>;
14
+ connect(nativeId: string): Promise<ProviderSandbox>;
15
+ }
@@ -0,0 +1,230 @@
1
+ import { ProviderError } from "../types.js";
2
+ import { DEFAULT_EXEC_TIMEOUT_S, killedByTimeout, timeoutError, toBytes } from "../util.js";
3
+ /**
4
+ * Run Cloud Linux sandboxes over plain REST. Firecracker microVMs, billed per second on the reserved
5
+ * CPU and memory; CPU and memory used above the reservation bill at the same rates.
6
+ *
7
+ * https://api.run.cloud, Authorization: Bearer <RUN_CLOUD_API_KEY>:
8
+ * POST /run-cloud/sandboxes {image, cpu, memory, timeoutSeconds, onTimeout, tags, wait:false}
9
+ * -> {id, state, last_error, ...} cpu is vCPUs, memory MiB
10
+ * GET /run-cloud/sandboxes/:id -> {id, state, last_error, ...}
11
+ * POST /run-cloud/sandboxes/:id/exec {cmd:[argv], cwd, env, timeout_seconds}
12
+ * -> {exit_code, stdout, stderr}; a command past its timeout has its
13
+ * whole process group killed (exit_code -1)
14
+ * POST /run-cloud/sandboxes/:id/fs {op:"read", path, offset, length}
15
+ * -> {content (base64), eof, next_offset, size} or {error}
16
+ * POST /run-cloud/sandboxes/:id/fs {op:"write", path, offset, content (base64), truncate}
17
+ * -> {next_offset} or {error}; parent directories are created
18
+ * POST /run-cloud/sandboxes/:id/pause, POST /run-cloud/sandboxes/:id/resume {wait:false}
19
+ * (202 while the sandbox moves to a host with room; repeat until running)
20
+ * POST /run-cloud/sandboxes/:id/tunnels {port} -> {url, expiresAt, ...}
21
+ * DELETE /run-cloud/sandboxes/:id
22
+ * States: pending, starting, building_image (first start from a new image), running, paused, stopped,
23
+ * archived, interrupted, destroying, destroyed. The API boots in the background and ends a boot that has
24
+ * not finished after 10 minutes. Live output streams only over a WebSocket (/exec/stream), which needs an
25
+ * Authorization header that Node's built-in WebSocket cannot send, so this adapter uses the buffered /exec.
26
+ * Docs: https://docs.run.cloud/sandboxes, https://docs.run.cloud/sandboxes/run-sandbox
27
+ */
28
+ const ID = "runcloud";
29
+ const DEFAULT_IMAGE = "runcloud/agent-base";
30
+ const START_TIMEOUT_MS = 10 * 60_000;
31
+ const POLL_MS = 500;
32
+ /** The guest's own file chunk size. */
33
+ const FILE_CHUNK = 512 * 1024;
34
+ const STARTING = new Set(["pending", "starting", "building_image"]);
35
+ const RESUMABLE = new Set(["paused", "stopped", "archived"]);
36
+ const GONE = new Set(["destroying", "destroyed"]);
37
+ export class RunCloudProvider {
38
+ apiKey;
39
+ baseUrl;
40
+ id = ID;
41
+ constructor(apiKey = process.env.RUN_CLOUD_API_KEY, baseUrl = (process.env.RUN_CLOUD_API_URL ?? "https://api.run.cloud").replace(/\/+$/, "")) {
42
+ this.apiKey = apiKey;
43
+ this.baseUrl = baseUrl;
44
+ }
45
+ configured() {
46
+ return !!this.apiKey;
47
+ }
48
+ /** @internal */
49
+ async api(method, path, json, timeoutMs = 60_000) {
50
+ if (!this.apiKey)
51
+ throw new ProviderError(ID, "RUN_CLOUD_API_KEY is not set");
52
+ const res = await fetch(`${this.baseUrl}${path}`, {
53
+ method,
54
+ headers: { Authorization: `Bearer ${this.apiKey}`, ...(json !== undefined ? { "Content-Type": "application/json" } : {}) },
55
+ body: json !== undefined ? JSON.stringify(json) : undefined,
56
+ signal: AbortSignal.timeout(timeoutMs),
57
+ });
58
+ const text = await res.text();
59
+ if (!res.ok) {
60
+ let detail = text.slice(0, 300);
61
+ try {
62
+ const j = JSON.parse(text);
63
+ const msg = j?.detail ?? j?.message ?? j?.error;
64
+ if (typeof msg === "string")
65
+ detail = j?.code ? `${j.code}: ${msg}` : msg;
66
+ }
67
+ catch {
68
+ /* plain-text body */
69
+ }
70
+ throw new ProviderError(ID, `${method} ${path.split("?")[0]} -> ${res.status} ${detail}`, res.status);
71
+ }
72
+ return { status: res.status, body: (text ? JSON.parse(text) : {}) };
73
+ }
74
+ async create(spec) {
75
+ const { body } = await this.api("POST", "/run-cloud/sandboxes", {
76
+ image: spec.image?.runcloud ?? DEFAULT_IMAGE,
77
+ cpu: spec.vcpu ?? 2,
78
+ memory: Math.round((spec.memoryGb ?? 4) * 1024),
79
+ // A hard lifetime: destroy at the end instead of parking a resumable snapshot.
80
+ timeoutSeconds: Math.max(60, Math.round((spec.timeoutMinutes ?? 30) * 60)),
81
+ onTimeout: "destroy",
82
+ ...(spec.metadata && Object.keys(spec.metadata).length ? { tags: spec.metadata } : {}),
83
+ wait: false,
84
+ });
85
+ if (!body.id)
86
+ throw new ProviderError(ID, "create returned no sandbox id");
87
+ const box = new RunCloudBox(this, body.id, spec.env ?? {});
88
+ try {
89
+ await box.waitRunning(false);
90
+ }
91
+ catch (err) {
92
+ await box.kill().catch(() => { });
93
+ throw err;
94
+ }
95
+ return box;
96
+ }
97
+ async connect(nativeId) {
98
+ const box = new RunCloudBox(this, nativeId, {});
99
+ await box.waitRunning(true);
100
+ return box;
101
+ }
102
+ }
103
+ class RunCloudBox {
104
+ p;
105
+ nativeId;
106
+ env;
107
+ tunnels = new Map();
108
+ constructor(p, nativeId, env) {
109
+ this.p = p;
110
+ this.nativeId = nativeId;
111
+ this.env = env;
112
+ }
113
+ get path() {
114
+ return `/run-cloud/sandboxes/${encodeURIComponent(this.nativeId)}`;
115
+ }
116
+ /** Poll until the sandbox runs; with `resume`, wake a paused or stopped one on the way. */
117
+ async waitRunning(resume) {
118
+ const deadline = Date.now() + START_TIMEOUT_MS;
119
+ for (;;) {
120
+ const { body: s } = await this.p.api("GET", this.path);
121
+ const state = s.state ?? "";
122
+ if (state === "running")
123
+ return;
124
+ if (GONE.has(state))
125
+ throw new ProviderError(ID, `sandbox ${this.nativeId} is ${state}`, 404);
126
+ if (resume && RESUMABLE.has(state)) {
127
+ await this.p.api("POST", `${this.path}/resume`, { wait: false });
128
+ }
129
+ else if (!STARTING.has(state)) {
130
+ const why = s.last_error ?? "";
131
+ // No room on the fleet: a capacity error, so the router tries the next provider.
132
+ const status = /no host with capacity/i.test(why) ? 409 : 502;
133
+ throw new ProviderError(ID, `sandbox ${this.nativeId} is ${state || "in an unknown state"}${why ? `: ${why}` : ""}`, status);
134
+ }
135
+ if (Date.now() > deadline)
136
+ throw new ProviderError(ID, `sandbox ${this.nativeId} not running after ${START_TIMEOUT_MS / 1000}s (${state})`, 504);
137
+ await sleep(POLL_MS);
138
+ }
139
+ }
140
+ async exec(cmd, opts = {}) {
141
+ const secs = opts.timeoutSeconds ?? DEFAULT_EXEC_TIMEOUT_S;
142
+ const env = { ...this.env, ...opts.env };
143
+ const t0 = Date.now();
144
+ let r;
145
+ try {
146
+ ({ body: r } = await this.p.api("POST", `${this.path}/exec`, {
147
+ cmd: ["/bin/sh", "-c", cmd],
148
+ ...(opts.cwd ? { cwd: opts.cwd } : {}),
149
+ ...(Object.keys(env).length ? { env } : {}),
150
+ timeout_seconds: secs,
151
+ },
152
+ // The guest kills the command at `secs`; this only bounds a request that never answers.
153
+ secs * 1000 + 30_000));
154
+ }
155
+ catch (err) {
156
+ if (err?.name === "TimeoutError")
157
+ throw timeoutError(ID, secs);
158
+ throw err;
159
+ }
160
+ const durationMs = Date.now() - t0;
161
+ if (typeof r.exit_code !== "number")
162
+ throw new ProviderError(ID, "exec returned no exit code");
163
+ if (killedByTimeout(r.exit_code, durationMs, secs))
164
+ throw timeoutError(ID, secs);
165
+ const stdout = r.stdout ?? "";
166
+ const stderr = r.stderr ?? "";
167
+ if (stdout)
168
+ opts.onStdout?.(stdout);
169
+ if (stderr)
170
+ opts.onStderr?.(stderr);
171
+ return { exitCode: r.exit_code, stdout, stderr, durationMs };
172
+ }
173
+ async fs(req) {
174
+ const { body } = await this.p.api("POST", `${this.path}/fs`, req, 120_000);
175
+ if (body.error) {
176
+ const missing = /no such file|not found|ENOENT/i.test(body.error);
177
+ throw new ProviderError(ID, `${req.op} ${req.path}: ${body.error}`, missing ? 404 : undefined);
178
+ }
179
+ return body;
180
+ }
181
+ async writeFile(path, content) {
182
+ const bytes = toBytes(content);
183
+ for (let offset = 0; offset === 0 || offset < bytes.byteLength; offset += FILE_CHUNK) {
184
+ const chunk = bytes.subarray(offset, offset + FILE_CHUNK);
185
+ const r = await this.fs({ op: "write", path, offset, content: Buffer.from(chunk).toString("base64"), truncate: offset === 0 });
186
+ if (chunk.byteLength > 0 && r.next_offset !== offset + chunk.byteLength) {
187
+ throw new ProviderError(ID, `write ${path}: chunk at ${offset} was not acknowledged`);
188
+ }
189
+ }
190
+ }
191
+ async readFile(path) {
192
+ const parts = [];
193
+ for (let offset = 0;;) {
194
+ const r = await this.fs({ op: "read", path, offset, length: FILE_CHUNK });
195
+ const chunk = Buffer.from(r.content ?? "", "base64");
196
+ parts.push(chunk);
197
+ offset += chunk.byteLength;
198
+ if (r.eof || chunk.byteLength === 0 || (r.size !== undefined && offset >= r.size))
199
+ break;
200
+ }
201
+ return new Uint8Array(Buffer.concat(parts));
202
+ }
203
+ /** A public tunnel to the port. Tunnels expire, so a new one is opened once the last is near its end. */
204
+ async url(port) {
205
+ const cached = this.tunnels.get(port);
206
+ if (cached && cached.expiresAt - Date.now() > 60_000)
207
+ return cached.url;
208
+ const { body } = await this.p.api("POST", `${this.path}/tunnels`, { port });
209
+ if (!body.url)
210
+ throw new ProviderError(ID, `tunnel for port ${port} returned no url`);
211
+ const expiresAt = body.expiresAt ? Date.parse(body.expiresAt) : NaN;
212
+ this.tunnels.set(port, { url: body.url, expiresAt: Number.isNaN(expiresAt) ? 0 : expiresAt });
213
+ return body.url;
214
+ }
215
+ async pause() {
216
+ await this.p.api("POST", `${this.path}/pause`, {});
217
+ }
218
+ async kill() {
219
+ try {
220
+ await this.p.api("DELETE", this.path);
221
+ }
222
+ catch (err) {
223
+ if (err.status !== 404)
224
+ throw err;
225
+ }
226
+ }
227
+ }
228
+ function sleep(ms) {
229
+ return new Promise((r) => setTimeout(r, ms));
230
+ }
package/dist/published.js CHANGED
@@ -44,12 +44,12 @@ export const PUBLISHED = {
44
44
  "name": "Novita AI Agent Sandbox",
45
45
  "size": {
46
46
  "vcpu": 2,
47
- "memoryGb": 4
47
+ "memoryGb": 1
48
48
  },
49
49
  "medianCreateMs": 298,
50
50
  "successRate": 1,
51
51
  "runs": 100,
52
- "hourlyUsd": 0.11664,
52
+ "hourlyUsd": 0.08208,
53
53
  "measuredAt": "2026-11-17T16:19:15.367Z"
54
54
  },
55
55
  "sprites": {
@@ -1813,7 +1813,7 @@ export const PUBLISHED = {
1813
1813
  "limited": 0,
1814
1814
  "size": {
1815
1815
  "vcpu": 2,
1816
- "memoryGb": 4
1816
+ "memoryGb": 1
1817
1817
  },
1818
1818
  "p50Ms": 1655,
1819
1819
  "p99Ms": 3157,
@@ -2048,7 +2048,7 @@ export const PUBLISHED = {
2048
2048
  "limited": 0,
2049
2049
  "size": {
2050
2050
  "vcpu": 2,
2051
- "memoryGb": 4
2051
+ "memoryGb": 1
2052
2052
  },
2053
2053
  "p50Ms": 2079,
2054
2054
  "p99Ms": 2671,
package/dist/results.js CHANGED
@@ -53,6 +53,8 @@ const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}
53
53
  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
54
  /** "12 Main Street", "Calle Mayor 5", "Apt 4B": a street or a flat, which a label never needs. */
55
55
  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;
56
+ /** A registry image reference: optional host, path, then a tag or digest. No "user:password@". */
57
+ 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
58
  const isNum = (n, min = 0, max = Infinity) => typeof n === "number" && Number.isFinite(n) && n >= min && n <= max;
57
59
  const isCount = (n, max) => Number.isInteger(n) && isNum(n, 0, max);
58
60
  const isSize = (size) => isNum(size?.vcpu, 0.1, 1024) && isNum(size?.memoryGb, 0.0625, 4096);
@@ -372,6 +374,52 @@ export function validateResult(j, now = Date.now()) {
372
374
  out.push(`${e?.provider}: command output and deletion must be verified`);
373
375
  }
374
376
  }
377
+ else if (j.tool === "sandboxrouter-image") {
378
+ add(checkDate(j.date, now));
379
+ add(checkLabel(j.label));
380
+ add(checkBy(j.by));
381
+ // A public reference only: no credentials in it, and nothing that is not a registry path.
382
+ if (typeof j.image !== "string" || !IMAGE_REF.test(j.image))
383
+ out.push("image must be a public registry reference, e.g. python:3.11-bookworm");
384
+ if (typeof j.verify?.command !== "string" || !j.verify.command || typeof j.verify?.contains !== "string" || !j.verify.contains) {
385
+ out.push("verify needs the command run in every sandbox and the text its output must contain");
386
+ }
387
+ if (!isSize(j.spec))
388
+ out.push("spec must record the requested size");
389
+ if (!isNum(j.repeats, 3, 100) || !Number.isInteger(j.repeats))
390
+ out.push("repeats must be at least 3");
391
+ if (!Array.isArray(j.rows) || !j.rows.length)
392
+ out.push("rows is empty");
393
+ for (const r of Array.isArray(j.rows) ? j.rows : []) {
394
+ provider(r?.provider, "row provider");
395
+ if (noBench(r?.provider))
396
+ out.push(`${r.provider}: ${NO_BENCH}`);
397
+ if (!isSize(r?.size))
398
+ out.push(`${r?.provider}: invalid sandbox size`);
399
+ const repeat = Array.isArray(r?.repeatCreateMs) ? r.repeatCreateMs : undefined;
400
+ if (!repeat || repeat.length > j.repeats || repeat.some((ms) => !isNum(ms, 1, MAX_MS))) {
401
+ out.push(`${r?.provider}: repeatCreateMs must list at most ${j.repeats} times, each between 1 ms and 15 min`);
402
+ continue;
403
+ }
404
+ if (r.firstCreateMs !== undefined && !isNum(r.firstCreateMs, 1, MAX_MS))
405
+ out.push(`${r.provider}: firstCreateMs must be between 1 ms and 15 min`);
406
+ if (r.firstCreateMs === undefined && repeat.length)
407
+ out.push(`${r.provider}: repeat starts without a first start`);
408
+ const starts = (r.firstCreateMs === undefined ? 0 : 1) + repeat.length;
409
+ if (!isCount(r.verified, 1 + j.repeats) || !isCount(r.failures, 1 + j.repeats) || r.verified !== starts || r.verified + r.failures > 1 + j.repeats) {
410
+ out.push(`${r.provider}: verified must count the timed starts, and verified plus failures cannot exceed the starts made`);
411
+ }
412
+ const sorted = [...repeat].sort((a, b) => a - b);
413
+ const mid = Math.floor(sorted.length / 2);
414
+ const expected = !sorted.length ? undefined : sorted.length % 2 ? sorted[mid] : Math.round((sorted[mid - 1] + sorted[mid]) / 2);
415
+ if (r.medianRepeatCreateMs !== expected)
416
+ out.push(`${r.provider}: medianRepeatCreateMs must be the median of repeatCreateMs`);
417
+ if (r.hourlyUsd !== undefined && !isNum(r.hourlyUsd, 0, 1000))
418
+ out.push(`${r.provider}: hourlyUsd is out of range`);
419
+ if ("error" in r || "lastError" in r)
420
+ out.push(`${r.provider}: errors must not be shared (they can hold account details)`);
421
+ }
422
+ }
375
423
  else {
376
424
  out.push(`unknown tool "${String(j.tool)}": expected a benchmark report, saved check, cost run or hosted ledger check`);
377
425
  }
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/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.17.0",
3
+ "version": "0.18.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.230.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.73.2",
187
+ "@limrun/api": "^0.74.0",
188
188
  "@mobilerun/sdk": "^6.1.0",
189
- "@northflank/js-client": "^0.12.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",