@sandboxrouter/sdk 0.14.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.
- package/README.md +7 -5
- package/dist/catalog.d.ts +27 -2
- package/dist/catalog.js +54 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/providers/beam.js +5 -4
- package/dist/providers/digitalocean.d.ts +16 -0
- package/dist/providers/digitalocean.js +174 -0
- package/dist/providers/google.d.ts +23 -0
- package/dist/providers/google.js +206 -0
- package/dist/providers/morph.js +3 -2
- package/dist/providers/northflank.js +20 -3
- package/dist/providers/shell-files.d.ts +12 -0
- package/dist/providers/shell-files.js +52 -0
- package/dist/router.js +10 -1
- package/dist/types.d.ts +2 -2
- package/dist/verified.js +4 -0
- 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
|
|
|
@@ -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 |
|
|
56
|
-
| [Morph Cloud](https://sandboxrouter.ai/providers/morph) | $0.100 | none |
|
|
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) |
|
|
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-
|
|
88
|
+
Checked 2026-11-04 to 2026-11-18.
|
|
87
89
|
|
|
88
90
|
## Install
|
|
89
91
|
|
package/dist/catalog.d.ts
CHANGED
|
@@ -54,13 +54,13 @@ export interface ProviderInfo {
|
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
56
|
* The size every sandbox gets unless a custom image (template, snapshot) is passed, whatever
|
|
57
|
-
* vcpu/memoryGb ask for.
|
|
57
|
+
* vcpu/memoryGb ask for. Use the documented stock template size or a measurement from a live sandbox. The router skips the
|
|
58
58
|
* provider for requests bigger than this and prices it at this size.
|
|
59
59
|
*/
|
|
60
60
|
defaultSize?: {
|
|
61
61
|
vcpu: number;
|
|
62
62
|
memoryGb: number;
|
|
63
|
-
measured
|
|
63
|
+
measured?: string;
|
|
64
64
|
};
|
|
65
65
|
/** Runs on your own machine (Docker). Never chosen automatically; name it to use it. */
|
|
66
66
|
local?: boolean;
|
|
@@ -119,6 +119,31 @@ export declare function planLabel(id: ProviderId): string;
|
|
|
119
119
|
* you have keys for, so a gated provider only gets work if you already have an account there.
|
|
120
120
|
*/
|
|
121
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
|
+
};
|
|
122
147
|
export declare const CATALOG: ProviderInfo[];
|
|
123
148
|
/** Cloudflare only rents fixed instance types: https://developers.cloudflare.com/containers/platform/limits/ */
|
|
124
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)",
|
|
@@ -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")
|
|
@@ -839,13 +890,13 @@ export function unfit(id, spec, require = []) {
|
|
|
839
890
|
const reserved = spec.ports?.find((port) => p.limits.reservedPorts?.includes(port));
|
|
840
891
|
if (reserved !== undefined)
|
|
841
892
|
return `port ${reserved} is reserved by the provider`;
|
|
842
|
-
|
|
893
|
+
const fixed = fixedSize(id, spec);
|
|
894
|
+
if ((spec.vcpu ?? fixed?.vcpu ?? DEFAULT_VCPU) > p.limits.maxVcpu)
|
|
843
895
|
return `max ${p.limits.maxVcpu} vCPU`;
|
|
844
|
-
if ((spec.memoryGb ?? DEFAULT_MEMORY_GB) > p.limits.maxMemoryGb)
|
|
896
|
+
if ((spec.memoryGb ?? fixed?.memoryGb ?? DEFAULT_MEMORY_GB) > p.limits.maxMemoryGb)
|
|
845
897
|
return `max ${p.limits.maxMemoryGb} GB memory`;
|
|
846
898
|
// A default image's size is fixed. With no size asked for you get that size, so only a size you
|
|
847
899
|
// name can be too big for it.
|
|
848
|
-
const fixed = fixedSize(id, spec);
|
|
849
900
|
if (fixed && ((spec.vcpu ?? 0) > fixed.vcpu || (spec.memoryGb ?? 0) > fixed.memoryGb))
|
|
850
901
|
return `default image is ${fixed.vcpu} vCPU / ${fixed.memoryGb} GB; a bigger size needs image.${id}`;
|
|
851
902
|
return null;
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export { NorthflankProvider } from "./providers/northflank.js";
|
|
|
33
33
|
export { BoatProvider } from "./providers/boat.js";
|
|
34
34
|
export { ExeDevProvider } from "./providers/exedev.js";
|
|
35
35
|
export { AgentCoreProvider } from "./providers/agentcore.js";
|
|
36
|
+
export { DigitalOceanProvider } from "./providers/digitalocean.js";
|
|
37
|
+
export { GoogleAgentPlatformProvider } from "./providers/google.js";
|
|
36
38
|
export { AzureSessionsProvider } from "./providers/azure.js";
|
|
37
39
|
export { LambdaMicrovmProvider, writeLambdaMicrovmBundle } from "./providers/lambda.js";
|
|
38
40
|
export { AlibabaProvider } from "./providers/alibaba.js";
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,8 @@ export { NorthflankProvider } from "./providers/northflank.js";
|
|
|
33
33
|
export { BoatProvider } from "./providers/boat.js";
|
|
34
34
|
export { ExeDevProvider } from "./providers/exedev.js";
|
|
35
35
|
export { AgentCoreProvider } from "./providers/agentcore.js";
|
|
36
|
+
export { DigitalOceanProvider } from "./providers/digitalocean.js";
|
|
37
|
+
export { GoogleAgentPlatformProvider } from "./providers/google.js";
|
|
36
38
|
export { AzureSessionsProvider } from "./providers/azure.js";
|
|
37
39
|
export { LambdaMicrovmProvider, writeLambdaMicrovmBundle } from "./providers/lambda.js";
|
|
38
40
|
export { AlibabaProvider } from "./providers/alibaba.js";
|
package/dist/providers/beam.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { DEFAULT_MEMORY_GB, DEFAULT_VCPU } from "../catalog.js";
|
|
2
2
|
import { ProviderError } from "../types.js";
|
|
3
|
-
import { DEFAULT_EXEC_TIMEOUT_S, dirname, optionalImport,
|
|
3
|
+
import { DEFAULT_EXEC_TIMEOUT_S, dirname, optionalImport, timeoutError, toBytes } from "../util.js";
|
|
4
4
|
/**
|
|
5
5
|
* Beam (beam.cloud) sandboxes via the official `@beamcloud/beam-js` SDK (checked against 1.1.6).
|
|
6
6
|
* Auth: BEAM_TOKEN and BEAM_WORKSPACE_ID (the TS SDK refuses requests without the workspace id).
|
|
7
7
|
* new Sandbox({ name, cpu, memory: MiB, gpu?, image?, keepWarmSeconds, env }).create()
|
|
8
8
|
* -> SandboxInstance (containerId is the sandbox id)
|
|
9
9
|
* Sandbox.connect(id) reattach by id
|
|
10
|
-
* instance.
|
|
10
|
+
* instance.exec(argv, { cwd, env, wait }) start a process; .wait() -> exit code,
|
|
11
11
|
* .stdout / .stderr are polled streams (async-iterable by line, or .read() for all so far)
|
|
12
12
|
* instance.fs.writeBytes(path, buf) / fs.readBytes(path)
|
|
13
13
|
* instance.terminate()
|
|
@@ -115,7 +115,8 @@ class BeamBox {
|
|
|
115
115
|
try {
|
|
116
116
|
// Never `wait: true`: that call returns only when the command exits, so the deadline below
|
|
117
117
|
// could not start until it was already too late to enforce.
|
|
118
|
-
|
|
118
|
+
// Beam's gateway treats execShell input like argv on some accounts.
|
|
119
|
+
proc = await this.sb.exec(["sh", "-c", cmd], { cwd: opts.cwd, env, wait: false });
|
|
119
120
|
}
|
|
120
121
|
catch (err) {
|
|
121
122
|
throw fail(err, "exec");
|
|
@@ -155,7 +156,7 @@ class BeamBox {
|
|
|
155
156
|
catch {
|
|
156
157
|
// Most likely a missing parent directory: create it and try once more.
|
|
157
158
|
try {
|
|
158
|
-
const p = await this.sb.
|
|
159
|
+
const p = await this.sb.exec(["mkdir", "-p", "--", dirname(path)], { wait: true });
|
|
159
160
|
await p.wait();
|
|
160
161
|
await this.sb.fs.writeBytes(path, buf);
|
|
161
162
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Provider, type ProviderSandbox, type SandboxSpec } from "../types.js";
|
|
2
|
+
export declare class DigitalOceanProvider implements Provider {
|
|
3
|
+
private token;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
readonly id: "digitalocean";
|
|
6
|
+
constructor(token?: string | undefined, baseUrl?: string);
|
|
7
|
+
configured(): boolean;
|
|
8
|
+
/** @internal */
|
|
9
|
+
request<T>(method: string, path: string, body?: unknown, timeoutMs?: number): Promise<T>;
|
|
10
|
+
create(spec: SandboxSpec): Promise<ProviderSandbox>;
|
|
11
|
+
connect(nativeId: string): Promise<ProviderSandbox>;
|
|
12
|
+
/** @internal */
|
|
13
|
+
remove(path: string): Promise<void>;
|
|
14
|
+
private getSession;
|
|
15
|
+
private waitReady;
|
|
16
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { digitalOceanSize, DEFAULT_MEMORY_GB, DEFAULT_VCPU } from "../catalog.js";
|
|
3
|
+
import { ProviderError } from "../types.js";
|
|
4
|
+
import { DEFAULT_EXEC_TIMEOUT_S, killedByTimeout, timeoutError, wrapCommand } from "../util.js";
|
|
5
|
+
import { ShellFiles } from "./shell-files.js";
|
|
6
|
+
/**
|
|
7
|
+
* DigitalOcean Harness Runtime. Start a harness-free microVM from an Environment Config,
|
|
8
|
+
* then use its session API to execute commands, pause, resume and delete. The temporary
|
|
9
|
+
* config is soft-deleted after the session is created. The service exposes an idle pause
|
|
10
|
+
* timeout rather than a wall-clock deletion deadline.
|
|
11
|
+
* https://docs.digitalocean.com/products/managed-agents/agent-harness-runtime/how-to/run-sandbox/
|
|
12
|
+
* https://docs.digitalocean.com/reference/api/reference/harness-runtime/
|
|
13
|
+
*/
|
|
14
|
+
const ID = "digitalocean";
|
|
15
|
+
const API = "/v2/harness-runtime";
|
|
16
|
+
const BOOT_TIMEOUT_MS = 110_000;
|
|
17
|
+
const MAX_EXEC_SECONDS = 240;
|
|
18
|
+
function statusOf(session) {
|
|
19
|
+
return session.status?.replace(/^SESSION_STATUS_/, "");
|
|
20
|
+
}
|
|
21
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
22
|
+
export class DigitalOceanProvider {
|
|
23
|
+
token;
|
|
24
|
+
baseUrl;
|
|
25
|
+
id = ID;
|
|
26
|
+
constructor(token = process.env.DIGITALOCEAN_TOKEN || process.env.DIGITALOCEAN_ACCESS_TOKEN, baseUrl = process.env.DIGITALOCEAN_HARNESS_URL ?? "https://api.digitalocean.com") {
|
|
27
|
+
this.token = token;
|
|
28
|
+
this.baseUrl = baseUrl;
|
|
29
|
+
}
|
|
30
|
+
configured() {
|
|
31
|
+
return !!this.token;
|
|
32
|
+
}
|
|
33
|
+
/** @internal */
|
|
34
|
+
async request(method, path, body, timeoutMs = 30_000) {
|
|
35
|
+
if (!this.token)
|
|
36
|
+
throw new ProviderError(ID, "DIGITALOCEAN_TOKEN is not set");
|
|
37
|
+
const response = await fetch(`${this.baseUrl.replace(/\/$/, "")}${API}${path}`, {
|
|
38
|
+
method,
|
|
39
|
+
headers: {
|
|
40
|
+
Authorization: `Bearer ${this.token}`,
|
|
41
|
+
Accept: "application/json",
|
|
42
|
+
...(body === undefined ? {} : { "Content-Type": "application/json" }),
|
|
43
|
+
},
|
|
44
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
45
|
+
redirect: "error",
|
|
46
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
47
|
+
});
|
|
48
|
+
const text = await response.text();
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
let detail = text.slice(0, 280);
|
|
51
|
+
try {
|
|
52
|
+
detail = JSON.parse(text).message ?? detail;
|
|
53
|
+
}
|
|
54
|
+
catch { /* non-JSON error */ }
|
|
55
|
+
throw new ProviderError(ID, `${method} ${path}: HTTP ${response.status} ${detail}`, response.status);
|
|
56
|
+
}
|
|
57
|
+
return (text ? JSON.parse(text) : {});
|
|
58
|
+
}
|
|
59
|
+
async create(spec) {
|
|
60
|
+
const size = digitalOceanSize(spec.vcpu ?? DEFAULT_VCPU, spec.memoryGb ?? DEFAULT_MEMORY_GB);
|
|
61
|
+
if (!size)
|
|
62
|
+
throw new ProviderError(ID, "no Harness Runtime size can satisfy the requested vCPU and memory");
|
|
63
|
+
const name = `sbr-${randomBytes(8).toString("hex")}`;
|
|
64
|
+
// Keep the caller's env out of the durable config.
|
|
65
|
+
const idleSeconds = Math.max(60, Math.ceil((spec.timeoutMinutes ?? 30) * 60));
|
|
66
|
+
const manifest = [`name: ${name}`, "harness: none", `size: ${size.slug}`, `idle_timeout: ${idleSeconds}s`].join("\n");
|
|
67
|
+
const { config } = await this.request("POST", "/configs", {
|
|
68
|
+
name,
|
|
69
|
+
manifest_yaml: manifest,
|
|
70
|
+
});
|
|
71
|
+
if (!config?.id)
|
|
72
|
+
throw new ProviderError(ID, "create config returned no config id");
|
|
73
|
+
const configPath = `/configs/${encodeURIComponent(config.id)}`;
|
|
74
|
+
let session;
|
|
75
|
+
try {
|
|
76
|
+
const result = await this.request("POST", "/sessions", { name, config_id: config.id });
|
|
77
|
+
session = result.session;
|
|
78
|
+
if (!session?.session_id)
|
|
79
|
+
throw new ProviderError(ID, "create session returned no session id");
|
|
80
|
+
await this.waitReady(session);
|
|
81
|
+
await this.remove(configPath);
|
|
82
|
+
return new DigitalOceanBox(this, session.session_id, spec.env);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
if (session?.session_id)
|
|
86
|
+
await this.remove(sessionPath(session.session_id)).catch(() => { });
|
|
87
|
+
await this.remove(configPath).catch(() => { });
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async connect(nativeId) {
|
|
92
|
+
const path = sessionPath(nativeId);
|
|
93
|
+
const session = await this.getSession(path);
|
|
94
|
+
if (statusOf(session) === "PAUSED")
|
|
95
|
+
await this.request("POST", `${path}/resume`, undefined, BOOT_TIMEOUT_MS);
|
|
96
|
+
await this.waitReady(statusOf(session) === "PAUSED" ? await this.getSession(path) : session);
|
|
97
|
+
return new DigitalOceanBox(this, nativeId);
|
|
98
|
+
}
|
|
99
|
+
/** @internal */
|
|
100
|
+
async remove(path) {
|
|
101
|
+
try {
|
|
102
|
+
await this.request("DELETE", path);
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
if (!(err instanceof ProviderError) || err.status !== 404)
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async getSession(path) {
|
|
110
|
+
const { session } = await this.request("GET", path);
|
|
111
|
+
if (!session?.session_id)
|
|
112
|
+
throw new ProviderError(ID, "session missing", 404);
|
|
113
|
+
return session;
|
|
114
|
+
}
|
|
115
|
+
async waitReady(session) {
|
|
116
|
+
const path = sessionPath(session.session_id);
|
|
117
|
+
const until = Date.now() + BOOT_TIMEOUT_MS;
|
|
118
|
+
while (Date.now() < until) {
|
|
119
|
+
const status = statusOf(session);
|
|
120
|
+
if (status === "READY")
|
|
121
|
+
return;
|
|
122
|
+
if (status === "FAILED" || status === "DESTROYED" || status === "PAUSED") {
|
|
123
|
+
throw new ProviderError(ID, `session is ${status.toLowerCase()}`, status === "DESTROYED" ? 404 : undefined);
|
|
124
|
+
}
|
|
125
|
+
await delay(500);
|
|
126
|
+
session = await this.getSession(path);
|
|
127
|
+
}
|
|
128
|
+
throw new ProviderError(ID, "session did not become ready", 504);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function sessionPath(id) {
|
|
132
|
+
return `/sessions/${encodeURIComponent(id)}`;
|
|
133
|
+
}
|
|
134
|
+
class DigitalOceanBox {
|
|
135
|
+
provider;
|
|
136
|
+
nativeId;
|
|
137
|
+
env;
|
|
138
|
+
files = new ShellFiles(ID, (command) => this.exec(command));
|
|
139
|
+
constructor(provider, nativeId, env) {
|
|
140
|
+
this.provider = provider;
|
|
141
|
+
this.nativeId = nativeId;
|
|
142
|
+
this.env = env;
|
|
143
|
+
}
|
|
144
|
+
async exec(command, opts = {}) {
|
|
145
|
+
const t0 = Date.now();
|
|
146
|
+
const seconds = Math.min(MAX_EXEC_SECONDS, Math.max(1, Math.ceil(opts.timeoutSeconds ?? DEFAULT_EXEC_TIMEOUT_S)));
|
|
147
|
+
const path = `${sessionPath(this.nativeId)}/sandbox/exec`;
|
|
148
|
+
const cmd = wrapCommand(command, { env: { ...this.env, ...opts.env } });
|
|
149
|
+
const result = await this.provider.request("POST", path, {
|
|
150
|
+
argv: ["sh", "-c", cmd],
|
|
151
|
+
workdir: opts.cwd,
|
|
152
|
+
timeout_seconds: seconds,
|
|
153
|
+
}, (seconds + 15) * 1000);
|
|
154
|
+
const { exit_code, stdout = "", stderr = "" } = result;
|
|
155
|
+
if (typeof exit_code !== "number" || !Number.isInteger(exit_code))
|
|
156
|
+
throw new ProviderError(ID, "exec returned no exit code");
|
|
157
|
+
const durationMs = result.duration_ms ?? Date.now() - t0;
|
|
158
|
+
if (killedByTimeout(exit_code, durationMs, seconds))
|
|
159
|
+
throw timeoutError(ID, seconds);
|
|
160
|
+
if (stdout)
|
|
161
|
+
opts.onStdout?.(stdout);
|
|
162
|
+
if (stderr)
|
|
163
|
+
opts.onStderr?.(stderr);
|
|
164
|
+
return { stdout, stderr, exitCode: exit_code, durationMs };
|
|
165
|
+
}
|
|
166
|
+
readFile(path) { return this.files.readFile(path); }
|
|
167
|
+
writeFile(path, data) { return this.files.writeFile(path, data); }
|
|
168
|
+
async pause() {
|
|
169
|
+
await this.provider.request("POST", `${sessionPath(this.nativeId)}/pause`, undefined, BOOT_TIMEOUT_MS);
|
|
170
|
+
}
|
|
171
|
+
async kill() {
|
|
172
|
+
await this.provider.remove(sessionPath(this.nativeId));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Provider, type ProviderSandbox, type SandboxSpec } from "../types.js";
|
|
2
|
+
export declare class GoogleAgentPlatformProvider implements Provider {
|
|
3
|
+
private engine;
|
|
4
|
+
private template;
|
|
5
|
+
private token;
|
|
6
|
+
private baseUrl?;
|
|
7
|
+
readonly id: "google";
|
|
8
|
+
private auth?;
|
|
9
|
+
constructor(engine?: string | undefined, template?: string | undefined, token?: string | undefined, baseUrl?: string | undefined);
|
|
10
|
+
configured(): boolean;
|
|
11
|
+
private engineName;
|
|
12
|
+
private headers;
|
|
13
|
+
/** @internal */
|
|
14
|
+
request<T>(method: string, resource: string, body?: unknown, timeoutMs?: number): Promise<T>;
|
|
15
|
+
private sandboxName;
|
|
16
|
+
create(spec: SandboxSpec): Promise<ProviderSandbox>;
|
|
17
|
+
connect(nativeId: string): Promise<ProviderSandbox>;
|
|
18
|
+
/** @internal */
|
|
19
|
+
action(name: string, action: "pause" | "resume"): Promise<void>;
|
|
20
|
+
/** @internal */
|
|
21
|
+
remove(name: string): Promise<void>;
|
|
22
|
+
private wait;
|
|
23
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { GOOGLE_SHELL_SIZE } from "../catalog.js";
|
|
3
|
+
import { ProviderError } from "../types.js";
|
|
4
|
+
import { DEFAULT_EXEC_TIMEOUT_S, killedByTimeout, optionalImport, timeoutError, wrapCommand } from "../util.js";
|
|
5
|
+
import { ShellFiles } from "./shell-files.js";
|
|
6
|
+
/**
|
|
7
|
+
* Gemini Enterprise Agent Platform shell sandboxes, using the Agent Platform regional REST API.
|
|
8
|
+
* Reuse a default shell template so that creating a sandbox does not leave behind a new template.
|
|
9
|
+
* The optional google-auth-library package supplies Application Default Credentials.
|
|
10
|
+
* https://docs.cloud.google.com/gemini-enterprise-agent-platform/scale/sandbox/shell-sandbox-quickstart
|
|
11
|
+
* https://docs.cloud.google.com/gemini-enterprise-agent-platform/scale/sandbox/manage-templates
|
|
12
|
+
* Wire reference: https://github.com/googleapis/python-aiplatform/blob/main/agentplatform/_genai/sandboxes.py
|
|
13
|
+
*/
|
|
14
|
+
const ID = "google";
|
|
15
|
+
const ENGINE_NAME = /^projects\/([\w-]+)\/locations\/([\w-]+)\/reasoningEngines\/[\w-]+$/;
|
|
16
|
+
const RESOURCE_NAME = /^(?:[\w-]+\/)*[\w-]+$/;
|
|
17
|
+
const OPERATION_TIMEOUT_MS = 110_000;
|
|
18
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
19
|
+
function dataChunk(mimeType, text) {
|
|
20
|
+
return { mimeType, data: Buffer.from(text).toString("base64") };
|
|
21
|
+
}
|
|
22
|
+
export class GoogleAgentPlatformProvider {
|
|
23
|
+
engine;
|
|
24
|
+
template;
|
|
25
|
+
token;
|
|
26
|
+
baseUrl;
|
|
27
|
+
id = ID;
|
|
28
|
+
auth;
|
|
29
|
+
constructor(engine = process.env.GOOGLE_SANDBOX_ENGINE, template = process.env.GOOGLE_SANDBOX_TEMPLATE, token = process.env.GOOGLE_SANDBOX_ACCESS_TOKEN, baseUrl) {
|
|
30
|
+
this.engine = engine;
|
|
31
|
+
this.template = template;
|
|
32
|
+
this.token = token;
|
|
33
|
+
this.baseUrl = baseUrl;
|
|
34
|
+
}
|
|
35
|
+
configured() {
|
|
36
|
+
return !!this.engine && !!this.template;
|
|
37
|
+
}
|
|
38
|
+
engineName() {
|
|
39
|
+
if (!this.engine || !ENGINE_NAME.test(this.engine) || !this.template || !RESOURCE_NAME.test(this.template)) {
|
|
40
|
+
throw new ProviderError(ID, "set GOOGLE_SANDBOX_ENGINE to projects/PROJECT/locations/LOCATION/reasoningEngines/ID and GOOGLE_SANDBOX_TEMPLATE to a shell template resource name");
|
|
41
|
+
}
|
|
42
|
+
return this.engine;
|
|
43
|
+
}
|
|
44
|
+
async headers(url) {
|
|
45
|
+
if (this.token)
|
|
46
|
+
return new Headers({ Authorization: `Bearer ${this.token}` });
|
|
47
|
+
this.auth ??= optionalImport("google-auth-library", ID).then(({ GoogleAuth }) => new GoogleAuth({ scopes: ["https://www.googleapis.com/auth/cloud-platform"] }));
|
|
48
|
+
return new Headers(await (await this.auth).getRequestHeaders(url));
|
|
49
|
+
}
|
|
50
|
+
/** @internal */
|
|
51
|
+
async request(method, resource, body, timeoutMs = 30_000) {
|
|
52
|
+
const engine = this.engineName();
|
|
53
|
+
const [, project, location] = ENGINE_NAME.exec(engine);
|
|
54
|
+
const prefix = `projects/${project}/locations/${location}/`;
|
|
55
|
+
// Limit both user-supplied IDs and returned operation names to this project and region.
|
|
56
|
+
if (!resource.startsWith(prefix) || !RESOURCE_NAME.test(resource.replace(/\/:(?:execute|pause|resume)$/, ""))) {
|
|
57
|
+
throw new ProviderError(ID, "resource is outside the configured Agent Platform location");
|
|
58
|
+
}
|
|
59
|
+
const host = this.baseUrl ?? `https://${location}-aiplatform.googleapis.com`;
|
|
60
|
+
const url = `${host.replace(/\/$/, "")}/v1beta1/${resource}`;
|
|
61
|
+
const headers = await this.headers(url);
|
|
62
|
+
headers.set("Accept", "application/json");
|
|
63
|
+
if (body !== undefined)
|
|
64
|
+
headers.set("Content-Type", "application/json");
|
|
65
|
+
const response = await fetch(url, {
|
|
66
|
+
method,
|
|
67
|
+
headers,
|
|
68
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
69
|
+
redirect: "error",
|
|
70
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
71
|
+
});
|
|
72
|
+
const text = await response.text();
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
let detail = text.slice(0, 280);
|
|
75
|
+
try {
|
|
76
|
+
detail = JSON.parse(text).error?.message ?? detail;
|
|
77
|
+
}
|
|
78
|
+
catch { /* non-JSON error */ }
|
|
79
|
+
throw new ProviderError(ID, `${method}: HTTP ${response.status} ${detail}`, response.status);
|
|
80
|
+
}
|
|
81
|
+
return (text ? JSON.parse(text) : {});
|
|
82
|
+
}
|
|
83
|
+
sandboxName(id) {
|
|
84
|
+
const parent = `${this.engineName()}/sandboxEnvironments/`;
|
|
85
|
+
if (!id.startsWith(parent) || !/^[\w-]+$/.test(id.slice(parent.length))) {
|
|
86
|
+
throw new ProviderError(ID, "invalid sandbox name for the configured Agent Platform instance", 404);
|
|
87
|
+
}
|
|
88
|
+
return id;
|
|
89
|
+
}
|
|
90
|
+
async create(spec) {
|
|
91
|
+
const engine = this.engineName();
|
|
92
|
+
if ((spec.vcpu ?? 0) > GOOGLE_SHELL_SIZE.vcpu || (spec.memoryGb ?? 0) > GOOGLE_SHELL_SIZE.memoryGb) {
|
|
93
|
+
throw new ProviderError(ID, "the standard shell sandbox is 1 vCPU / 2 GiB");
|
|
94
|
+
}
|
|
95
|
+
const { response } = await this.wait(await this.request("POST", `${engine}/sandboxEnvironments`, {
|
|
96
|
+
displayName: `sbr-${randomBytes(8).toString("hex")}`,
|
|
97
|
+
spec: { shellEnvironment: {} },
|
|
98
|
+
sandboxEnvironmentTemplate: this.template,
|
|
99
|
+
ttl: `${Math.max(60, Math.ceil((spec.timeoutMinutes ?? 30) * 60))}s`,
|
|
100
|
+
}));
|
|
101
|
+
if (!response?.name)
|
|
102
|
+
throw new ProviderError(ID, "create operation returned no sandbox name");
|
|
103
|
+
const name = this.sandboxName(response.name);
|
|
104
|
+
try {
|
|
105
|
+
const resource = await this.request("GET", name);
|
|
106
|
+
if (resource.state !== "STATE_RUNNING")
|
|
107
|
+
throw new ProviderError(ID, `sandbox is ${resource.state ?? "not running"}`);
|
|
108
|
+
return new GoogleBox(this, name, spec.env);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
await this.remove(name).catch(() => { });
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async connect(nativeId) {
|
|
116
|
+
const name = this.sandboxName(nativeId);
|
|
117
|
+
const sandbox = await this.request("GET", name);
|
|
118
|
+
if (sandbox.state === "STATE_PAUSED")
|
|
119
|
+
await this.action(name, "resume");
|
|
120
|
+
else if (sandbox.state !== "STATE_RUNNING")
|
|
121
|
+
throw new ProviderError(ID, `sandbox is ${sandbox.state ?? "not running"}`);
|
|
122
|
+
return new GoogleBox(this, name);
|
|
123
|
+
}
|
|
124
|
+
/** @internal */
|
|
125
|
+
async action(name, action) {
|
|
126
|
+
await this.wait(await this.request("POST", `${this.sandboxName(name)}/:${action}`, {}));
|
|
127
|
+
}
|
|
128
|
+
/** @internal */
|
|
129
|
+
async remove(name) {
|
|
130
|
+
try {
|
|
131
|
+
await this.wait(await this.request("DELETE", this.sandboxName(name)));
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
if (!(err instanceof ProviderError) || err.status !== 404)
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async wait(operation) {
|
|
139
|
+
// Some delete responses have an empty body.
|
|
140
|
+
const until = Date.now() + OPERATION_TIMEOUT_MS;
|
|
141
|
+
while (!operation.done && operation.name && Date.now() < until) {
|
|
142
|
+
await delay(500);
|
|
143
|
+
operation = await this.request("GET", operation.name);
|
|
144
|
+
}
|
|
145
|
+
if (operation.error) {
|
|
146
|
+
const status = { 5: 404, 7: 403, 8: 429, 16: 401 }[operation.error.code ?? 0];
|
|
147
|
+
throw new ProviderError(ID, operation.error.message ?? "sandbox operation failed", status);
|
|
148
|
+
}
|
|
149
|
+
if (operation.name && !operation.done)
|
|
150
|
+
throw new ProviderError(ID, "sandbox operation timed out", 504);
|
|
151
|
+
return operation;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
class GoogleBox {
|
|
155
|
+
provider;
|
|
156
|
+
nativeId;
|
|
157
|
+
env;
|
|
158
|
+
files = new ShellFiles(ID, (command) => this.exec(command));
|
|
159
|
+
constructor(provider, nativeId, env) {
|
|
160
|
+
this.provider = provider;
|
|
161
|
+
this.nativeId = nativeId;
|
|
162
|
+
this.env = env;
|
|
163
|
+
}
|
|
164
|
+
async exec(command, opts = {}) {
|
|
165
|
+
const t0 = Date.now();
|
|
166
|
+
const seconds = Math.max(1, Math.ceil(opts.timeoutSeconds ?? DEFAULT_EXEC_TIMEOUT_S));
|
|
167
|
+
const cmd = wrapCommand(command, { env: { ...this.env, ...opts.env } });
|
|
168
|
+
const inputs = [
|
|
169
|
+
dataChunk("application/x.sandbox-request-uri", "/exec"),
|
|
170
|
+
dataChunk("application/x.sandbox-request-port", "8080"),
|
|
171
|
+
dataChunk("application/json", JSON.stringify({ command: cmd, cwd: opts.cwd, timeout: seconds })),
|
|
172
|
+
];
|
|
173
|
+
let result;
|
|
174
|
+
try {
|
|
175
|
+
result = await this.provider.request("POST", `${this.nativeId}/:execute`, { inputs }, (seconds + 15) * 1000);
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
// Agent Platform wraps confirmed guest command kills in a 400 DEADLINE_EXCEEDED response.
|
|
179
|
+
if (err instanceof ProviderError &&
|
|
180
|
+
err.status === 400 &&
|
|
181
|
+
/\bDEADLINE_EXCEEDED\b/.test(err.message) &&
|
|
182
|
+
/\bcommand exceeded \d+(?:\.\d+)?s and was killed\b/i.test(err.message)) {
|
|
183
|
+
throw timeoutError(ID, seconds);
|
|
184
|
+
}
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
187
|
+
const out = result.outputs?.find((chunk) => chunk.data)?.data;
|
|
188
|
+
if (!out)
|
|
189
|
+
throw new ProviderError(ID, "shell sandbox returned no output");
|
|
190
|
+
const { returncode, stdout = "", stderr = "", duration_ms } = JSON.parse(Buffer.from(out, "base64").toString("utf8"));
|
|
191
|
+
if (typeof returncode !== "number" || !Number.isInteger(returncode))
|
|
192
|
+
throw new ProviderError(ID, "shell sandbox returned no exit code");
|
|
193
|
+
const durationMs = duration_ms ?? Date.now() - t0;
|
|
194
|
+
if (killedByTimeout(returncode, durationMs, seconds))
|
|
195
|
+
throw timeoutError(ID, seconds);
|
|
196
|
+
if (stdout)
|
|
197
|
+
opts.onStdout?.(stdout);
|
|
198
|
+
if (stderr)
|
|
199
|
+
opts.onStderr?.(stderr);
|
|
200
|
+
return { stdout, stderr, exitCode: returncode, durationMs };
|
|
201
|
+
}
|
|
202
|
+
readFile(path) { return this.files.readFile(path); }
|
|
203
|
+
writeFile(path, data) { return this.files.writeFile(path, data); }
|
|
204
|
+
pause() { return this.provider.action(this.nativeId, "pause"); }
|
|
205
|
+
kill() { return this.provider.remove(this.nativeId); }
|
|
206
|
+
}
|
package/dist/providers/morph.js
CHANGED
|
@@ -109,8 +109,9 @@ class MorphBox {
|
|
|
109
109
|
// and would leave the process running, so it is set past ours as a fallback.
|
|
110
110
|
const script = guardTimeout(`[ -r ${ENV_FILE} ] && . ${ENV_FILE}; ${wrapCommand(cmd, { cwd: opts.cwd, env: opts.env })}`, seconds);
|
|
111
111
|
try {
|
|
112
|
-
//
|
|
113
|
-
|
|
112
|
+
// Morph joins command array entries into shell text. Pass the complete script so the
|
|
113
|
+
// timeout guard keeps its quoting on both buffered and streaming requests.
|
|
114
|
+
const r = await this.inst.exec(script, {
|
|
114
115
|
timeout: seconds + 15,
|
|
115
116
|
onStdout: opts.onStdout,
|
|
116
117
|
onStderr: opts.onStderr,
|
|
@@ -7,6 +7,7 @@ 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
11
|
/**
|
|
11
12
|
* Northflank sandboxes via `@northflank/js-client`. Auth: NORTHFLANK_API_TOKEN plus
|
|
12
13
|
* NORTHFLANK_PROJECT_ID (the project every sandbox is created in; its region is fixed at
|
|
@@ -155,7 +156,23 @@ class NorthflankBox {
|
|
|
155
156
|
return new Uint8Array(Buffer.from(r.stdout, "base64"));
|
|
156
157
|
}
|
|
157
158
|
async kill() {
|
|
158
|
-
|
|
159
|
+
try {
|
|
160
|
+
await call(() => this.nf.delete.service({ parameters: this.params }));
|
|
161
|
+
// The delete request acknowledges scheduling. The service can still execute commands
|
|
162
|
+
// until teardown completes, so keep polling until Northflank reports it gone.
|
|
163
|
+
const deadline = Date.now() + DELETE_TIMEOUT_MS;
|
|
164
|
+
for (;;) {
|
|
165
|
+
await this.info();
|
|
166
|
+
if (Date.now() >= deadline)
|
|
167
|
+
throw new ProviderError("northflank", `service ${this.nativeId} did not disappear after deletion`, 504);
|
|
168
|
+
await sleep(1000);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
if (err instanceof ProviderError && err.status === 404)
|
|
173
|
+
return;
|
|
174
|
+
throw err;
|
|
175
|
+
}
|
|
159
176
|
}
|
|
160
177
|
/** One exec session: optional stdin, streamed stdout/stderr, exit code. `expired` is thrown when limitMs passes. */
|
|
161
178
|
async run(command, limitMs, opts = {}, stdin, expired = () => timeoutError("northflank", Math.round(limitMs / 1000))) {
|
|
@@ -190,7 +207,6 @@ class NorthflankBox {
|
|
|
190
207
|
let timer;
|
|
191
208
|
const timedOut = new Promise((resolve) => {
|
|
192
209
|
timer = setTimeout(() => resolve("timeout"), limitMs);
|
|
193
|
-
timer.unref();
|
|
194
210
|
});
|
|
195
211
|
try {
|
|
196
212
|
const res = await Promise.race([session.waitForCommandResult(), failed, timedOut]);
|
|
@@ -255,5 +271,6 @@ function plan(vcpu, memoryGb) {
|
|
|
255
271
|
return (fits[0] ?? PLANS[PLANS.length - 1])[0];
|
|
256
272
|
}
|
|
257
273
|
function sleep(ms) {
|
|
258
|
-
|
|
274
|
+
// Keep standalone callers running until the next readiness poll.
|
|
275
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
259
276
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ExecResult, type ProviderId } from "../types.js";
|
|
2
|
+
type ShellExec = (command: string) => Promise<ExecResult>;
|
|
3
|
+
/** Binary-safe files for shell APIs whose command arguments and output have bounded sizes. */
|
|
4
|
+
export declare class ShellFiles {
|
|
5
|
+
private provider;
|
|
6
|
+
private run;
|
|
7
|
+
constructor(provider: ProviderId, run: ShellExec);
|
|
8
|
+
private checked;
|
|
9
|
+
writeFile(path: string, content: Uint8Array | string): Promise<void>;
|
|
10
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { ProviderError } from "../types.js";
|
|
3
|
+
import { shq, toBytes } from "../util.js";
|
|
4
|
+
/** Binary-safe files for shell APIs whose command arguments and output have bounded sizes. */
|
|
5
|
+
export class ShellFiles {
|
|
6
|
+
provider;
|
|
7
|
+
run;
|
|
8
|
+
constructor(provider, run) {
|
|
9
|
+
this.provider = provider;
|
|
10
|
+
this.run = run;
|
|
11
|
+
}
|
|
12
|
+
async checked(command) {
|
|
13
|
+
const result = await this.run(command);
|
|
14
|
+
if (result.exitCode !== 0)
|
|
15
|
+
throw new ProviderError(this.provider, result.stderr.trim() || "sandbox file command failed");
|
|
16
|
+
return result.stdout;
|
|
17
|
+
}
|
|
18
|
+
async writeFile(path, content) {
|
|
19
|
+
const destination = shq(path);
|
|
20
|
+
const temporary = shq(`${path}.sbr-${randomUUID()}`);
|
|
21
|
+
const bytes = Buffer.from(toBytes(content));
|
|
22
|
+
const chunkSize = 32 * 1024;
|
|
23
|
+
await this.checked(`mkdir -p -- "$(dirname -- ${destination})" && umask 077 && : > ${temporary}`);
|
|
24
|
+
try {
|
|
25
|
+
for (let offset = 0; offset < bytes.length; offset += chunkSize) {
|
|
26
|
+
const chunk = bytes.subarray(offset, offset + chunkSize).toString("base64");
|
|
27
|
+
await this.checked(`printf '%s' '${chunk}' | base64 -d >> ${temporary}`);
|
|
28
|
+
}
|
|
29
|
+
await this.checked(`mv -f -- ${temporary} ${destination}`);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
await this.run(`rm -f -- ${temporary}`).catch(() => { });
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async readFile(path) {
|
|
37
|
+
const source = shq(path);
|
|
38
|
+
const length = Number((await this.checked(`test -f ${source} && wc -c < ${source}`)).trim());
|
|
39
|
+
if (!Number.isSafeInteger(length) || length < 0)
|
|
40
|
+
throw new ProviderError(this.provider, "invalid sandbox file length");
|
|
41
|
+
const chunks = [];
|
|
42
|
+
const chunkSize = 128 * 1024;
|
|
43
|
+
for (let offset = 0; offset < length; offset += chunkSize) {
|
|
44
|
+
const read = await this.checked(`bash -o pipefail -c ${shq(`dd if=${source} bs=${chunkSize} skip=${offset / chunkSize} count=1 2>/dev/null | base64`)}`);
|
|
45
|
+
const chunk = Buffer.from(read, "base64");
|
|
46
|
+
if (chunk.length !== Math.min(chunkSize, length - offset))
|
|
47
|
+
throw new ProviderError(this.provider, "sandbox file changed or the response was truncated");
|
|
48
|
+
chunks.push(chunk);
|
|
49
|
+
}
|
|
50
|
+
return Buffer.concat(chunks);
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { accessLabel, billedCpuShare, billingRules, CATALOG, cpuHourlyAtFull, DEFAULT_MEMORY_GB, DEFAULT_VCPU, fixedSize, hourlyCost, info, unfit, vercelSandboxSize } from "./catalog.js";
|
|
2
|
+
import { accessLabel, billedCpuShare, billingRules, CATALOG, cpuHourlyAtFull, DEFAULT_MEMORY_GB, DEFAULT_VCPU, digitalOceanSize, fixedSize, hourlyCost, info, unfit, vercelSandboxSize } from "./catalog.js";
|
|
3
3
|
import { RoutedComputer, createComputer, planComputer, } from "./computers.js";
|
|
4
4
|
import { loadBench, median } from "./bench-store.js";
|
|
5
5
|
import { PUBLISHED } from "./published.js";
|
|
@@ -25,6 +25,8 @@ import { NorthflankProvider } from "./providers/northflank.js";
|
|
|
25
25
|
import { BoatProvider } from "./providers/boat.js";
|
|
26
26
|
import { ExeDevProvider } from "./providers/exedev.js";
|
|
27
27
|
import { AgentCoreProvider } from "./providers/agentcore.js";
|
|
28
|
+
import { DigitalOceanProvider } from "./providers/digitalocean.js";
|
|
29
|
+
import { GoogleAgentPlatformProvider } from "./providers/google.js";
|
|
28
30
|
import { AzureSessionsProvider } from "./providers/azure.js";
|
|
29
31
|
import { LambdaMicrovmProvider } from "./providers/lambda.js";
|
|
30
32
|
import { AlibabaProvider } from "./providers/alibaba.js";
|
|
@@ -80,6 +82,8 @@ export function defaultProviders() {
|
|
|
80
82
|
new ExeDevProvider(),
|
|
81
83
|
new AgentCoreProvider(),
|
|
82
84
|
new AzureSessionsProvider(),
|
|
85
|
+
new DigitalOceanProvider(),
|
|
86
|
+
new GoogleAgentPlatformProvider(),
|
|
83
87
|
new LambdaMicrovmProvider(),
|
|
84
88
|
new Agent37Provider(),
|
|
85
89
|
new AlibabaProvider(),
|
|
@@ -649,5 +653,10 @@ export const EXEC_GRACE_S = 30;
|
|
|
649
653
|
export function sizeOf(id, spec = {}) {
|
|
650
654
|
if (id === "vercel")
|
|
651
655
|
return vercelSandboxSize(spec);
|
|
656
|
+
if (id === "digitalocean") {
|
|
657
|
+
const shape = digitalOceanSize(spec.vcpu ?? DEFAULT_VCPU, spec.memoryGb ?? DEFAULT_MEMORY_GB);
|
|
658
|
+
if (shape)
|
|
659
|
+
return { vcpu: shape.vcpu, memoryGb: shape.memoryGb };
|
|
660
|
+
}
|
|
652
661
|
return fixedSize(id, spec) ?? { vcpu: spec.vcpu ?? DEFAULT_VCPU, memoryGb: spec.memoryGb ?? DEFAULT_MEMORY_GB };
|
|
653
662
|
}
|
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";
|
|
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";
|
|
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. */
|
|
@@ -30,7 +30,7 @@ export interface SandboxSpec {
|
|
|
30
30
|
expectedSeconds?: number;
|
|
31
31
|
/**
|
|
32
32
|
* How busy the CPU will be, 0 to 1 (default 1). Only a pricing hint: providers that bill CPU only
|
|
33
|
-
* while it's busy (Vercel, Cloudflare, Tensorlake, AgentCore, Sail, Sprites, Deno, Upstash) are priced
|
|
33
|
+
* while it's busy (Vercel, Cloudflare, Tensorlake, AgentCore, DigitalOcean, Sail, Sprites, Deno, Upstash) are priced
|
|
34
34
|
* at this share of their CPU plus their full memory, never below a provider's CPU floor. An agent that
|
|
35
35
|
* mostly waits on model calls uses about 0.1; a build or test run is close to 1.
|
|
36
36
|
*/
|
package/dist/verified.js
CHANGED
|
@@ -2,6 +2,7 @@ export const VERIFIED = {
|
|
|
2
2
|
agent37: "2026-11-13",
|
|
3
3
|
agentcore: "2026-11-13",
|
|
4
4
|
lambda: "2026-11-13",
|
|
5
|
+
beam: "2026-11-18",
|
|
5
6
|
blaxel: "2026-11-13",
|
|
6
7
|
boat: "2026-11-14",
|
|
7
8
|
cloudflare: "2026-11-13",
|
|
@@ -9,8 +10,11 @@ export const VERIFIED = {
|
|
|
9
10
|
e2b: "2026-11-13",
|
|
10
11
|
sprites: "2026-11-13",
|
|
11
12
|
freestyle: "2026-11-13",
|
|
13
|
+
google: "2026-11-18",
|
|
12
14
|
maritime: "2026-11-13",
|
|
13
15
|
modal: "2026-11-13",
|
|
16
|
+
morph: "2026-11-18",
|
|
17
|
+
northflank: "2026-11-18",
|
|
14
18
|
novita: "2026-11-13",
|
|
15
19
|
openscale: "2026-11-13",
|
|
16
20
|
sail: "2026-11-14",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandboxrouter/sdk",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
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",
|
|
@@ -88,6 +88,7 @@
|
|
|
88
88
|
"e2b": ">=2",
|
|
89
89
|
"modal": ">=0.11",
|
|
90
90
|
"morphcloud": ">=0.0.20",
|
|
91
|
+
"google-auth-library": "^10.0.0",
|
|
91
92
|
"@mobilerun/sdk": ">=6",
|
|
92
93
|
"@limrun/api": ">=0.69",
|
|
93
94
|
"@aws-sdk/client-appstream": ">=3",
|
|
@@ -116,6 +117,9 @@
|
|
|
116
117
|
"morphcloud": {
|
|
117
118
|
"optional": true
|
|
118
119
|
},
|
|
120
|
+
"google-auth-library": {
|
|
121
|
+
"optional": true
|
|
122
|
+
},
|
|
119
123
|
"@fly/sprites": {
|
|
120
124
|
"optional": true
|
|
121
125
|
},
|