# Peg Insertion in MuJoCo, the Classic Contact-Rich Task
> Peg-in-hole insertion is a benchmark contact-rich manipulation task. Drift builds a MuJoCo scene where a robot arm aligns and inserts a peg, from one prompt.
**Author:** Drift Team
**Published:** 2026-08-27
**Tag:** Product
**Reading time:** 5 min
**Canonical URL:** https://godrift.ai/blogs/peg-insertion-mujoco
---Peg-in-hole insertion is the "hello world" of contact-rich manipulation. It looks trivial and is one of the most studied hard problems in robotic assembly.

&nbsp;

\<video\>

&nbsp;

Today we test a simple but surprisingly important robot skill: insertion. We build a MuJoCo scene where a robot arm aligns a cylindrical peg and inserts it into a matching hole, with [Drift](https://link.godrift.ai/peg-1) generating the task from one prompt. Peg insertion in MuJoCo is worth doing deliberately, because peg-in-hole is the canonical contact-rich manipulation benchmark, and almost everything hard about robotic assembly shows up in it.

## Why peg insertion is a decades-old benchmark?

&nbsp;

Peg-in-hole has been a standard manipulation benchmark for decades, and for good reason. It isolates the part of assembly that's genuinely hard: precise, contact-rich alignment where tolerances are tight and the margin for error is small.

&nbsp;

The difficulty scales with clearance. A loose fit is forgiving; a tight-clearance peg demands sub-millimeter positioning and precise orientation, and once the peg contacts the hole edge, the problem becomes about managing contact forces rather than just following a trajectory. Get the alignment slightly wrong and the peg jams, binds, or misses entirely. That combination, precision plus contact reasoning, is why insertion generalizes to real assembly and why it's a workhorse task for both classical force control and learned policies. It's a more constrained cousin of the [pick-and-place](https://www.godrift.ai/blogs/pick-and-place-mujoco) work, with the difficulty concentrated at the point of contact.

## Why the peg starts pre-attached to the gripper?

&nbsp;

We deliberately start with the peg already attached to the robot's end-effector, and focus entirely on the insertion itself. That scoping is intentional, and it's worth understanding why.

&nbsp;

Grasping the peg and inserting it are two separate hard problems. By fixing the peg to the gripper, we remove grasp uncertainty from the picture, no variation in how the peg sits in the hand, so the whole difficulty of the demo lives in the approach, alignment, and insertion. It isolates the contact-rich phase, which is the part actually being studied here. In a full assembly pipeline you'd chain a grasp before this, but for testing insertion behavior, removing the grasp variable gives you a cleaner signal.

## What we asked Drift to build?

&nbsp;

The task we give [Drift](https://link.godrift.ai/peg-1) is specific: with the peg pre-attached to the end-effector, the arm needs to smoothly approach the target, align the cylindrical peg with the hole, and lower it into place.

&nbsp;

That describes an insertion behaviour in three phases, approach, align, insert, without hand-specifying the waypoints or control gains. [Drift](https://link.godrift.ai/peg-1) generates the MuJoCo scene with the peg, the hole, and the arm, along with the motion that carries out the insertion. New to the simulator? Here's [how to install MuJoCo in one prompt](https://www.godrift.ai/blogs/install-mujoco) first.

## Running the insertion

&nbsp;

We run the simulation and watch the sequence. The arm starts above the target and moves into position over the hole. Once the peg is aligned, it slowly lowers and completes the insertion, seating the peg in the hole.

&nbsp;

The deliberate, slow descent is the point. Insertion rewards controlled, careful motion over speed, because the alignment has to hold all the way down as the peg enters the hole. Watching where the arm slows and how precisely it aligns before committing to the descent is watching the actual difficulty of the task play out.

## Why insertion is a foundation for assembly?

&nbsp;

It looks simple, but insertion comes down to precision. A small error in position or orientation is the difference between a clean insertion and a jam or a miss, and that sensitivity is exactly why the task is valuable. It stress-tests the alignment and contact handling that real assembly depends on.

&nbsp;

That's what makes insertion a foundation for more complex robotic assembly. Fastening, connector mating, part fitting, and most assembly steps are insertion problems at their core, so a robot that inserts reliably has the primitive that assembly is built from. It's also a natural target for [reinforcement learning](https://www.godrift.ai/blogs/franka-push-cube-ppo-mujoco), since a policy can learn the fine contact adjustments that are hard to script by hand, and it appears as a standard task in robot-learning benchmark suites like [robosuite](https://robosuite.ai/). Tighten the clearance, offset the hole, or add a policy on top, and you have a benchmark you can push as far as you want. The full walkthrough is in the video above.

## FAQ

1. **What is peg-in-hole insertion in robotics?** Peg-in-hole insertion is a benchmark manipulation task where a robot aligns a peg with a matching hole and inserts it. It's widely used to study contact-rich manipulation because success depends on precise position and orientation control and on managing contact forces once the peg touches the hole.
2. **Why is peg insertion considered difficult?** Because it demands high precision and contact reasoning. With tight clearances, sub-millimeter position and orientation errors cause the peg to jam or miss, and once contact begins the robot must handle contact forces rather than just follow a path. That mix of precision and contact is what makes it hard.
3. **Why start with the peg already attached to the gripper?** Grasping and inserting are separate hard problems. Fixing the peg to the end-effector removes grasp uncertainty so the demo isolates the approach, alignment, and insertion, which is the contact-rich phase actually being tested. A full pipeline would add a grasp step before insertion.
4. **Why is insertion important for robotic assembly?** Most assembly operations, fastening, connector mating, and part fitting, are insertion problems at their core. A robot that can insert reliably has the fundamental skill that assembly is built on, which is why peg-in-hole is a foundational benchmark for assembly automation.
5. **How does Drift build the insertion task?** From a single natural-language prompt, [Drift](https://link.godrift.ai/peg-1) generates the MuJoCo scene with the peg, hole, and arm, and the motion to approach, align, and insert the peg, so you get a runnable insertion task without hand-authoring the scene or tuning the trajectory yourself.

## Related reading

- [Build a Pick-and-Place Scene in MuJoCo in One Prompt](https://www.godrift.ai/blogs/pick-and-place-mujoco)
- [Training a Franka Panda to Push a Cube With Reinforcement Learning](https://www.godrift.ai/blogs/franka-push-cube-ppo-mujoco)
- [Why Robot Hands Are So Hard](https://www.godrift.ai/blogs/why-robot-hands-are-hard)
- [MuJoCo: The Physics Engine Robotics Research Quietly Runs On](https://www.godrift.ai/blogs/what-is-mujoco)
