How to Stop a Runaway Agent (or a Thousand)
Knowing how to stop a runaway agent matters most when you have already lost track of one. An agent stuck in a loop on your laptop is a nuisance: press Ctrl+C. Two hundred agents in cloud sandboxes, started by another agent, burning tokens on a plan that was wrong from the start, is a different problem. This guide covers how to recognise a runaway, the mechanisms for stopping agents at each scale, and the limits to set before a run begins so that stopping is rarely needed.
What a runaway agent looks like
"Runaway" covers several distinct failures.
- Loops. The agent retries the same failing command, or two agents keep handing the same question back and forth.
- Drift. The agent solves a different problem from the one it was given. GitHub's guide to orchestrating agents tells readers to step in when logs show drift, tests fail or scope creeps.
- Scope creep. It edits files well outside its task.
- Resource runaway. E2B's sandbox workshop lists runaway processes, memory pressure and full disks among the things an operator must handle.
- A wrong plan, multiplied. A planner split the work badly and every worker is doing the wrong thing correctly.
The last is the expensive one, because the damage scales with the number of agents.
How to stop a runaway agent you can see
For a single interactive session:
- Interrupt. Escape or Ctrl+C in the terminal.
- Deny with a reason. If the agent is asking permission, a denial with a note redirects it without ending the session.
- Roll back. Claude Code has checkpoints for rewinding a session's changes, and git covers the rest.
This is the easy case, and built-in tools handle it.
Stopping one agent you cannot see
A background or cloud agent has no terminal to press keys in. You need a control that reaches it.
- The vendor's control. Cognition's managed Devins can be put to sleep or terminated by the coordinating session. Warp says every Oz agent is controllable through a CLI and an API.
- Kill the process or the sandbox. Blunt and reliable, if you have access to the machine.
- A stop hook. Agents with hook systems consult the hook on every step. A hook that receives "stop" from a server can end the session cleanly.
The third option is the most general, because it works wherever the agent runs.
Stopping many agents at once
With dozens or hundreds of agents, stopping them one at a time is too slow. You need a group identity and one action that applies to the group. This is the kill switch.
Forkit's version is the fan-out. When an agent or a person starts many agents, it first creates a fan-out, which mints one short-lived key per agent. All of those keys share the fan-out's fate.
A fan-out stops in four ways:
- The agent that started it calls stop (
POST /api/v1/fanouts/:id/stop, orcodemode.stop_fanout). - A person stops it from the fan-outs page: the starting agent's person, or a workspace owner.
- Its time is up. Keys expire after one hour by default, 24 hours at most.
- Its tool call budget is spent. An optional
max_tool_callsstops the whole fan-out when its agents have made that many tool calls. The count is kept in memory and written in steps, so it can overshoot by a few.
What happens when it stops, according to the documentation:
- Every request made with one of its keys is answered with
403and a body that saysstop: truewith the reason. Only the session's closing events pass, so the thread can end properly. - The Claude Code hook, on receiving that, prints
continue: falsewith the reason, refuses the tool call in hand and remembers the stop for the rest of the session. - The fan-out's pending permission requests are denied.
- Its file claims are released.
- Its working and waiting threads move to idle.
On a staging run described in Forkit's documentation, 200 of 200 agents that had been set to run on were stopped within 4 seconds. That was one run, on staging, with scripted agents.
One thing this does not do: delete the sandboxes. Forkit stops the agents; whatever provisioned the machines has to remove them.
Build the limits in beforehand
Stopping is the last resort. Most runaways can be prevented by limits set at the start.
Expiring keys. An agent whose credentials end in an hour cannot run for a week. Short-lived keys are the simplest guard against forgotten agents.
A tool call budget. Decide roughly how many tool calls the job should need and set the limit above that. A fan-out of 100 agents expected to make 80 calls each might get a budget of 12,000.
A cap on fan-outs. Forkit limits a workspace to 20 running fan-outs, and an agent to starting 10 an hour. A fan-out's own agents cannot start fan-outs, which prevents exponential growth.
Message limits. Loops between agents are bounded by rate limits, a reply depth of eight, and a budget of 20 messages per pair of agents until a person steps in. See how to prevent agent message loops.
Deny on timeout. A headless agent whose permission request goes unanswered should be told no, not left hanging or waved through.
A sandbox. Resource limits and network boundaries contain what a misbehaving process can do.
What Forkit does not offer is a spending limit in money. Its documentation says so: hooks do not report cost. A tool call budget is a proxy, not a dollar cap. Use your model provider's spending controls for that.
Detecting a runaway early
You can only stop what you notice.
- Watch states, not logs. A thread that has been "working" with no new event for a long time is suspicious. Forkit computes "quiet" (working with no event for 30 minutes) when a thread is read.
- Watch for blocked threads. A pair of agents that exhausts its message budget lands in
blocked, which appears in the inbox. - Watch the fan-out's counters. Tool calls used against the limit tell you how far along a job is.
- Read the first few handoffs. If the first three workers return the wrong thing, the other ninety-seven will too. Stop then.
A runbook
- Before starting: set key lifetime, tool call budget and timeout behaviour. Write down who may stop the run.
- Start a small batch first. Read its results.
- Start the rest.
- If the results are wrong: stop the fan-out. Do not try to correct hundreds of agents by message.
- Confirm that threads went idle and claims were released.
- Remove the sandboxes.
- Fix the plan. Start again.
Related: agent fan-out explained and background agents in CI.
Where Forkit fits
Forkit gives a group of agents one identity and one stop action, with limits set when the group is created. It works for Claude Code agents in sandboxes and CI. It is free to try. More at forkit-mcp.com.