from langchain.agents import create_agent
from langchain.tools import tool
from nullspace import Sandbox
@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 = create_agent(
model="openai:<model-name>",
tools=[run_in_nullspace],
system_prompt="Use the sandbox tool for isolated execution.",
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "Check uname -a in a sandbox."}]}
)
print(result)