Skip to Content
DeploymentCloudflare Workers

Cloudflare Workers Deployment

Deploy OpenClaw on Cloudflare’s edge network using the moltworker container runtime.

Overview

ItemValue
Repositorygithub.com/strataga/moltworker 
Monthly Cost~$5 (Workers) + API costs
Setup Time5-10 minutes
Control UI/_admin/

We recommend the strataga/moltworker fork instead of the official cloudflare/moltworker. The fork adds public webhook routes required for Slack and Discord integrations.

Architecture

Cloudflare Workers ┌─────────────────────────────────────────────────────────┐ │ │ │ ┌───────────────┐ ┌─────────────────────────────┐ │ │ │ Hono Router │───▶│ Public Routes (no auth) │ │ │ │ │ │ - /slack/events │ │ │ │ │ │ - /slack/interactions │ │ │ │ │ │ - /discord/interactions │ │ │ │ │ │ - /telegram-webhook │ │ │ │ │ └─────────────────────────────┘ │ │ │ │ │ │ │ │ ┌─────────────────────────────┐ │ │ │ │───▶│ Protected Routes (CF Access)│ │ │ │ │ │ - /_admin/* │ │ │ │ │ │ - /api/* │ │ │ └───────────────┘ └─────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────┐ │ │ │ Sandbox Container│ │ │ │ (OpenClaw Gateway)│ │ │ │ Port 18789 │ │ │ └─────────────────┘ │ │ │ └─────────────────────────────────────────────────────────┘

Prerequisites

  • Cloudflare account with Workers Paid plan ($5/mo)
  • Anthropic API key
  • Node.js 18+ installed locally
  • Wrangler CLI (npm install -g wrangler)

Deployment Steps

Clone the Repository

git clone https://github.com/strataga/moltworker.git cd moltworker npm install

Configure Worker Name

Edit wrangler.jsonc to set your worker name:

{ "name": "your-worker-name", // Change this // ... rest of config }

Build and Deploy

npm run build npx wrangler deploy

Configure Secrets

Required secrets:

npx wrangler secret put ANTHROPIC_API_KEY npx wrangler secret put MOLTBOT_GATEWAY_TOKEN npx wrangler secret put CF_ACCESS_TEAM_DOMAIN npx wrangler secret put CF_ACCESS_AUD

Set Up Cloudflare Access

  1. Go to Zero Trust Dashboard 
  2. Create an Access Application for your worker
  3. Set path to /_admin/* (NOT /)
  4. Configure authentication (email OTP is simplest)
  5. Note the Application Audience (AUD) tag
  6. Add the AUD to secrets: CF_ACCESS_AUD

Messaging Integrations

Slack works reliably with moltworker. Use HTTP Mode (not Socket Mode).

Create Slack App

  1. Go to api.slack.com/apps 
  2. Create a new app from scratch
  3. Select your workspace

Enable Event Subscriptions

  • Request URL: https://YOUR-WORKER.workers.dev/slack/events
  • Subscribe to bot events:
    • message.channels
    • message.im
    • app_mention

Enable Interactivity

  • Request URL: https://YOUR-WORKER.workers.dev/slack/interactions

Add OAuth Scopes

Under “OAuth & Permissions”, add:

  • chat:write
  • channels:history
  • im:history
  • users:read

Install and Configure

  1. Install app to workspace
  2. Copy Bot Token (starts with xoxb-)
  3. Add to Worker secrets:
npx wrangler secret put SLACK_BOT_TOKEN

Discord

Create Discord Application

  1. Go to discord.com/developers 
  2. Create a new application

Configure Interactions Endpoint

  • URL: https://YOUR-WORKER.workers.dev/discord/interactions

Add Bot to Server

  1. Generate OAuth2 URL with bot scope
  2. Select required permissions
  3. Authorize in your server

Add Secret

npx wrangler secret put DISCORD_BOT_TOKEN

Telegram (Limited Support)

Telegram has fundamental limitations on Cloudflare Workers due to container hibernation. For reliable Telegram support, use VPS deployment.

Why Telegram is unreliable:

  1. OpenClaw uses long-polling by default for Telegram
  2. Cloudflare containers hibernate when idle
  3. Hibernated containers can’t receive poll responses
  4. New messages can’t wake the container

If you must use Telegram:

Set the webhook manually:

curl -X POST "https://api.telegram.org/bot<TOKEN>/setWebhook" \ -H "Content-Type: application/json" \ -d '{"url": "https://YOUR-WORKER.workers.dev/telegram-webhook"}'

Do NOT set TELEGRAM_DM_POLICY - it causes gateway crashes.

Environment Variables

Required

VariableDescription
ANTHROPIC_API_KEYClaude API key
MOLTBOT_GATEWAY_TOKENToken for Control UI access
CF_ACCESS_TEAM_DOMAINCloudflare Access team domain
CF_ACCESS_AUDCloudflare Access application audience

Optional

VariableDescription
SLACK_BOT_TOKENSlack bot token (xoxb-…)
DISCORD_BOT_TOKENDiscord bot token
TELEGRAM_BOT_TOKENTelegram bot token (limited support)
DEV_MODESet to ‘true’ to skip auth (local dev only)
SANDBOX_SLEEP_AFTERDuration before sleep (‘never’, ‘10m’, ‘1h’)

Cost Breakdown

ItemMonthly Cost
Cloudflare Workers (Paid plan)$5
Anthropic API (Claude Sonnet)$10-50 (usage-based)
R2 Storage (optional)~$0.015/GB
Total~$15-55/mo

Troubleshooting

See Troubleshooting for common issues and solutions.