TypeScript SDK
The TypeScript SDK for Pod, for Node 24, Deno and browsers
@mapier/pod runs in Node 24, Deno and browsers, on the runtime's own fetch and WebSocket.
Not available yet The TypeScript and Python packages are not published to their registries yet. Invited teams get them from us.
npm install @mapier/podimport { Pod } from "@mapier/pod";
const pod = new Pod({ apiKey: process.env.POD_API_KEY! });
const sandbox = await pod.sandboxes.create({ size: "small", labels: { app: "quickstart" } });
const { stdout } = await sandbox.run("uname -a && ls /");
console.log(stdout);
await sandbox.files.write("/root/hello.py", 'print("hello from Pod")\n');
const result = await sandbox.run(["python3", "/root/hello.py"]);
console.log(result.exitCode, result.stdout);
await sandbox.delete();baseUrl defaults to https://api.pod.mapier.ai.
What it covers
- Sandboxes.
pod.sandboxes.create,get,listanddelete, andsleep,wake,stop,start,resize,extend,forkandsnapshot, onpod.sandboxesby id or on aSandbox. Calls that change a sandbox wait until the change is done, up totimeoutMs. - Lists are async iterables that fetch the next page as you go:
for await (const s of pod.sandboxes.list({ state: 'running' }))..pages()gives the pages,.toArray()collects them. - Commands.
sandbox.exec(cmd)answers a handle whosestdoutandstderrare async iterables of bytes, withwait(),kill(signal),sendSignal(signal),writeStdin,closeStdinandresize.sandbox.run(cmd)collects the output for you. A string runs under/bin/sh -c; an array runs as it is, with no shell. - Files.
sandbox.files.read,readText,write,list,remove,moveandmkdir. - Usage.
pod.usage.get({ period: '2026-11', group_by: 'size' }), in seconds and bytes. - Your users.
pod.endUsers.create,get,listandsetLimits, andpod.endUsers.sandbox(ref)for one computer per user; see Your users. - Organizations.
pod.organisations, withmembersandinvitations. Changing members is for a signed-in person, so with an API key those calls throwperson_required. - Also
pod.snapshots,pod.operations,pod.keys,pod.projects,pod.serviceGrants,pod.billingandpod.catalog().pod.apiis the typed client underneath, for anything the SDK does not wrap.
const proc = await sandbox.exec("npm test", { cwd: "/work", timeout_s: 600 });
for await (const chunk of proc.stdout) process.stdout.write(chunk);
const { exitCode } = await proc.wait();Names the API defines keep the API's spelling (time_limit_s, group_by). Options only the SDK has are camelCase (timeoutMs, idempotencyKey, signal).
Errors and retries
Every refusal is a PodApiError whose code is a name from the error list, with status, requestId, retryAfterS and isRetryable(). The others are PodConnectionError, PodTimeoutError (it names the operation or sandbox still in progress), PodStateError, PodStreamError and PodValidationError, all subclasses of PodError.
The SDK sends a call again by itself only when the error list allows it and the call is a read or carries an idempotency key. Every call that changes something carries one, the same on every attempt, so a retry never acts twice. Pass idempotencyKey to repeat a call safely from another process. Retries back off with jitter and honor retry_after_s; set retry: { maxRetries } or retry: false on new Pod(), or maxRetries on one call. err.sameKeyRunsAgain() says whether the same key would run the call again.
Every call takes signal (an AbortSignal) and timeoutMs. Aborting an exec ends the command.
In a browser
A page should never hold an API key. Your server makes a stream ticket for one command's stream and your page's origin, and the page opens the stream with it:
// On your server, with the key.
const proc = await sandbox.exec("npm test", { detached: true });
const ticket = await pod.sandboxes.execStreamTicket(sandbox.id, proc.id, {
origin: "https://app.example.com",
});// In the page, with no key.
import { attachExec } from "@mapier/pod/browser";
const out = await attachExec({
baseUrl: "https://api.pod.mapier.ai",
ticket: () => askMyServerForATicket(),
});
for await (const chunk of out.stdout) show(chunk);@mapier/pod/browser loads nothing that calls the API with a key. A ticket opens one stream, once, from its origin, within 30 seconds by default, so pass a function that asks your server: a failed upgrade asks it once more. A handle opened this way streams, takes standard input and sendSignal(); kill() and refresh() need a key.