@sandboxrouter/sdk 0.13.0 → 0.14.1

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.
Files changed (46) hide show
  1. package/README.md +9 -7
  2. package/dist/billing.js +0 -1
  3. package/dist/catalog.d.ts +29 -2
  4. package/dist/catalog.js +73 -15
  5. package/dist/cli.js +3 -1
  6. package/dist/client.d.ts +6 -1
  7. package/dist/client.js +19 -0
  8. package/dist/cost.d.ts +44 -5
  9. package/dist/cost.js +54 -24
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +2 -0
  12. package/dist/providers/beam.js +5 -4
  13. package/dist/providers/blaxel.d.ts +1 -0
  14. package/dist/providers/blaxel.js +56 -1
  15. package/dist/providers/daytona.js +33 -1
  16. package/dist/providers/deno.d.ts +3 -0
  17. package/dist/providers/deno.js +14 -0
  18. package/dist/providers/digitalocean.d.ts +16 -0
  19. package/dist/providers/digitalocean.js +174 -0
  20. package/dist/providers/docker.d.ts +1 -0
  21. package/dist/providers/docker.js +17 -0
  22. package/dist/providers/e2b.d.ts +22 -1
  23. package/dist/providers/e2b.js +50 -3
  24. package/dist/providers/google.d.ts +23 -0
  25. package/dist/providers/google.js +206 -0
  26. package/dist/providers/hopx.js +12 -0
  27. package/dist/providers/modal.js +7 -0
  28. package/dist/providers/morph.js +3 -2
  29. package/dist/providers/northflank.js +20 -3
  30. package/dist/providers/novita.js +5 -5
  31. package/dist/providers/sail.js +4 -4
  32. package/dist/providers/shell-files.d.ts +12 -0
  33. package/dist/providers/shell-files.js +52 -0
  34. package/dist/providers/vercel.js +39 -1
  35. package/dist/published.js +957 -2
  36. package/dist/results.d.ts +2 -2
  37. package/dist/results.js +62 -1
  38. package/dist/router.d.ts +8 -5
  39. package/dist/router.js +49 -6
  40. package/dist/server.d.ts +4 -1
  41. package/dist/server.js +101 -7
  42. package/dist/types.d.ts +18 -3
  43. package/dist/validate.d.ts +4 -2
  44. package/dist/validate.js +18 -1
  45. package/dist/verified.js +4 -0
  46. package/package.json +5 -1
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, E2B, exe.dev, Fly.io Sprites, Freestyle, 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, 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
 
