Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.podflare.ai/llms.txt

Use this file to discover all available pages before exploring further.

Install

npm install podflare
ESM only, Node 20+.

Configuration

import { Sandbox, Client } from "podflare";

// Default: reads PODFLARE_HOSTD_URL env var, falls back to https://api.podflare.ai
const sbx = await Sandbox.create();

// Explicit host
const sbx = await Sandbox.create({ host: "https://api.podflare.ai" });

// Shared Client for many sandboxes
const client = new Client({ host: "https://api.podflare.ai" });
const a = await Sandbox.create({ client });
const b = await Sandbox.create({ client });

Core verbs

runCode(code, language?): Promise<ExecResult>

const r = await sbx.runCode("print(sum(range(10)))");
console.log(r.stdout, r.exitCode);

runCodeStream(code, language?): AsyncGenerator<Event>

for await (const ev of sbx.runCodeStream("for i in range(3): print(i)")) {
  if (ev.type === "stdout") process.stdout.write(ev.data + "\n");
}

fork(n=1): Promise<Sandbox[]>

See Fork for semantics.
const children = await parent.fork(5);

diff(other, paths?): Promise<{added, removed, modified}>

const d = await a.diff(b);

mergeInto(winner): Promise<void>

await parent.mergeInto(winner);

upload(data, remotePath) / download(remotePath)

await sbx.upload(new TextEncoder().encode("hello"), "/root/hello.txt");
const bytes = await sbx.download("/root/hello.txt");
console.log(new TextDecoder().decode(bytes));

close(): Promise<void>

const sbx = await Sandbox.create();
try {
  // ...
} finally {
  await sbx.close();
}

Vercel AI SDK adapter

Subpath import: "podflare/ai-sdk".
import { tool } from "ai";
import { z } from "zod";
import { podflareRunCode } from "podflare/ai-sdk";

const pf = podflareRunCode();

const { text } = await generateText({
  model: anthropic("claude-opus-4-7"),
  tools: {
    runCode: tool({
      description: pf.description,
      parameters: z.object({
        code: z.string(),
        language: z.enum(["python", "bash"]).optional(),
      }),
      execute: pf.execute,
    }),
  },
  prompt: "Use runCode to compute sqrt(12345)",
});

await pf.close();
See Vercel AI SDK for the full guide.

Types

import type { Sandbox, Event, ExecResult, Language } from "podflare";