Patterns
Pattern 11 of 26
Autonomous Loops
Let it cook
An autonomous loop wraps an agent in a persistent execution cycle. Give it a task list and exit conditions, then let it run for hours without waiting for human input at every step. Claude Code has /loop, Devin has long-running tasks, Cursor has Cloud Agents. The concept is the same across all of them. You need three things to do this safely in production: circuit breakers, rate limiting, and sandboxed execution. Without those, it is not a feature.
Why it matters
This is the pattern that moves an agent from assistant to worker. Without a loop, every conversation resets. The agent cannot build on its previous work. With a well-designed loop, I can hand off a multi-hour task, go do something else, and come back to results. That is a qualitatively different relationship with the tool.
Deep Dive
An autonomous loop gives the agent a persistent execution context. Instead of responding to a single prompt and stopping, the agent maintains a task list, takes actions, observes results, updates its understanding of what is left to do, and continues until it hits an exit condition. The exit conditions matter as much as the loop itself. They can be time-based, cost-based, completion-based, or error-rate-based. Claude Code's /loop command, Devin 2.0, and Cursor Cloud Agents all implement this pattern in slightly different ways, but the underlying structure is the same.
The three safety controls are not optional. Circuit breakers terminate the loop when it exceeds a cost threshold, time limit, or error rate. Without them, a runaway loop can burn through an API budget in minutes or hit rate limits for every external service it touches. Rate limiting prevents the agent from exhausting quotas in a single session. Sandboxed execution ensures that code the agent writes and runs cannot affect production systems. I have seen all three of these fail in demos that were not properly controlled. In production, the failure mode is worse.
Anthropic's November 2025 engineering post on effective harnesses for long-running agents covers the specific patterns that make autonomous loops reliable in practice. Progress checkpointing lets the agent resume after an interruption rather than starting over. Clean state at the start of each session, reconstructed from artifacts rather than from memory, makes the loop robust to context loss. Structured exit conditions, ones the agent can evaluate unambiguously rather than interpret loosely, prevent the agent from deciding it is done before it actually is. The harness is the engineering that separates a loop that ships from one that only works in demos.