Skip to content

Deploy Moltworker: Cloudflare AI Agent Setup Guide

A hands-on install guide for Moltworker, Cloudflare's proof-of-concept AI agent - real commands, real costs, real errors from the community tracker.

9 min readIntermediate

Most tutorials about the Cloudflare AI agent project called Moltworker rush you through git clone and npm run deploy without answering the one question that actually matters: is this thing going to cost you $5 a month or $40? The answer depends on a single environment variable that nobody flags until after you’ve deployed. So let’s start there and work backward into the install.

Moltworker is Cloudflare’s proof-of-concept for running a self-hosted personal AI assistant on their edge. It’s a middleware Worker that runs Moltbot on Cloudflare’s Sandbox SDK – so you can self-host an AI personal assistant without new hardware. It’s a proof of concept, not a Cloudflare product, which matters. You’re deploying an experiment. It will change.

Should you actually deploy Moltworker?

Before touching a terminal, look at the bill. You’ll need a Cloudflare account and a Workers Paid plan to access Sandbox Containers – $5/month as the entry ticket (as of this writing; check current Workers pricing). That’s the easy part.

The container itself is where the math gets real. Containers are billed per 10ms of active runtime. The $5/month plan includes 25 GiB-hours of memory, 375 vCPU-minutes, and 200 GB-hours of disk (check current Containers pricing – these figures were accurate at the time of writing). Sounds generous until you look at Moltworker’s default config.

The container runs 24/7. That’s the default. The SANDBOX_SLEEP_AFTER setting ships as never – always running – which blows past every included allotment within days. Based on Cloudflare Containers pricing, a 24/7 sandbox runs approximately $34.50/month on top of the $5 base (per DeepWiki’s analysis of the repo). Nobody in the top tutorials mentions this. They should.

Setup Monthly cost (approx.) Trade-off
Default (always-on) ~$39.50 Instant response after first boot
SANDBOX_SLEEP_AFTER set to a few minutes $5 + light overage 1-2 min cold start per idle period
Free tier alone Impossible Containers are paid-only

If your assistant sits idle most of the day, opt into sleep. If it’s genuinely always-on, budget for it.

There’s a broader question lurking here: who is Moltworker actually for, right now? It’s not a polished SaaS. It’s closer to a reference implementation – Cloudflare showing what their Sandbox Containers and Developer Platform APIs can do when assembled together. That framing matters for your expectations. If you want a personal AI assistant that just works, this probably isn’t your shortest path. If you want to understand how persistent AI agents run on edge infrastructure – and you’re comfortable with an experiment that could shift under you – this is genuinely interesting to poke at.

System requirements and account setup

Local requirements are light – this deploys to Cloudflare’s edge, not your machine. You need Node.js (current LTS recommended), npm, git, and the Wrangler CLI (installed automatically via npx). Any modern macOS, Linux, or Windows box works.

The Cloudflare side is where the gates are:

  • Cloudflare account with Workers Paid plan enabled (~$5/mo, as of this writing)
  • Containers enabled in the dashboard (Workers & Pages → Containers) – this is a manual toggle, easy to miss
  • An Anthropic API key or a Cloudflare AI Gateway with a configured provider
  • Optional: R2 bucket for persistence, Cloudflare Access for admin route protection

One constraint the marketing pages don’t advertise: Cloudflare Containers is Linux/amd64 only – no ARM support as of this writing. Your local docker build on an M-series Mac still works because deployment happens in Cloudflare’s build environment, but keep this in mind if you plan to test the Dockerfile locally.

Install Moltworker step by step

The repo (github.com/cloudflare/moltworker, roughly 9.9k stars and 1.8k forks as of mid-2025) is the canonical source. Clone, install, authenticate, set secrets, deploy.

# 1. Grab the repo
git clone https://github.com/cloudflare/moltworker.git
cd moltworker

# 2. Install
npm install

# 3. Authenticate Wrangler against your Cloudflare account
npx wrangler login

# 4. Set the AI provider secret (simplest path: direct Anthropic)
npx wrangler secret put ANTHROPIC_API_KEY
# paste your sk-ant-... key when prompted

# 5. Generate and store a gateway token for the Control UI
export MOLTBOT_GATEWAY_TOKEN=$(openssl rand -base64 32 | tr -d '=+/' | head -c 32)
echo "Save this token: $MOLTBOT_GATEWAY_TOKEN"
npx wrangler secret put MOLTBOT_GATEWAY_TOKEN

# 6. Deploy
npm run deploy

Routing through Cloudflare AI Gateway – recommended if you want cost tracking and observability – swaps three secrets in place of ANTHROPIC_API_KEY: CLOUDFLARE_AI_GATEWAY_API_KEY, CF_AI_GATEWAY_ACCOUNT_ID, and CF_AI_GATEWAY_GATEWAY_ID, all required (OpenClaw constructs the gateway URL from the account and gateway IDs). When AI Gateway is configured, the default model is Anthropic’s Claude Sonnet 4.5 – correct as of this writing, but check the README for any updates.

