@baobabtech/sandbox
v0.2.0
Published
TypeScript client for baobab-sandbox: self-hosted microVM sandboxes for AI agents (Vercel Sandbox-style API)
Readme
@baobabtech/sandbox
TypeScript client for baobab-sandbox, which serves self-hosted microVM sandboxes for AI agents. The API is shaped like @vercel/sandbox, so switching between them is easy.
- Zero dependencies; uses
fetch. Works in Node 18+, Bun, Deno and edge runtimes. - ESM and CommonJS, with full types and JSDoc on every method.
- Docs ship in the package for you and your coding agent:
AGENTS.mdanddocs/(client guide, HTTP API, networking, AI SDK).
npm i @baobabtech/sandboximport { Sandbox } from "@baobabtech/sandbox";
// SBX_URL=https://sandbox.example.com SBX_TOKEN=sbx_…
const sbx = await Sandbox.create({ template: "python", timeout: 5 * 60_000 });
try {
await sbx.writeFiles([{ path: "/work/main.py", content: "print(2 + 2)" }]);
const r = await sbx.runCommand("python3", ["/work/main.py"]);
console.log(r.exitCode, await r.stdout()); // 0 "4\n"
await sbx.runCommandStream({ cmd: "sh", args: ["-c", "make all"] }, (e) => {
if (e.type === "stdout") process.stdout.write(e.data);
});
} finally {
await sbx.stop();
}API
| | |
|---|---|
| Sandbox.create({ template?, timeout?, env?, resources?, egress?, baseUrl?, token?, headers? }) | New sandbox (~50 ms from a warm pool) |
| Sandbox.get(id) / Sandbox.list() / Sandbox.templates() | Reattach, list running sandboxes, list templates |
| sbx.runCommand(cmd, args?) / sbx.runCommand({ cmd, args, cwd, env, timeout }) | Buffered; { exitCode, stdout(), stderr() }. A non-zero exit doesn't throw |
| sbx.runCommandStream(cmdOrOpts, onEvent) | Streams stdout / stderr events; resolves with the exit code |
| sbx.writeFiles([{ path, content, mode? }]) / sbx.readFileToBuffer({ path }) | Absolute paths; null if the file is missing |
| sbx.extendTimeout(ms) / sbx.stop() | stop() is idempotent |
| Sandbox.events(query) / sbx.events() | Activity log for your app or this sandbox |
Errors throw SandboxError with status and code (app_limit, host_full, egress_not_allowed, …).
Sandboxes are offline unless your operator granted your app egress and you pass egress: true.
Full guide: client guide · HTTP API
License
Apache-2.0
