Designing agentic loops

simonwillison.net

270 points by simonw a day ago


akashakya - a day ago

For lightweight sandboxing on Linux you can use bubblewrap or firejail instead of Docker. They are faster and _simpler_. Here is a bwrap script I wrote to run Claude in a minimal sandbox an hour back:

    exec bwrap \
      --ro-bind /usr /usr \
      --ro-bind /etc /etc \
      --ro-bind /run /run \
      --ro-bind "$NODE_PATH" /node \
      --proc /proc \
      --dev /dev \
      --symlink usr/lib64 /lib64 \
      --tmpfs /tmp \
      --unshare-all \
      --share-net \
      --die-with-parent \
      --new-session \
      --bind "$HOME/claude" /claude \
      --bind "$HOME/.claude.json" /claude/.claude.json \
      --bind "$HOME/.claude" /claude/.claude \
      --setenv HOME /claude \
      --setenv PATH "/node:/claude/bin:/usr/bin" \
      --bind "$(pwd)" /work \
      --chdir /work \
      /claude/bin/claude "$@"
mike_hearn - a day ago

I recently built my own coding agent, due to dissatisfaction with the ones that are out there (though the Claude Code UI is very nice). It works as suggested in the article. It starts a custom Docker container and asks the model, GPT-5 in this case, to send shell scripts down the wire which are then run in the container. The container is augmented with some extra CLI tools to make the agent's life easier.

My agent has a few other tricks up its sleeve and it's very new, so I'm still experimenting with lots of different ideas, but there are a few things I noticed.

One is that GPT-5 is extremely willing to speculate. This is partly because of how I prompt it, but it's willing to write scripts that try five or six things at once in a single script, including things like reading files that might not exist. This level of speculative execution speeds things up dramatically especially as GPT-5 is otherwise a very slow model that likes to think about things a lot.

Another is that you can give it very complex "missions" and it will drive things to completion using tactics that I've not seen from other agents. For example, if it needs to check something that's buried in a library dependency, it'll just clone the upstream repository into its home directory and explore that to find what it needs before going back to working on the user's project.

None of this triggers any user interaction due to running in the container. In fact, no user interaction is possible. You set it going and do something else until it finishes. The model is very much to queue up "missions" that can then run in parallel and you merge them together at the end. The agent also has a mode where it takes the mission, writes a spec, reviews the spec, updates the spec given the review, codes, reviews the code, etc.

Even though it's early days I've set this agent missions that it spent 20 minutes of continuous uninterrupted inferencing time on, and succeeded excellently. I think this UI paradigm is the way to go. You can't scale up AI assisted coding if you're constantly needing to interact with the agent. Getting the most out of models requires maximally exploiting parallelism, so sandboxing is a must.

amluto - a day ago

The state of YOLO is embarrassing:

> Update: It turns out Anthropic have their own documentation on Safe YOLO mode for Claude Code which says:

