When should you use it?
- You want to experiment with an agent that improves itself
- You can run Docker
- You will read the commit history
Not for: Production systems; Anyone without a rollback plan
What do you need, and what do you get?
You need
- Agent code and capability list
- Docker setup
- Validation checks and fixed rules
You get
- Commits for each change
- Automatic rollbacks
- Growing capability list
How does it work, step by step?
- Split the trustKeep the runner, git and checks on the host, where the agent cannot touch them.
- Mount read-onlyLet the agent write only to its own code folder.
- Snapshot firstTake a git snapshot before each change.
- ValidateRun syntax, schema and import checks and roll back on any failure.
- Add fixed rulesGive it rules it can read but never edit, such as keeping tool count low.
The prompt
Our own prompt, inspired by PedroMFernandes on Hacker News and written to work in Claude and Custom agent. Values in lime are placeholders.
Design a guarded runner for an agent that edits its own code. The runner lives outside the sandbox and must: snapshot with git, send the next task, run syntax, schema and import checks, commit on pass and roll back on fail. List the fixed rules the agent can read but not edit, and how to cap context and spend per batch.
Inspired by PedroMFernandes on Hacker News: Comment in Miguel: An AI agent that modifies its own source code, sandboxed in Docker. The prompt above is written by playbooks.bot in our own words; nothing from the original is quoted.
What can go wrong?
- Context runs out when the agent reads too many of its own files; budget it.
- Agents add thin wrapper tools; each one costs context.
- API spend sets the pace; cap it.
Our take
A self-modifying agent sounds like a bad idea until you see where PedroMFernandes put the trust boundary. Miguel can change its own files, but the snapshot, the checks and the decision to commit live on the host, out of reach, so a broken change simply vanishes. That separation is the transferable lesson for any agent that edits important things: let it work freely inside a sandbox, and keep the judge outside. The project's lessons are also practical. Miguel tended to pile up flimsy wrappers around existing tools, and every tool costs context, so fewer, broader tools worked better; fixed rules that the agent cannot rewrite were needed to stop the habit. The most dangerous failure was running out of context before doing the actual work. Keep API spend visible per batch, as the author did, so experiments stay cheap. If you try something similar, build the snapshot and rollback first, test that rollback works by deliberately breaking a change, and only then let the agent touch its own code.
Where the time goes back: Self-improvement experiments run safely because every change can be undone.
FAQ
What surprised the author?
What was the worst failure?
Source and credit
Inspired by PedroMFernandes on Hacker News. We describe the idea in our own words, link to the original, and wrote the prompt ourselves; nothing is quoted.
- Inspired by
- Comment in Miguel: An AI agent that modifies its own source code, sandboxed in Docker
- Creator
- PedroMFernandes on Hacker News
- Published on
- Hacker News
- Original date
- Mar 10, 2026
- License
- Not openly licensed (the poster keeps all rights), so we quote nothing and link to the original
- Originally for
- Custom agent
- AI dry run
- Oct 23, 2026: passed. Dry-run tested by our AI test agent on sample input. PASS: Gates held on desk check; no live sends, bookings or purchases.
AI dry run on sample data; not run with live connected accounts. The playbooks.bot test agent filled the prompt with synthetic inputs, produced the output and checked it against the page's stated outputs and guardrails. - Verified
- Oct 23, 2026: source link resolves to the original, the credited creator published it, our excerpt or prompt matches it, and the license allows our use.
Are you the creator? Claim or correct this page.