Before npm run deploy, open the Containers section of the Cloudflare dashboard and confirm Containers is enabled. Skip this and you’ll watch a build succeed, then fail at runtime with an Unauthorized error – about 3-5 minutes wasted.

Verify it actually works

After deploy finishes, Wrangler prints your Worker URL (something like moltworker.your-subdomain.workers.dev). The Control UI is gated by the token you generated.

# Health check - expect a JSON response
curl https://moltworker.your-subdomain.workers.dev/health

# Open the Control UI (paste the token you saved earlier)
# https://moltworker.your-subdomain.workers.dev/?token=YOUR_MOLTBOT_GATEWAY_TOKEN

The gateway token is passed via ?token= query parameter (the README is explicit about this – keep it out of your browser history). First request is where the surprise hits: cold starts take 1-2 minutes. That’s not a typo. If your curl command times out at 60 seconds, extend the timeout or hit the endpoint from a browser tab that will wait. HTTP clients with default 30-60s timeouts will simply error out on a cold container.

Once in the UI, you’ll pair devices. Each device – browser, CLI, chat platform DM – needs explicit approval through the admin UI before it can interact with the assistant. That’s the default pairing policy.

Errors to know before they find you

The Cloudflare Community forum thread on Moltworker is the fastest real-world signal for what breaks. Here’s what shows up repeatedly.

“Missing Variables CF_ACCESS_AUD, ANTHROPIC_API_KEY or AI_GATEWAY_API_KEY” – deploy succeeded; runtime can’t find your secrets. Run wrangler secret put <VARIABLE_NAME> for each missing one, then refresh. If you’re using Cloudflare Access for the admin route, double-check secret formats against the README exactly – small format errors here cause confusing failures.

“npm run dev fails with Unauthorized” – you need to enable Cloudflare Containers in the Containers dashboard. Do this before touching the CLI again.

Config changes don’t apply after redeploy – this one stings. Turns out Docker is caching your image and serving the old one. The fix: edit the # Build cache bust: comment in the Dockerfile, bump the version marker, redeploy. Wrangler won’t tell you it’s using a cached image – you just see your old behavior.

R2 persistence looks fine locally – because local R2 doesn’t actually do anything. Docs say R2 mounting works; just not with wrangler dev. The mount only activates in production. Local testing gives you a silent no-op, which is worse than an error. Verify R2 secrets are set per the README, then test persistence only against your deployed Worker.

WebSockets fail in local dev. HTTP works through the sandbox proxy; WebSockets don’t – the README calls this out directly. Real-time features need a full production deploy to test. Don’t spend time debugging WebSocket errors on localhost:8787.

A legitimate open question at this stage: the community forum shows a pattern of new environment variables appearing in the README without clear announcements. Whether Cloudflare plans to formalize a changelog or migration guide for this project isn’t documented anywhere. If you run Moltworker long-term, monitoring the README diff on each git pull is the closest thing to a release note you’ll get.

Upgrading and uninstalling

Upgrades: git pull, then treat it like a breaking change. Check the README diff for new required secrets before running npm install && npm run deploy. Config refusing to stick? Same Dockerfile cache-bust trick from the errors section – bump the comment, force a rebuild.

Uninstalling is fast:

# Delete the Worker and its Durable Object bindings
npx wrangler delete moltworker

# Optional: revoke secrets from the Cloudflare dashboard
# Workers & Pages → moltworker → Settings → Variables and Secrets

# Optional: delete the R2 bucket if you created one
# R2 → your-bucket → Settings → Delete bucket

# Optional: downgrade the Workers plan if this was your only paid Worker
# Dashboard → Workers & Pages → Plans

That last step is the one people forget. The $5/month Workers Paid subscription keeps billing whether Moltworker exists or not – cancel it explicitly if you’re done experimenting.

Where to go next

The most useful thing after your first successful deploy isn’t building integrations – it’s opening wrangler.jsonc and setting SANDBOX_SLEEP_AFTER to something like 5m. That single change is worth roughly $30/month if you’re not running the assistant around the clock. Then check the official Moltworker announcement post and the Containers pricing docs to model your actual usage. If you’re curious about the broader agent framework Cloudflare is building around this – Agents SDK, Durable Objects, MCP – the Cloudflare Agents docs are where that lives.

FAQ

Is Moltworker safe to run in production?

No. Cloudflare has been explicit: it’s an experiment to showcase Sandbox Containers and the Developer Platform. Personal projects only.

Can I run Moltworker entirely on Cloudflare’s free tier?

No free path exists. Sandbox Containers require the Workers Paid plan – the container runtime isn’t available on free accounts, full stop. Say you’re a developer testing this over a weekend: you’re looking at $5 minimum, almost certainly more once the container starts running. If cost is the hard constraint, the Cloudflare Agents SDK using Workers AI without containers is a different approach – though what your agent can actually execute is more limited, and that trade-off is worth understanding before you start building.

Which AI model does Moltworker use by default?

Claude Sonnet 4.5, routed through Cloudflare AI Gateway when configured. Check the README for the current default – model names in this space move fast.