← Back to Blog

The $12,000 Infinite Loop: An AI Agent With No Stop Button

By Craig Lowther, Founder · 6 August 2026 · 4 min read · Cost Guard — Runaway AI Spend

A developer built an autonomous agent to run recursively in a sandbox. It had no real exit condition. It kept calling the API, on its own, until the bill hit $12,000 — a forensic case study in what happens when "the agent decides when it's done" is the only stop condition an autonomous system has.

What Happened

Documented in detail as "The $12,000 Infinite Loop: How My AI Agent Bankrupted a Sandbox," this is a first-person account of exactly the failure mode Thuban Cost Guard exists to catch. An autonomous agent was set up to recurse — call itself, process the result, call itself again — without a hard-coded ceiling on how many times that could happen. The agent's own judgement was the only thing standing between "keep going" and "stop." It didn't stop. Each recursive call was another billed API request, compounding for hours before anyone caught it, by which point the sandbox environment had run up a $12,000 tab.

This is a smaller-scale, single-developer version of the same failure that burned $47,000 across a 4-agent LangChain system in a separate incident (see our earlier post on that one) — different framework, different scale, identical root cause.

The Common Thread: No Stop Button

What makes this pattern so dangerous isn't sophistication — it's how ordinary the code looks:

The exact code pattern

// recursive agent loop, no depth limit, no budget guard
async function runAgent(context) {
  const result = await llm.chat.completions.create({
    model: 'gpt-4',
    messages: buildPrompt(context),
  });
  if (!isTaskComplete(result)) {
    return runAgent(updateContext(context, result)); // recurses indefinitely
  }
  return result;
}

No max depth. No token ceiling on the individual call. No budget guard anywhere in the call chain. This compiles, runs, and looks completely reasonable in a pull request — right up until it doesn't stop.

How Thuban Cost Guard Catches This

TCG-101 (Unbounded AI Loop Execution) doesn't care whether the unbounded pattern is a while loop or a self-recursive function — the underlying risk is the same: an AI SDK call with no reachable, bounded exit condition. Cost Guard's static analyzer checks for a genuine iteration cap, budget-guard wrapper, or guarded break before a loop is cleared. If the only thing standing between "call the API" and "stop calling the API" is the model's own output, that's flagged CRITICAL — and if the call inside also has no output token limit set, TCG-201 escalates the combined finding to HIGH.

TCG-101 · Unbounded AI Loop

Catches this exact shape — an AI call with no bounded iteration count and no guarded exit, whether it's a loop or recursion.

TCG-201 · Missing Output Token Limit

Flags the missing max_tokens on the same call — the second half of what turns "wasteful" into "financially serious."

Before it ships

Cost Guard runs in every thuban scan, so this pattern gets caught in code review, not in a bank statement.

Zero config

No flag, no setup. It's part of the same scan you're already running for security and hallucination detection.

Positioning

A sandbox protects your filesystem. It does nothing to protect your bank account. Cost isn't a runtime concern you bolt on later — it's a code review finding, and it should be caught exactly where the rest of your bugs are caught.

Sources

Does your agent code have a real stop button, or just a hopeful one?

Free, no signup, runs entirely locally — your code never leaves your machine.

npx thuban protect

Cost Guard runs automatically in every scan — no extra flag needed.

Thuban Help
Ask a question or pick a topic below.