from langchain.agents import create_agent
from langchain.tools import tool
from nullspace import Machine
@tool
def run_in_nullspace(command: str) -> str:
"""Run a short shell command in an isolated Nullspace machine."""
with Machine.create(template="base", timeout=300) as machine:
result = machine.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 machine tool for isolated execution.",
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "Check uname -a in a machine."}]}
)
print(result)