@@ -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`, `exec` (streamed), `writeFile`, `readFile`, `pause`, `kill`. Switch providers by changing which keys are set.
38
- - **The provider's own SDK is still there.** `sbx.native` is the provider's own sandbox object (an E2B `Sandbox`, a Daytona `Sandbox`, a Modal `Sandbox`, ...), already connected, for ports, background processes, snapshots and anything else the router doesn't cover. See [Using a provider's own features](https://sandboxrouter.ai/docs#native).
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).
@@ -52,12 +52,13 @@ List price while running, 2 vCPU / 4 GB, cheapest first; waitlisted sign-ups fol
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
54
  | [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
- | [Northflank](https://sandboxrouter.ai/providers/northflank) | $0.067 | none | not run yet | [pricing](https://northflank.com/pricing) |
56
- | [Morph Cloud](https://sandboxrouter.ai/providers/morph) | $0.100 | none | not run yet | [pricing](https://cloud.morph.so/web/pricing) |
55
+ | [Northflank](https://sandboxrouter.ai/providers/northflank) | $0.067 | none | passed (2026-11-18) | [pricing](https://northflank.com/pricing) |
56
+ | [Morph Cloud](https://sandboxrouter.ai/providers/morph) | $0.100 | none | passed (2026-11-18) | [pricing](https://cloud.morph.so/web/pricing) |
57
57
  | [exe.dev](https://sandboxrouter.ai/providers/exedev) | $0.105 | $15/mo | not run yet | [pricing](https://exe.dev/docs/standalone-vms.md) |
58
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
+ | [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/) |
59
60
  | [Freestyle](https://sandboxrouter.ai/providers/freestyle) | $0.134 | none | passed (2026-11-13) | [pricing](https://www.freestyle.sh/docs/vms/pricing-and-limits) |
60
- | [Beam](https://sandboxrouter.ai/providers/beam) | $0.140 | $20/mo (credited) | not run yet | [pricing](https://www.beam.cloud/pricing) |
61
+ | [Beam](https://sandboxrouter.ai/providers/beam) | $0.140 | $20/mo (credited) | passed (2026-11-18) | [pricing](https://www.beam.cloud/pricing) |
61
62
  | [CodeSandbox SDK (Together)](https://sandboxrouter.ai/providers/codesandbox) | $0.149 | none | not run yet | [pricing](https://docs.together.ai/docs/together-code-sandbox-legacy) |
62
63
  | [Fly.io Sprites](https://sandboxrouter.ai/providers/sprites) | up to $0.164 | none | passed (2026-11-13) | [pricing](https://fly.io/sprites) |
63
64
  | [Blaxel](https://sandboxrouter.ai/providers/blaxel) | $0.166 | none | passed (2026-11-13) | [pricing](https://blaxel.ai/pricing) |
@@ -80,10 +81,11 @@ List price while running, 2 vCPU / 4 GB, cheapest first; waitlisted sign-ups fol
80
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) |
81
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) |
82
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
+ | [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) |
83
85
  | [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) |
84
86
  | [Docker (local)](https://sandboxrouter.ai/providers/docker) | free | none | passed (2026-11-13) | [pricing](https://docs.docker.com/engine/) |
85
87
 
86
- Checked 2026-11-04 to 2026-11-17.
88
+ Checked 2026-11-04 to 2026-11-18.
87
89
 
88
90
  ## Install
89
91
 
package/dist/billing.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export const BILLED_VS_LIST = {
2
2
  agent37: { ratio: 0.998, date: "2026-11-14" },
3
- sail: { ratio: 0.495, date: "2026-11-06" },
4
3
  };
package/dist/catalog.d.ts CHANGED
@@ -49,16 +49,18 @@ export interface ProviderInfo {
49
49
  limits: {
50
50
  maxVcpu: number;
51
51
  maxMemoryGb: number;
52
+ maxPorts?: number;
53
+ reservedPorts?: number[];
52
54
  };
53
55
  /**
54
56
  * The size every sandbox gets unless a custom image (template, snapshot) is passed, whatever
55
- * vcpu/memoryGb ask for. Measured inside real sandboxes (nproc, MemTotal). The router skips the
57
+ * vcpu/memoryGb ask for. Use the documented stock template size or a measurement from a live sandbox. The router skips the
56
58
  * provider for requests bigger than this and prices it at this size.
57
59
  */
58
60
  defaultSize?: {
59
61
  vcpu: number;
60
62
  memoryGb: number;
61
- measured: string;
63
+ measured?: string;
62
64
  };
63
65
  /** Runs on your own machine (Docker). Never chosen automatically; name it to use it. */
64
66
  local?: boolean;
@@ -117,6 +119,31 @@ export declare function planLabel(id: ProviderId): string;
117
119
  * you have keys for, so a gated provider only gets work if you already have an account there.
118
120
  */
119
121
  export declare function listingOrder(spec?: SandboxSpec): ProviderInfo[];
122
+ export declare function digitalOceanSize(vcpu: number, memoryGb: number): {
123
+ readonly slug: "mars-1vcpu-1gb";
124
+ readonly vcpu: 1;
125
+ readonly memoryGb: 1;
126
+ } | {
127
+ readonly slug: "mars-2vcpu-2gb";
128
+ readonly vcpu: 2;
129
+ readonly memoryGb: 2;
130
+ } | {
131
+ readonly slug: "mars-2vcpu-4gb";
132
+ readonly vcpu: 2;
133
+ readonly memoryGb: 4;
134
+ } | {
135
+ readonly slug: "mars-4vcpu-8gb";
136
+ readonly vcpu: 4;
137
+ readonly memoryGb: 8;
138
+ } | {
139
+ readonly slug: "mars-16vcpu-32gb";
140
+ readonly vcpu: 16;
141
+ readonly memoryGb: 32;
142
+ } | undefined;
143
+ export declare const GOOGLE_SHELL_SIZE: {
144
+ readonly vcpu: 1;
145
+ readonly memoryGb: 2;
146
+ };
120
147
  export declare const CATALOG: ProviderInfo[];
121
148
  /** Cloudflare only rents fixed instance types: https://developers.cloudflare.com/containers/platform/limits/ */
122
149
  export declare const CLOUDFLARE_INSTANCES: readonly [{
package/dist/catalog.js CHANGED
@@ -34,7 +34,50 @@ export function listingOrder(spec = { vcpu: DEFAULT_VCPU, memoryGb: DEFAULT_MEMO
34
34
  * size (or by your measured cold starts), ties broken alphabetically. Nobody gets a better slot.
35
35
  * Prices come from each provider's public pricing page; PRs that correct one are welcome.
36
36
  */
37
+ /** Sellable Harness Runtime microVM shapes. Use the same allocation for pricing and create. */
38
+ const DIGITALOCEAN_SIZES = [
39
+ { slug: "mars-1vcpu-1gb", vcpu: 1, memoryGb: 1 },
40
+ { slug: "mars-2vcpu-2gb", vcpu: 2, memoryGb: 2 },
41
+ { slug: "mars-2vcpu-4gb", vcpu: 2, memoryGb: 4 },
42
+ { slug: "mars-4vcpu-8gb", vcpu: 4, memoryGb: 8 },
43
+ { slug: "mars-16vcpu-32gb", vcpu: 16, memoryGb: 32 },
44
+ ];
45
+ export function digitalOceanSize(vcpu, memoryGb) {
46
+ return DIGITALOCEAN_SIZES.find((size) => size.vcpu >= vcpu && size.memoryGb >= memoryGb);
47
+ }
48
+ export const GOOGLE_SHELL_SIZE = { vcpu: 1, memoryGb: 2 };
37
49
  const ENTRIES = [
50
+ {
51
+ id: "digitalocean",
52
+ name: "DigitalOcean Harness Runtime",
53
+ pricing: {
54
+ vcpuHour: 0.044,
55
+ gbHour: 0.0095,
56
+ source: "https://docs.digitalocean.com/products/managed-agents/agent-harness-runtime/details/pricing/",
57
+ checked: "2026-11-18",
58
+ note: "Actual CPU and allocated memory, per second; storage and outbound traffic separate. Positive Harness Runtime balance required.",
59
+ },
60
+ capabilities: ["pause"],
61
+ limits: { maxVcpu: 16, maxMemoryGb: 32 },
62
+ credentials: [["DIGITALOCEAN_TOKEN"], ["DIGITALOCEAN_ACCESS_TOKEN"]],
63
+ docs: "https://docs.digitalocean.com/products/managed-agents/agent-harness-runtime/how-to/run-sandbox/",
64
+ },
65
+ {
66
+ id: "google",
67
+ name: "Google Cloud Agent Platform",
68
+ pricing: {
69
+ vcpuHour: 0.085,
70
+ gbHour: 0.009,
71
+ source: "https://cloud.google.com/products/gemini-enterprise-agent-platform/pricing",
72
+ checked: "2026-11-18",
73
+ note: "Standard shell template estimate for 1 vCPU / 2 GiB. Allocated Agent Compute and Agent Memory, per second; storage separate.",
74
+ },
75
+ capabilities: ["pause"],
76
+ limits: { maxVcpu: GOOGLE_SHELL_SIZE.vcpu, maxMemoryGb: GOOGLE_SHELL_SIZE.memoryGb },
77
+ defaultSize: GOOGLE_SHELL_SIZE,
78
+ credentials: [["GOOGLE_SANDBOX_ENGINE", "GOOGLE_SANDBOX_TEMPLATE"]],
79
+ docs: "https://docs.cloud.google.com/gemini-enterprise-agent-platform/scale/sandbox/shell-sandbox-quickstart",
80
+ },
38
81
  {
39
82
  id: "docker",
40
83
  name: "Docker (local)",
@@ -45,7 +88,7 @@ const ENTRIES = [
45
88
  source: "https://docs.docker.com/engine/",
46
89
  checked: "2026-11-04",
47
90
  },
48
- capabilities: ["pause", "custom-image"],
91
+ capabilities: ["pause", "custom-image", "ports"],
49
92
  limits: { maxVcpu: 64, maxMemoryGb: 256 },
50
93
  local: true,
51
94
  credentials: [],
@@ -76,7 +119,7 @@ const ENTRIES = [
76
119
  source: "https://e2b.dev/pricing",
77
120
  checked: "2026-11-04",
78
121
  },
79
- capabilities: ["pause", "custom-image"],
122
+ capabilities: ["pause", "custom-image", "ports", "background"],
80
123
  limits: { maxVcpu: 8, maxMemoryGb: 8 },
81
124
  // The default template; a bigger size needs a template built with --cpu-count / --memory-mb.
82
125
  defaultSize: { vcpu: 2, memoryGb: 0.5, measured: "2026-11-06" },
@@ -93,7 +136,7 @@ const ENTRIES = [
93
136
  source: "https://www.daytona.io/pricing",
94
137
  checked: "2026-11-17",
95
138
  },
96
- capabilities: ["pause", "custom-image"],
139
+ capabilities: ["pause", "custom-image", "ports", "background"],
97
140
  limits: { maxVcpu: 4, maxMemoryGb: 8 },
98
141
  // The default snapshot; resources only apply when creating from an image (image.daytona).
99
142
  defaultSize: { vcpu: 1, memoryGb: 1, measured: "2026-11-06" },
@@ -112,7 +155,7 @@ const ENTRIES = [
112
155
  source: "https://modal.com/pricing",
113
156
  checked: "2026-11-17",
114
157
  },
115
- capabilities: ["gpu", "custom-image"],
158
+ capabilities: ["gpu", "custom-image", "ports"],
116
159
  limits: { maxVcpu: 64, maxMemoryGb: 256 },
117
160
  credentials: [["MODAL_TOKEN_ID", "MODAL_TOKEN_SECRET"]],
118
161
  docs: "https://modal.com/docs/guide/sandbox",
@@ -130,8 +173,8 @@ const ENTRIES = [
130
173
  source: "https://vercel.com/docs/vercel-sandbox/pricing",
131
174
  checked: "2026-11-05",
132
175
  },
133
- capabilities: [],
134
- limits: { maxVcpu: 8, maxMemoryGb: 16 },
176
+ capabilities: ["ports", "background"],
177
+ limits: { maxVcpu: 8, maxMemoryGb: 16, maxPorts: 15 },
135
178
  credentials: [["VERCEL_OIDC_TOKEN"], ["VERCEL_TOKEN", "VERCEL_TEAM_ID", "VERCEL_PROJECT_ID"]],
136
179
  docs: "https://vercel.com/docs/vercel-sandbox",
137
180
  },
@@ -176,9 +219,9 @@ const ENTRIES = [
176
219
  source: "https://blaxel.ai/pricing",
177
220
  checked: "2026-11-04",
178
221
  },
179
- capabilities: ["custom-image"],
222
+ capabilities: ["custom-image", "ports", "background"],
180
223
  // Self-serve caps are per-tier and not published; these are conservative.
181
- limits: { maxVcpu: 8, maxMemoryGb: 16 },
224
+ limits: { maxVcpu: 8, maxMemoryGb: 16, reservedPorts: [80, 443, 8080] },
182
225
  credentials: [["BL_API_KEY", "BL_WORKSPACE"]],
183
226
  docs: "https://docs.blaxel.ai/Sandboxes/Overview",
184
227
  noBenchmarks: {
@@ -274,9 +317,9 @@ ENTRIES.push({
274
317
  source: "https://hopx.ai/pricing",
275
318
  checked: "2026-11-04",
276
319
  },
277
- capabilities: ["pause", "custom-image"],
320
+ capabilities: ["pause", "custom-image", "ports"],
278
321
  // HOPX takes no size at create; capped at the default size so bigger requests go elsewhere.
279
- limits: { maxVcpu: 2, maxMemoryGb: 4 },
322
+ limits: { maxVcpu: 2, maxMemoryGb: 4, reservedPorts: [7777] },
280
323
  credentials: [["HOPX_API_KEY"]],
281
324
  docs: "https://docs.hopx.ai",
282
325
  }, {
@@ -480,7 +523,7 @@ ENTRIES.push({
480
523
  source: "https://deno.com/sandbox",
481
524
  checked: "2026-11-17",
482
525
  },
483
- capabilities: ["custom-image"],
526
+ capabilities: ["custom-image", "ports"],
484
527
  limits: { maxVcpu: 2, maxMemoryGb: 4 },
485
528
  credentials: [["DENO_DEPLOY_TOKEN"]],
486
529
  docs: "https://docs.deno.com/sandbox/",
@@ -562,7 +605,7 @@ ENTRIES.push({
562
605
  source: "https://docs.novita.ai/guides/sandbox-pricing",
563
606
  checked: "2026-11-04",
564
607
  },
565
- capabilities: ["pause", "custom-image"],
608
+ capabilities: ["pause", "custom-image", "ports", "background"],
566
609
  limits: { maxVcpu: 8, maxMemoryGb: 8 },
567
610
  credentials: [["NOVITA_API_KEY"]],
568
611
  docs: "https://docs.novita.ai/guides/sandbox-overview",
@@ -588,6 +631,8 @@ ENTRIES.push({
588
631
  */
589
632
  const P = "2026-11-06";
590
633
  const BILLING = {
634
+ digitalocean: { billing: "active-cpu" },
635
+ google: { billing: "allocated" },
591
636
  docker: { billing: "allocated" },
592
637
  agent37: { billing: "allocated" },
593
638
  agentcore: { billing: "active-cpu" },
@@ -732,6 +777,10 @@ function fullHourlyCost(id, spec = {}) {
732
777
  const size = vercelSandboxSize(spec);
733
778
  return size.vcpu * pricing.vcpuHour + size.memoryGb * pricing.gbHour;
734
779
  }
780
+ if (id === "digitalocean") {
781
+ const shape = digitalOceanSize(vcpu, mem) ?? DIGITALOCEAN_SIZES[DIGITALOCEAN_SIZES.length - 1];
782
+ return shape.vcpu * pricing.vcpuHour + shape.memoryGb * pricing.gbHour;
783
+ }
735
784
  // Blaxel sizes by memory, about 2 GB per core.
736
785
  if (id === "blaxel")
737
786
  mem = Math.max(mem, vcpu * 2);
@@ -813,6 +862,8 @@ export function cpuHourlyAtFull(id, spec = {}) {
813
862
  return vercelSandboxSize(spec).vcpu * p.pricing.vcpuHour;
814
863
  if (id === "cloudflare")
815
864
  return cloudflareInstance(vcpu, mem).vcpu * p.pricing.vcpuHour;
865
+ if (id === "digitalocean")
866
+ return (digitalOceanSize(vcpu, mem)?.vcpu ?? p.limits.maxVcpu) * p.pricing.vcpuHour;
816
867
  if (id === "upstash")
817
868
  return fullHourlyCost(id, spec);
818
869
  if (id === "deno")
@@ -829,16 +880,23 @@ export function unfit(id, spec, require = []) {
829
880
  const needs = new Set(require);
830
881
  if (spec.gpu)
831
882
  needs.add("gpu");
883
+ if (spec.ports?.length)
884
+ needs.add("ports");
832
885
  for (const c of needs)
833
886
  if (!p.capabilities.includes(c))
834
887
  return `no ${c} support`;
835
- if ((spec.vcpu ?? DEFAULT_VCPU) > p.limits.maxVcpu)
888
+ if (spec.ports?.length && p.limits.maxPorts !== undefined && spec.ports.length > p.limits.maxPorts)
889
+ return `max ${p.limits.maxPorts} preview ports`;
890
+ const reserved = spec.ports?.find((port) => p.limits.reservedPorts?.includes(port));
891
+ if (reserved !== undefined)
892
+ return `port ${reserved} is reserved by the provider`;
893
+ const fixed = fixedSize(id, spec);
894
+ if ((spec.vcpu ?? fixed?.vcpu ?? DEFAULT_VCPU) > p.limits.maxVcpu)
836
895
  return `max ${p.limits.maxVcpu} vCPU`;
837
- if ((spec.memoryGb ?? DEFAULT_MEMORY_GB) > p.limits.maxMemoryGb)
896
+ if ((spec.memoryGb ?? fixed?.memoryGb ?? DEFAULT_MEMORY_GB) > p.limits.maxMemoryGb)
838
897
  return `max ${p.limits.maxMemoryGb} GB memory`;
839
898
  // A default image's size is fixed. With no size asked for you get that size, so only a size you
840
899
  // name can be too big for it.
841
- const fixed = fixedSize(id, spec);
842
900
  if (fixed && ((spec.vcpu ?? 0) > fixed.vcpu || (spec.memoryGb ?? 0) > fixed.memoryGb))
843
901
  return `default image is ${fixed.vcpu} vCPU / ${fixed.memoryGb} GB; a bigger size needs image.${id}`;
844
902
  return null;
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
- /** What the provider says it charged for this sandbox, USD. Undefined when it can't be read. */
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 per provider, from the saved cost runs in `dir` (default results/cost): the latest
79
- * entry whose bill is precise enough to compare. A bill rounded to whole cents only counts when the
80
- * prediction is at least $1, so rounding can't move the ratio by more than 1%. Providers whose terms
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 [cpus, mem] = (await box.exec(PROBE)).stdout.trim().split(/\s+/).map(Number);
38
- if (cpus > 0 && mem > 0) {
39
- entry.delivered = { vcpu: cpus, memoryMb: mem };
40
- entry.deliveredUsdHour = round(hourlyCost(provider, { vcpu: cpus, memoryGb: mem / 1024 }));
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
- if (load)
43
- await box.exec(LOAD);
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(`${r.status} ${(await r.text()).slice(0, 200)}`);
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
- return { usd: round(row.totalPrice), seconds, source: "daytona analytics /usage/sandbox totalPrice" };
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
- return { usd: round(row.summary?.cost ?? 0), source: "blaxel /metrics cost (USD)" };
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
- const cents = days.reduce((n, d) => n + (d.cents ?? 0), 0);
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((row.cost_usd_nanos ?? 0) / 1e9),
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((row.total_micros ?? 0) / 1e6),
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) => (n === undefined ? "n/a" : n < 0.01 ? `$${n.toFixed(5)}` : `$${n.toFixed(4)}`);
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) | Billed | Billed ÷ predicted | Source |",
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 ? `${((e.bill.usd / e.predictedUsd) * 100).toFixed(0)}%` : "n/a";
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 per provider, from the saved cost runs in `dir` (default results/cost): the latest
185
- * entry whose bill is precise enough to compare. A bill rounded to whole cents only counts when the
186
- * prediction is at least $1, so rounding can't move the ratio by more than 1%. Providers whose terms
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 (!usd || !predicted || usd <= 0 || predicted <= 0 || !benchmarksPublishable(e.provider))
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
- if (/integer cents/i.test(e.bill.source) && predicted < 1)
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);