A FunctionAgent with a sandbox tool
LlamaIndex agents accept plain Python functions as tools and read the docstring as the tool description. Retrieval answers questions about your documents; the sandbox computes anything the documents do not state directly.
pip install llama-index llama-index-llms-openai-like cpuosimport asyncioimport osfrom cpuos import Sandboxfrom llama_index.core.agent.workflow import FunctionAgentfrom llama_index.llms.openai_like import OpenAILikellm = OpenAILike( model="qwen3-32b", api_base="https://gpuos.si/v1", api_key=os.environ["GPUOS_API_KEY"], is_chat_model=True, is_function_calling_model=True, context_window=32768,)sbx = Sandbox.create(template="python", timeout="30m")def 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 = FunctionAgent( tools=[run_python], llm=llm, system_prompt="Use run_python for any calculation. Files are in /work.",)async def main(): print(await agent.run("What is the compound growth of 1,000 at 4% over 17 years?")) sbx.pause()asyncio.run(main())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.
Official documentation: www.llamaindex.ai