Skip to main content
The podflare_code_interpreter() helper returns an OpenAI Agents SDK-compatible tool that lazily creates a Podflare sandbox on the first invocation and reuses it for every subsequent code execution in the same run. You install two packages, pass the tool to your Agent, and call close_podflare_sandbox() when you’re done.

Install

pip install podflare openai-agents

Quickstart

1

Create the tool

Import podflare_code_interpreter and call it to get a ready-to-use tool object. No sandbox is created yet — it spins up on the first agent invocation.
from podflare.integrations.openai_agents import podflare_code_interpreter

tool = podflare_code_interpreter()
2

Attach the tool to an agent

Pass the tool in the tools list when constructing your Agent.
from agents import Agent

agent = Agent(
    name="assistant",
    instructions="Use the run_code tool to answer computational questions.",
    tools=[tool],
)
3

Run the agent

Run the agent with Runner.run. The tool intercepts run_code calls, executes the code inside a Podflare sandbox, and returns stdout, stderr, and exit_code to the model.
from agents import Runner

result = await Runner.run(agent, "What is the sum of squares from 1 to 100?")
print(result.final_output)
4

Clean up the sandbox

Call close_podflare_sandbox() on the tool object after the run completes to destroy the underlying VM.
tool.close_podflare_sandbox()

Full example

from agents import Agent, Runner
from podflare.integrations.openai_agents import podflare_code_interpreter

tool = podflare_code_interpreter()

agent = Agent(
    name="assistant",
    instructions="Use the run_code tool to answer computational questions.",
    tools=[tool],
)

result = await Runner.run(agent, "What is the sum of squares from 1 to 100?")
print(result.final_output)

# Destroy the Podflare sandbox when the run is complete
tool.close_podflare_sandbox()

How it works

On each run_code invocation the tool calls sandbox.run_code(code, language) on the underlying Sandbox and returns a dict with three keys:
KeyTypeDescription
stdoutstrCaptured standard output
stderrstrCaptured standard error
exit_codeintProcess exit code
The sandbox is created lazily on the first call, so pool warm-up happens only when the agent actually runs code. Because the same sandbox is reused across every invocation, Python interpreter state — imported modules, variables, loaded files — persists for the entire agent run.

Options

Pass keyword arguments to podflare_code_interpreter() to override the host or select a specific sandbox template:
tool = podflare_code_interpreter(
    host="https://api.podflare.dev",  # default: PODFLARE_HOST env var
    template="python-datasci",         # default: primary pool
)
If host is not provided, the SDK reads the PODFLARE_HOST environment variable and falls back to http://127.0.0.1:7070 for local development.

Cleanup

The tool object exposes close_podflare_sandbox(). Call it after every agent run to destroy the VM and release the slot back to the pool.
# Always clean up, even if the run raises
try:
    result = await Runner.run(agent, user_input)
finally:
    tool.close_podflare_sandbox()
For many short-lived agent runs, creating a new tool per run is fine — pool hits are around 10 ms. For long-running conversations, reuse the same tool instance across turns to keep REPL state alive between messages.