Sandbox object that wraps every API operation — code execution, forking, filesystem transfers, and lifecycle management — behind a clean, typed interface. Every public symbol ships with full type annotations so your editor can autocomplete and type-check your sandbox code.
Installation
Install the package from PyPI. Python 3.10 or later is required.Configuration
Set the host
By default the SDK reads
PODFLARE_HOST from your environment and falls back to http://127.0.0.1:7070 for local development. You can also pass the host explicitly or share a single Client across multiple sandboxes to avoid creating one httpx.Client per sandbox.Set the API key
Pass your key explicitly or export
PODFLARE_API_KEY so every Sandbox() call picks it up automatically.For local development without an API key, the SDK falls back to
http://127.0.0.1:7070 automatically. See Authentication for details.Core methods
run_code
ExecResult containing stdout, stderr, and exit_code.
run_code_stream
Event objects as they arrive from the sandbox. Use this when you want to display output incrementally rather than waiting for the full result.
fork
n independent children, each starting from the parent’s current memory and filesystem state. Fork is nearly flat in cost across n because children restore in parallel — spawning 5 children takes ~101 ms on reference hardware.
diff
other. The result is a dict with added, removed, and modified keys containing lists of paths. By default, /root and /tmp are compared; pass paths to restrict the comparison.
merge_into
winner’s state as the new state of the parent. After this call, the parent’s ID remains valid and now drives winner’s VM. Calling winner.close() becomes a no-op.
upload and download
close and context manager
close() automatically even if an exception is raised.
Full example — fork, evaluate, merge
The following example loads a dataset once, forks five children to explore different hypotheses in parallel, picks the best result, and merges the winner back into the parent.Type annotations
The SDK ships full type annotations. ImportExecResult, Event, and Language from the top-level module to annotate your own functions.
Returned by
run_code. Fields: stdout: str, stderr: str, exit_code: int.Yielded by
run_code_stream. Fields: type: str ("stdout", "stderr", "exit"), data: str.Literal["python", "bash"] — the set of languages accepted by run_code and run_code_stream.Framework adapters
Use these integrations to wire Podflare sandboxes directly into AI agent frameworks.OpenAI Agents SDK
from podflare.integrations.openai_agents import podflare_code_interpreterAnthropic Messages API
from podflare.integrations.anthropic import handle_code_execution_tool_use