OpenAI Agents SDK
Give an OpenAI Agents SDK agent a Sandal sandbox as its code-execution tool (Python).
The agent gets one tool, run_python, and every call runs in the same isolated sandbox, so files and installed packages persist between calls for the length of the run. The sandbox is deleted when the async with block ends.
Install the Sandal SDK from your beta bundle and sign in once with sandal login (the SDK reads that profile), or set SANDAL_API_KEY (the key alone is enough).
pip install openai-agents # plus the sandal-sdk wheel from your bundleimport asyncio
from agents import Agent, Runner, function_tool
from sandal import Sandal
async def main() -> None:
sandal = Sandal() # the `sandal login` profile, or the SANDAL_* variables
try:
async with await sandal.create_sandbox() as sb: # one sandbox per agent run, deleted at the end
@function_tool
async def run_python(code: str) -> str:
"""Run Python 3 code in an isolated Sandal sandbox and return its exit code and output."""
await sb.write_text("/workspace/main.py", code)
result = await sb.exec("python3 /workspace/main.py")
return f"exit {result.exit_code}\n{result.stdout}{result.stderr}"
agent = Agent(
name="Coder",
instructions="Answer by writing and running Python with the run_python tool.",
tools=[run_python],
)
result = await Runner.run(agent, "What is the 30th Fibonacci number? Compute it.")
print(result.final_output)
finally:
await sandal.close()
asyncio.run(main())Run it with OPENAI_API_KEY set: python agent.py.
Verified against Sandal CLI/SDK 0.1.0-beta.10 on 2026-11-25: the tool was called directly and ran print(sum(range(10))) in a real sandbox (exit 0, 45). The model call itself needs your own model provider key.
Tested with openai-agents 0.26.0.