A function tool backed by a sandbox
The Agents SDK turns a typed Python function into a tool with @function_tool. Make that function write the code into a cpuos sandbox and run it there, and the agent can execute whatever it writes without touching your machine.
pip install openai-agents cpuosimport osfrom agents import (Agent, OpenAIChatCompletionsModel, Runner, function_tool, set_tracing_disabled)from cpuos import Sandboxfrom openai import AsyncOpenAIgpuos = AsyncOpenAI(base_url="https://gpuos.si/v1", api_key=os.environ["GPUOS_API_KEY"])set_tracing_disabled(True) # traces go to OpenAI by defaultsbx = Sandbox.create(template="python", timeout="30m")@function_tooldef run_python(code: str) -> str: """Run a Python 3 script in an isolated sandbox. Files live in /work. Returns the exit code, stdout and stderr.""" sbx.files.write("/work/main.py", code) run = sbx.exec("cd /work && python main.py", timeout="2m") return f"exit_code={run.exit_code}\n{run.stdout[-4000:]}\n{run.stderr[-2000:]}"agent = Agent( name="Analyst", instructions="Compute every number with run_python. Files are in /work.", model=OpenAIChatCompletionsModel(model="qwen3-32b", openai_client=gpuos), tools=[run_python],)result = Runner.run_sync(agent, "What is the 90th Fibonacci number?")print(result.final_output)sbx.pause()The examples point the model at gpuOS, which serves open models on your own GPUs at https://gpuos.si/v1 with an OpenAI-compatible API. Any other OpenAI-compatible provider works the same way: change the base URL, the key and the model name.
cpuos is in early access: @cpuos/sdk (npm) and cpuos (PyPI) ship to early-access teams first, and read the API key from CPUOS_API_KEY. The calls on this page show the current API shape.
One sandbox per conversation
Create the sandbox when a conversation starts and pass it to the tool through the run context instead of a global, so two users never share a machine. Pause it when the run ends and store the id with the conversation; Sandbox.resume(id) brings back the files and installed packages on the next turn.
Official documentation: openai.github.io/openai-agents-python