DEV Community

Pranay Gupta
Pranay Gupta

Posted on Originally published at alloy.argonrobotics.ai Fully Autonomous

How to let Claude Code, Codex or Cursor build a robot simulation

Coding agents are good at writing Python, but robot simulation is a hard place for them: scenes fail in confusing ways, the first run compiles for minutes, and a simulation that quietly blew up can look like a success. This walkthrough sets up Alloy, an open-source physics engine for robot learning, so an agent like Claude Code, Codex or Cursor can build and run simulations on its own, either through plain Python or through an MCP server.

pip install alloy-engine
Enter fullscreen mode Exit fullscreen mode

1. Point the agent at docs written for agents

The package ships its docs, examples and a quick start written for agents. An agent can find them itself:

python -m alloy.docs          # prints three paths: the docs, the examples and AGENTS.md
python -m alloy.docs agents   # prints AGENTS.md, a quick start for agents
Enter fullscreen mode Exit fullscreen mode

A good first prompt is simply: "Install alloy-engine, run python -m alloy.docs agents, and build me a scene where a robot arm pours water into a cup."

2. Or give it the engine as MCP tools

Alloy includes an MCP server, so the agent gets operations such as scene, build, run, state, check and render as tools instead of writing code. For Claude Code:

claude mcp add alloy -- alloy mcp
Enter fullscreen mode Exit fullscreen mode

Other MCP clients (Cursor, Codex and so on) take the same command, alloy mcp, as a local stdio server.

3. The loop that keeps an agent honest

Two habits make agent-built simulations reliable: read the error's fix, and check the world after every run.

import alloy

scene = alloy.Scene(dt=0.01)
scene.add_ground()
scene.add_box("block", size=(0.05, 0.05, 0.05), pos=(0, 0, 0.1))
try:
    scene.add_box("thin", size=(0.05, 0.05))          # a typical agent mistake
except alloy.AlloyAPIError as e:
    print(e.message)
    print(e.fix)
sim = alloy.build(scene, device="cpu")
sim.run(0.5)
print(sim.check()["ok"], round(float(sim.state(world=0)["block.pos"][2]), 3))
Enter fullscreen mode Exit fullscreen mode
size needs 3 finite numbers, got (0.05, 0.05)
pass size=(..., ..., ...) in m
True 0.025
Enter fullscreen mode Exit fullscreen mode

Every error carries a message and a fix that names what to pass, so the agent can correct itself without guessing. After the run the block rests on the ground with its centre at 0.025 m, and sim.check()["ok"] is True.

Keep in mind

  • Tell the agent to print sim.check()["ok"] after every run: a frozen, broken world looks calm in a render.
  • The first run of each kind of scene compiles for minutes. Tell the agent not to stop it.
  • The docs keep the full list of limits.

Links

Top comments (0)