Adding a provider
From README.md, rendered when the site was built.
A provider is one file. Only create, exec and kill are required. The router
implements file read, write and listing on top of exec (base64 in chunks, so binary is
safe), and an adapter that can do better adds the native calls.
// src/providers/acme.ts
import { defineProvider, httpJson } from "./util.js";
export const acmeProvider = defineProvider({
info: {
id: "acme",
name: "Acme Sandboxes",
homepage: "https://acme.dev",
env: ["ACME_API_KEY"],
capabilities: ["customImage"],
freeTier: {
tier: { kind: "monthly-credit", usd: 10 },
concurrency: 5,
source: "https://acme.dev/pricing",
checked: "2026-11-11",
},
pricing: { vcpuSecondUsd: 0.00001, gibSecondUsd: 0.000003, defaultCpu: 1, defaultMemoryMiB: 1024 },
},
async create(spec, ctx) {
const s = await httpJson<{ id: string }>("https://api.acme.dev/v1/sandboxes", {
headers: { authorization: `Bearer ${ctx.env.ACME_API_KEY}` },
body: { image: spec.image, timeout: spec.timeoutSec, env: spec.env, metadata: spec.metadata },
});
return { providerSandboxId: s.id };
},
async exec(id, command, opts, ctx) { /* … */ return { stdout: "", stderr: "", exitCode: 0 }; },
async kill(id, ctx) { /* … */ },
});
Then add it to src/providers/index.ts, or call
router.register(acmeProvider) from your own code. To finish:
- Add
listAlivesosbr sweepcan close sandboxes that died behind the router's back. - If the provider keeps a sandbox alive past the requested timeout, set
enforcesTimeout: falseininfo. The router then deletes it at the deadline. - Make
createthrow errors with an HTTPstatus, so quota (402) and rate limits (429) fail over correctly. If the provider uses a status that means something else (a spent allowance as 429 or 409, a plan limit as 403), declare it withrefusals()insrc/providers/util.ts. - If the provider bills the vCPUs only while they are busy, set
billing: "active-cpu"inpricing(andactiveCpuFloorif it bills a minimum share), so strategies rank it by its expected cost. - Run the tests:
test/providers.test.tschecks that every built-in declares its free-tier source and backs each capability it claims.