import asyncio
from agents import Agent, Runner, function_tool
from nullspace import Sandbox
@function_tool
def run_in_nullspace(command: str) -> str:
"""Run a short shell command in an isolated Nullspace sandbox."""
with Sandbox.create(template="base", timeout=300) as sandbox:
result = sandbox.commands.run(command, shell=True, timeout=120)
return result.stdout[-4000:] or result.stderr[-4000:]
agent = Agent(
name="Sandbox Operator",
instructions="Use the sandbox tool for commands that need isolated execution.",
tools=[run_in_nullspace],
)
async def main() -> None:
result = await Runner.run(agent, "Use a sandbox to print Python's platform.")
print(result.final_output)
asyncio.run(main())