AI Agent 跑在 Durable Objects 上,对比常开容器
bigdatachads 对比了 Cloudflare 的 Moltworker(把 Agent 放在 Sandbox 容器里)和他直接基于 Workers 与 Durable Objects 构建的 Agent,认为对个人 Agent 来说,为避免冷启动而 24 小时常开的容器,比按请求计费的 Durable Objects 贵得多。数字为作者估算。
- 适用产品
- Durable ObjectsContainersWorkersBrowser Rendering
- 来源
- 作者经验𝕏 文章
- 作者
- bigdatachads(@bigdatachads)
要点
- 他指出 Moltworker 首次请求要等一到两分钟容器启动,其 README 建议让容器 24 小时运行;按 Moltworker 自己的估算,每月约 $34.50($5 Workers 方案,加约 $26 内存、$2 CPU、$1.50 磁盘)。
- 他的原生方案把状态放在 SQLite 后端的 Durable Objects 里,使用 WebSocket Hibernation API,只在用到浏览器工具时从 Durable Object 直接调用 Browser Rendering,容器只用于执行代码、空闲五分钟后休眠,因此不用时整个架构都处于空闲。
- 他对每天 50 次对话的个人 Agent 的估算:每次 10 轮消息的对话基础设施约 $0.02 到 $0.08,另加 AI 服务商费用;基础设施差额为常开容器每月 $29.50,对比 Durable Object 操作 $0.15。他也指出两种方案中 AI 服务商费用都占大头,并随 token 用量变化。
原始来源
发布
原帖
到 𝕏 阅读bigdatachads 对比了 Cloudflare 的 Moltworker(把 Agent 放在 Sandbox 容器里)和他直接基于 Workers 与 Durable Objects 构建的 Agent,认为对个人 Agent 来说,为避免冷启动而 24 小时常开的容器,比按请求计费的 Durable Objects 贵得多。数字为作者估算。
bigdatachads
@bigdatachads · 𝕏 原帖
https://t.co/3cjweX0XBK
阅读全文归档于
bigdatachads · @bigdatachads
MOLTWORKER USES A CONTAINER. I USED DURABLE OBJECTS.
Cloudflare published a blog post about Moltworker, their adaptation of OpenClaw that runs inside a Sandbox container on Workers. I built a multichannel AI agent on Cloudflare. Different architecture. No container for the core runtime. Worth comparing the two approaches. Moltworker takes an existing agent (OpenClaw) and wraps it in a Sandbox container with a Worker as a proxy. My approach builds the agent natively on Workers and Durable Objects, only using containers for code execution. Same platform, opposite design philosophies. The architecture comparison The fundamental difference is where the agent logic lives. Moltworker puts everything in a container and uses Workers as a thin proxy. The native approach puts everything in Workers and Durable Objects, only reaching for containers when the agent needs to run untrusted code. State management is the biggest gap Moltworker stores state on the container filesystem. It mounts R2 as a filesystem partition via sandbox.mountBucket() and runs a cron job every five minutes to back up config data. Containers are ephemeral. When the container restarts between backup cycles, state from that window disappears. The R2 backup is optional but recommended. Users who skip it lose everything on restart. Users who enable it still have a window of up to five minutes where conversation history, device pairings, and memory can vanish. Durable Objects with SQLite solve this at the platform level. SQLite tables handle conversations, messages, persistent memory, devices, pairing requests, scheduled tasks, and installed skills. Every write is durable immediately. No five minute window of potential data loss. No separate R2 bucket to configure. No backup scripts to maintain. Cold starts matter for a personal agent Moltworker’s README is upfront about this. First request takes one to two minutes while the container starts. Their recommendation is to keep the container running 24/7 to avoid it. Running a container 24/7 costs roughly $34.50 per month according to their own estimates. That’s the $5 Workers plan plus $26 in memory, $2 in CPU, and $1.50 in disk. A Durable Object cold starts in milliseconds. The agent runtime wakes instantly. The AI response adds seconds for inference, but the user isn’t waiting two minutes for infrastructure to boot. You pay per request. If nobody messages the agent for three hours, it costs nothing for those three hours. The DO wakes instantly when the next message arrives. For a personal agent that handles maybe 50 conversations a day, the per request model wins by an order of magnitude. Browser automation without the proxy Moltworker’s blog post dedicates an entire section to their CDP proxy. They built a thin proxy layer that pipes Chrome DevTools Protocol commands from the Sandbox container through the Worker to Browser Rendering. Three hops. Container to Worker to headless browser and back. My agent has two browser tools. The stateless tool calls the Cloudflare Browser Rendering REST API directly from the Durable Object. One authenticated fetch. No Puppeteer. No CDP. No container. Cloudflare spins up a headless browser, executes the action, returns the result. Each call is stateless and independent. Seven actions available including markdown extraction, screenshots stored to R2, structured data extraction via Workers AI, and PDF generation. The stateful tool uses @cloudflare/puppeteer with puppeteer.launch(env.BROWSER) directly in the Durable Object. The browser session stays alive across multiple tool calls within a conversation. Login flows, multi step form submission, authenticated scraping. Twelve actions. The DO holds the session reference and cleans up on conversation end. No container involved. Compare to Moltworker where every browser command routes from container to Worker to Browser Rendering. My stateless tool is one hop. My stateful tool connects directly from the DO to the browser instance. What Moltworker does well Credit where it matters. Moltworker solves a real problem. OpenClaw was designed to run locally. People were buying dedicated hardware for a personal assistant. Cloudflare showed you can skip the hardware purchase and run it on their platform for $35 a month instead of $500+ upfront. The AI Gateway integration is worth noting. Swapping the ANTHROPIC_BASE_URL to point at AI Gateway with zero code changes is the kind of thing that makes a platform valuable. I use AI Gateway in my setup too. It’s the right abstraction for provider management. What I would change about Moltworker Move state out of the container. Use Durable Objects with SQLite for conversations, memory, and device pairings. Keep the container for code execution only. This eliminates the R2 backup cron entirely and makes cold starts a non issue for the core agent loop. Split the container from the agent. The agent should respond in milliseconds via a Durable Object. When it needs to run code, it calls out to a Sandbox container. Two concerns, two runtimes. The container can sleep aggressively because it only wakes for heavy tasks. Use the Browser Rendering REST API or Puppeteer binding directly. The CDP proxy adds complexity. Calling the REST API from a Worker or DO gives you stateless browser capabilities without routing commands through a container. For stateful sessions, puppeteer.launch(env.BROWSER) in a DO gives you persistent browser sessions with no proxy layer. Cost The entire architecture hibernates when unused. The DO uses the WebSocket Hibernation API. No browser runs when no browser tools are active. The container sleeps after five minutes of inactivity. The gateway is a stateless Worker. Pages serves static files on the free tier. Per conversation with 10 message exchanges. 20 Worker requests (gateway + agent) 40 Durable Object operations ~10 to 20 AI Gateway calls (1+ per message, more with tool use) 0 container time (unless code execution requested) 0 browser time (unless browser tools requested) Estimated per conversation. $0.02 to $0.08 infrastructure + AI provider cost. Monthly comparison for a personal agent handling 50 conversations per day. All figures are estimates based on published pricing. The AI provider cost dominates in both cases and varies heavily with token usage per call. But the infrastructure delta is significant. $29.50 for an always on container versus $0.15 for Durable Object operations. The native approach scales down to near zero when idle and scales up per request when active. The point Moltworker is a proof of concept and Cloudflare labels it as such. It proves OpenClaw can run on their platform. That’s valuable for the OpenClaw community. But if you’re building an AI agent from scratch on Cloudflare, don’t put the whole runtime in a container. Use Durable Objects for state and conversation management. Use Workers for message routing. Hit the Browser Rendering API directly instead of proxying through a container. Use containers only for the things that actually need a full Linux environment. Millisecond cold starts. Durable state without backup scripts. Zero idle cost. Per request pricing. These aren’t minor optimizations. They’re architectural advantages you get for free by building on the platform instead of running inside it.
其他推荐阅读
Appflare 费用保护:在自己账户里按应用告警并自动暂停
Appflare 是在你自己 Cloudflare 账户里以 Worker 运行的开源(Apache-2.0)应用管理器,新增了费用保护:每 5 分钟读取每个已安装应用的用量,用量异常时告警,并可暂停失控的应用。
Steven Menke:Agents SDK 缺陷,Durable Objects 发票 $1,700。
Steven Menke(@Galorious_)报告 Agents SDK 缺陷导致 Durable Objects 失控,3 天内产生 $1,700 发票,称有 1 万亿次 SQLite 读取(后一帖称写入)。他称支持工单即使经维护者升级,数月仍无回复。
硬上限为何需要时间:Ashley Peacock 谈计费数据延迟
Cloudflare Durable Objects 团队的 Ashley Peacock(@ashleypeacock)从个人经验解释为何接近实时的费用上限难做,称硬性账单上限即将推出,并建议在此之前先配预算告警和问题告警。