Agent-written Durable Objects, without the five-figure invoice
Coding agents now write Durable Object code on the first try — including alarm loops that reportedly billed $34k in eight days with zero users, and one agent-written loop at $10,811. The fix is not slower agents; it is guardrails the code cannot talk its way past.
How agent-written DO code burns money
Unconditional alarm re-arm: setAlarm() in onAlarm() with no terminal condition bills a request + row write per tick, forever, user or no user.
Duration without hibernation: accept()ed WebSockets that never hibernate accrue wall-clock duration (128MB-priced) for the entire connection — Cloudflare's own chat example is $143/mo unhibernated vs $21 hibernated.
Storage surprise: SQLite-backed DO storage has billed rows since Jan 2026 (writes 50M/mo included, then $1/M) — code that logs everything is a meter, not a notebook.
Rules to paste into your agent's instructions
Never write an alarm that re-arms itself unconditionally: exponential backoff, a terminal condition, and a hard max-iteration cap — or don't use alarms.
Use the WebSocket Hibernation API for idle sockets; test with zero users for 24h and read the bill before calling it done.
Set a Durable Objects spending limit (requests/duration/storage) before first real traffic — seatbelt first, optimizations second.
Bound every write loop: counters, caps, and idempotent handlers. If it retries, it needs a budget.
The productized answer
FluxyChat rooms move the dangerous parts out of generated code entirely: the room Durable Object is product code (hibernation, fan-out, replay), plan quotas are enforced Worker-side before Cloudflare meters anything (402 quota_exceeded at the limit, 80% warnings in /billing), and agent runs persist partials to D1 and resume on the next invoke instead of retrying blindly. Your agent writes the app; the room's economics are not its to improvise.
Skill guardrails: the public FluxyChat SKILL.md (fluxychat.com/SKILL.md) instructs coding agents on exactly these rules — alarm loops included — before they write a line.
MCP surface is authenticated and room-scoped: agents operate rooms through tools (list_rooms, send_message, search_chat), not raw socket code.
Self-host keeps the same quotas and adds Cloudflare's native spend limit as the outer guardrail.
Review checklist for agent-generated DO code
Search the diff for setAlarm: who re-arms it, what stops it, what's the max tick count?
Search for accept(): hibernation API or duration bill?
Search for puts/writes in loops: what's the per-event row cost at your message volume?
Ask the agent to write the zero-user 24h test (alarm + idle socket) and show the estimated meters.
Confirm the spend limit exists in the account before the demo touches production.
Production next step
FluxyChat packages the same stack: RoomDurableObject, D1 history, multi-tenant JWT, reconnect-aware SDK, and operator console. MIT self-host or hosted beta.