Run OpenClaw, (formerly Moltbot, formerly Clawdbot) on Cloudflare Workers
Run OpenClaw, (formerly Moltbot, formerly Clawdbot) on Cloudflare Workers
Run OpenClaw (formerly Moltbot, formerly Clawdbot) personal AI assistant in a Cloudflare Sandbox.
Experimental: This is a proof of concept demonstrating that OpenClaw can run in Cloudflare Sandbox. It is not officially supported and may break without notice. Use at your own risk.
The following Cloudflare features used by this project have free tiers:
This project uses a standard-1 Cloudflare Container instance (1/2 vCPU, 4 GiB memory, 8 GB disk). Below are approximate monthly costs assuming the container runs 24/7, based on Cloudflare Containers pricing:
| Resource | Provisioned | Monthly Usage | Included Free | Overage | Approx. Cost |
|---|---|---|---|---|---|
| Memory | 4 GiB | 2,920 GiB-hrs | 25 GiB-hrs | 2,895 GiB-hrs | ~$26/mo |
| CPU (at ~10% utilization) | 1/2 vCPU | ~2,190 vCPU-min | 375 vCPU-min | ~1,815 vCPU-min | ~$2/mo |
| Disk | 8 GB | 5,840 GB-hrs | 200 GB-hrs | 5,640 GB-hrs | ~$1.50/mo |
| Workers Paid plan | $5/mo | ||||
| Total | ~$34.50/mo |
Notes:
SANDBOX_SLEEP_AFTER (e.g., 10m) so the container sleeps when idle. A container that only runs 4 hours/day would cost roughly ~$5-6/mo in compute on top of the $5 plan fee.lite at 256 MiB/$0.50/mo memory or standard-4 at 12 GiB for heavier workloads).OpenClaw (formerly Moltbot, formerly Clawdbot) is a personal AI assistant with a gateway architecture that connects to multiple chat platforms. Key features:
This project packages OpenClaw to run in a Cloudflare Sandbox container, providing a fully managed, always-on deployment without needing to self-host. Optional R2 storage enables persistence across container restarts.
Cloudflare Sandboxes are available on the Workers Paid plan.
…After deploying, open the Control UI with your token:
https://your-worker.workers.dev/?token=YOUR_GATEWAY_TOKENReplace your-worker with your actual worker subdomain and YOUR_GATEWAY_TOKEN with the token you generated above.
Note: The first request may take 1-2 minutes while the container starts.
Important: You will not be able to use the Control UI until you complete the following steps. You MUST:
- Set up Cloudflare Access to protect the admin UI
- Pair your device via the admin UI at
/_admin/
You'll also likely want to enable R2 storage so your paired devices and conversation history persist across container restarts (optional but recommended).
To use the admin UI at /_admin/ for device management, you need to:
The easiest way to protect your worker is using the built-in Cloudflare Access integration for workers.dev:
moltbot-sandbox)workers.dev row, click the meatballs menu (...)CF_ACCESS_AUD in Step 2 belowAfter enabling Cloudflare Access, set the secrets so the worker can validate JWTs:
# Your Cloudflare Access team domain (e.g., "myteam.cloudflareaccess.com")
npx wrangler secret put CF_ACCESS_TEAM_DOMAIN
# The Application Audience (AUD) tag from your Access application that you copied in the step above
npx wrangler secret put CF_ACCESS_AUDYou can find your team domain in the Zero Trust Dashboard under Settings > Custom Pages (it's the subdomain before .cloudflareaccess.com).
npm run deployNow visit /_admin/ and you'll be prompted to authenticate via Cloudflare Access before accessing the admin UI.
If you prefer more control, you can manually create an Access application:
moltbot-sandbox.your-subdomain.workers.dev)/_admin/*, /api/*, /debug/*For local development, create a .dev.vars file with:
DEV_MODE=true # Skip Cloudflare Access auth + bypass device pairing
DEBUG_ROUTES=true # Enable /debug/* routes (optional)By default, moltbot uses device pairing for authentication. When a new device (browser, CLI, etc.) connects, it must be approved via the admin UI at /_admin/.
/_admin/This is the most secure option as it requires explicit approval for each device.
A gateway token is required to access the Control UI when hosted remotely. Pass it as a query parameter:
https://your-worker.workers.dev/?token=YOUR_TOKEN
wss://your-worker.workers.dev/ws?token=YOUR_TOKENNote: Even with a valid token, new devices still require approval via the admin UI at /_admin/ (see Device Pairing above).
For local development only, set DEV_MODE=true in .dev.vars to skip Cloudflare Access authentication and enable allowInsecureAuth (bypasses device pairing entirely).
By default, moltbot data (configs, paired devices, conversation history) is lost when the container restarts. To enable persistent storage across sessions, configure R2:
moltbot-data bucket (created automatically on first deploy)# R2 Access Key ID
npx wrangler secret put R2_ACCESS_KEY_ID
# R2 Secret Access Key
npx wrangler secret put R2_SECRET_ACCESS_KEY
# Your Cloudflare Account ID
npx wrangler secret put CF_ACCOUNT_IDTo find your Account ID: Go to the Cloudflare Dashboard, click the three dots menu next to your account name, and select "Copy Account ID".
R2 storage uses a backup/restore approach for simplicity:
On container startup:
During operation:
/_admin/In the admin UI:
Without R2 credentials, moltbot still works but uses ephemeral storage (data lost on container restart).
By default, the sandbox container stays alive indefinitely (SANDBOX_SLEEP_AFTER=never). This is recommended because cold starts take 1-2 minutes.
To reduce costs for infrequently used deployments, you can configure the container to sleep after a period of inactivity:
npx wrangler secret put SANDBOX_SLEEP_AFTER
# Enter: 10m (or 1h, 30m, etc.)When the container sleeps, the next request will trigger a cold start. If you have R2 storage configured, your paired devices and data will persist across restarts.
Access the admin UI at /_admin/ to:
The admin UI requires Cloudflare Access authentication (or DEV_MODE=true for local development).
Debug endpoints are available at /debug/* when enabled (requires DEBUG_ROUTES=true and Cloudflare Access):
GET /debug/processes - List all container processesGET /debug/logs?id=<process_id> - Get logs for a specific processGET /debug/version - Get container and moltbot version infonpx wrangler secret put TELEGRAM_BOT_TOKEN
npm run deploynpx wrangler secret put DISCORD_BOT_TOKEN
npm run deploynpx wrangler secret put SLACK_BOT_TOKEN
npx wrangler secret put SLACK_APP_TOKEN
npm run deployThis worker includes a Chrome DevTools Protocol (CDP) shim that enables browser automation capabilities. This allows OpenClaw to control a headless browser for tasks like web scraping, screenshots, and automated testing.
npx wrangler secret put CDP_SECRET
# Enter a secure random stringnpx wrangler secret putWebSocket proxy throws when forwarding reserved close code 1006
Please enable R2 through the Cloudflare Dashboard.
No OAuth option for ChatGPT Plus / Codex subscription — only API key is available
Possible complementary direction: post-task skill lifecycle management with SkillClaw
Security findings from ClawGuard static analysis
Security scan available for cloudflare/moltworker
R2不能自动保存
Please add availabilty to change to Moonshot Kimi K2.5
brew not installed
Container doesn't start anymore