> Letting Claude run arbitrary commands is risky and can result in data loss, system corruption, or even data exfiltration (e.g., via prompt injection attacks). To minimize these risks, use --dangerously-skip-permissions in a container without internet access. You can follow this reference implementation using Docker Dev Containers. [https://github.com/anthropics/claude-code/tree/main/.devcont...]

And… that link goes to a devcontainer that firewalls itself from inside using, effectively, sudo iptables. If Claude Code can’t break that all by itself in a single try, I’d be a bit surprised.

warthog - 13 hours ago

I built this using OpenAI GPT-5 agentic loops as well where the agent interacts with a spreadsheet: banker dot so

Some principles I learned: 1. You don't really wanna use any kind of framework that wraps around openai or claude sdks. You end up fighting them 2. Small number of tools with more functions are better than large number of tools with small number of functions inside 3. Function definitions you put inside the tools are actually very important and need to be very clear 4. Integrating another agent as a tool to the main agent can relieve your context window by 5x 5. RAG via only vector search is mostly unnecessary. Claude Code itself leverages iterative search which works way better with code repos as well as most documents

refset - a day ago

For anyone else curious about what a practical loop implementation might look like, Steve Yegge YOLO-bootstrapped his 'Efrit' project using a few lines of Elisp: https://github.com/steveyegge/efrit/blob/4feb67574a330cc789f...

And for more context on Efrit this is a fun watch: "When Steve Gives Claude Full Access To 50 Years of Emacs Capabilities" https://www.youtube.com/watch?v=ZJUyVVFOXOc

tra3 - a day ago

On one hand, folks are complaining that even basic tasks are impossible with LLMs.

On the other hand we have cursed language [0] which was fully driven by AI and seems to be functional. Btw, how much did that cost?

I feel like I've been hugely successful tools like Claude Code, aider, open code. Especially when I can define custom tools. "You" have to be a part of the loop, in some capacity. To provide guidance and/or direction. I'm puzzled by the fact that people are surprised by this. When I'm working with other entities (people) who are not artificially intelligent, the majority of the time is spent clarifying requirements and aligning on goals. Why would it be different with LLMs?

0: https://ghuntley.com/cursed/

vinhnx - 9 hours ago

I'm currently building my own coding agent, mainly for self-research [0], so this article is very helpful to me. Thank you Simon!

In this particular thread, other has commented about lightweight sandboxing solution. I think I will integrate this next in my agent for safe code execution. [1]

[0] https://github.com/vinhnx/vtcode

[1] https://news.ycombinator.com/item?id=45429787

codethief - 14 hours ago

For sandboxing and parallelizing agents people at my day job recently started using container-use[0] and seem to be quite happy with it. I have yet to try it in depth but the approach it takes seems quite sensible to me: Have the agent execute all commands within a container via an MCP[1], propagate any changes the agent makes to git branches on the host, for easy review & merge.

[0]: https://github.com/dagger/container-use

[1]: I would like it better if the entire agent process were sandboxed but I suppose that would make it difficult to use with IDE/GUI-based agents.

jujugoboom - a day ago

Wrong takeaway, but claude code was released February of this year??? I swear people have been glazing it for way longer... my memory isn't that bad right?

tptacek - a day ago

This is great. I feel like most of the oxygen is going to go to the sandboxing question (fair enough). But I'm kind of obsessed with what agent loops for engineering tasks that aren't coding look like, and also the tweaks you need for agent loops that handle large amounts of anything (source code lines, raw metrics or oTel span data, whatever).

There was an interval where the notion of "context engineering" came into fashion, and we quickly dunked all over it (I don't blame anybody for that; "prompt engineering" seemed pretty cringe-y to me), but there's definitely something to the engineering problems of managing a fixed-size context window while iterating indefinitely through a complex problem, and there's all sorts of tricks for handling it.

athrowaway3z - 16 hours ago

On unix you can just use a user account to limit access.

Create a group for you and the `claude` user, and have it do `umask 002` on login.

The shellagent use case has much more parallels with 1980s TTY+mainframes dealing with multiple users than it has with containers.

I.e. Docker's USP was reproducibility; not access controls.

simonw - a day ago

I updated this post to link to the Claude Code docs that suggest running YOLO mode using their Docker dev container: https://www.anthropic.com/engineering/claude-code-best-pract... - which locks down network access to just a small set of domains: https://github.com/anthropics/claude-code/blob/5062ed93fc67f...

mccoyb - a day ago

I think this is a strictly worse name than "agentic harness", which is already a term used by open-source agentic IDEs (https://github.com/search?q=repo%3Aopenai%2Fcodex%20harness&... or https://github.com/openai/codex/discussions/1174)

Any reason why you want to rename it?

Edit: to say more about my opinions, "agentic loop" could mean a few things -- it could mean the thing you say, or it could mean calling multiple individual agents in a loop ... whereas "agentic harness" evokes a sort of interface between the LLM and the digital outside world which mediates how the LLM embodies itself in that world. That latter thing is exactly what you're describing, as far as I can tell.

deevus - 15 hours ago

Fantastic article. I'm always looking for better ways to work with agents. I am personally using Claude Code, and want to try some more YOLO type stuff.

My problem is I often give it too much to do. I'm usually overly optimistic about how effective it can be.

I have found Sonnet 4.5 to be quite the improvement over Sonnet 4 however.

ademup - a day ago

I'm surprised to see so many people using containers when setting up a KVM is so easy, gives the most robust environment possible, and to my knowledge much has better isolation. A vanilla build of Linux plus your IDE of choice and you're off to the races.

- 14 hours ago
[deleted]
cadamsdotcom - a day ago

My preferred ergonomics for agents are like using a washing machine: choose what clothes you want to have cleaned (whites or colors..) and press “go”.

Claude Code plan mode is the washing machine of agentic loops. It lets you see a detailed plan and if you approve you can let it rip with trust that it’ll do what it says, and go do something else while it’s at work.

Adding tests and other ways to validate its work help it go further & run longer off a single plan.

SafeDusk - a day ago

Resonating with the statement "Designing agentic loops is a very new skill—Claude Code was first released in just February 2025!" when I was investigating Codex[0].

[0]: https://blog.toolkami.com/openai-codex-tools/#coding-agents

BoppreH - a day ago

> If anything goes wrong it’s a Microsoft Azure machine somewhere that’s burning CPU and the worst that can happen is code you checked out into the environment might be exfiltrated by an attacker, or bad code might be pushed to the attached GitHub repository.

Isn't that risking getting banned from Azure? The compromised agent might not accomplish anything useful, but its attempts might get (correctly!) flagged by the cloud provider.

CuriouslyC - a day ago

One important issue with agentic loops is that agents are lazy, so you need some sort of retrigger mechanism. Claude code supports hooks, you can wire your agent stop hook to a local LLM, feed the context in and ask the model to prompt Claude to continue if needed. It works pretty well, Claude can override retriggers if it's REALLY sure it's done.

Regarding sandboxing, VMs are the way. Prompt injected agents WILL be able to escape containers 100%.

codazoda - a day ago

I made a simple docker container to jail an LLM for a recent project.

https://github.com/codazoda/llm-jail

- a day ago
[deleted]
chevman - a day ago

I feel like the AI industry is basically recreating "workflow engines" again and again and again, in different forms, with different input mechanisms.

mattacular - 15 hours ago

> This is so dangerous, but it’s also key to getting the most productive results

where do i sign up?

Escapade5160 - 18 hours ago

I typically run my code agents in distrobox.

moduspol - a day ago

A little off-topic but I’ve been waiting for a post by someone who’s built something like Claude Code or Codex that can explain how the state machine works for execution.

Clearly it’s not just a good system prompt and hoping for the best. Obviously they’ve both got fairly good algorithms for working toward whatever the user asked for incrementally, handling expectable errors, changing course if necessary, etc.

I mean ultimately it’s gotta be a really big flow chart that results in the LLM getting prompted various ways in all kinds of directions before ultimately converging on the final response, right? Or am I way off-base?

Has anyone seen such a post explaining this architecture / state machine / algorithm?

dboreham - 15 hours ago

In case anyone else is confused: I saw the word "loop" and wondered what the point is to run an LLM in a loop? Like, what's the goal here? You want to write N different React todo web apps, or something?

After reading the article a bit, I realized this isn't about "loops" at all. What it is about is "bypassing the yes/no human check on each step the LLM wants to take in completing some multi-step task". You can already to this with, for example, claude code. However, one of the points of having a human approve LLM actions is to prevent it doing something stupid or destructive. So now you have a second problem: how to prevent the LLM from poking holes in spacetime?

Answer: sandbox it.

And that's what the article is about.

ggggggdgdhdjdj - a day ago

I find the word agentic to be a hot spike into my brain ... I am not sure why but I think it has to do with the fact it is marketing bs.

Is it just me ?

lobochrome - 20 hours ago

Is there a way to let the agents share their agents.md? Claude code looks at Claude.md and I have yet to find a way to unify the agent handbook.

saltyoldman - a day ago

I wouldn't be surprised if agents start getting managed by a distributed agentic system - think about it. Right now you get codex/claude/etc... and it's system prompt and various other internally managed prompts are locked down to the version you downloaded. What if a distributed system ran experimental prompts and monitored the success rate (what code makes it into a commit) and provides feedback to the agent manager. That could help automatically fine tune it's own prompts.