OpenClaw Serverless AI Assistant on Cloudflare Workers
Run OpenClaw personal AI assistant on Cloudflare Workers Sandbox. Multi-platform gateway with device pairing, persistent storage, and serverless deployment
Originally published:
OpenClaw on Cloudflare Workers: Serverless AI Assistant Sandbox
OpenClaw (formerly Moltbot) is a personal AI assistant platform with a gateway architecture designed to connect multiple chat interfaces—Telegram, Discord, Slack, and more—through a unified control hub. This project demonstrates how to run OpenClaw entirely within Cloudflare Sandbox containers on Workers, eliminating the need for traditional self-hosting while maintaining full agent capabilities and persistent conversation history.
Purpose and Significance
OpenClaw addresses a critical gap in the AI assistant ecosystem: most personal AI tools require either expensive cloud infrastructure or complex self-hosting setups. By running in Cloudflare Sandbox, OpenClaw becomes accessible to developers who want an always-on, multi-platform AI gateway without managing servers. The architecture separates the AI agent runtime from platform-specific connectors, making it trivial to add new chat integrations or extend agent capabilities through skills and workspace extensions.
Key Features
- Multi-platform Gateway — Single unified interface controlling Telegram, Discord, Slack, and web-based UI simultaneously
- Device Pairing Authentication — Explicit approval required for each new device before access, with optional gateway token for remote connectivity
- Persistent Conversations — Chat history and context maintained across container restarts using optional Cloudflare R2 storage
- Agent Runtime — Extensible skill system and workspace capabilities powered by Claude via Anthropic API or Cloudflare AI Gateway
- Cloudflare Access Integration — Built-in Zero Trust security for admin UI and API endpoints
- Browser Rendering — Native Cloudflare Browser Rendering support for web automation tasks
- Zero Configuration Option — Works immediately with minimal secrets setup; optional R2, AI Gateway, and custom Access policies available for advanced deployments
Getting Started
Prerequisites: Cloudflare Workers Paid plan ($5/month minimum for Sandbox access), Anthropic API key or AI Gateway setup, and Node.js/npm installed.
Basic Deployment:
# Install dependencies
npm install
Set Anthropic API key
npx wrangler secret put ANTHROPIC_API_KEY
Generate gateway token
export MOLTBOT_GATEWAY_TOKEN=$(openssl rand -hex 32)
npx wrangler secret put MOLTBOT_GATEWAY_TOKEN
Deploy
npm run deploy
Access your Control UI at https://your-worker.workers.dev/?token=YOUR_GATEWAY_TOKEN. First request takes 1-2 minutes while the container initializes.
Essential Next Steps: Enable Cloudflare Access on your worker domain to protect the admin UI at /_admin/, then approve your device via the admin panel before the Control UI becomes fully functional. Optionally enable R2 storage for persistence across restarts.
Local Development
Create a .dev.vars file with DEV_MODE=true to skip authentication and device pairing during testing. Set DEBUG_ROUTES=true to enable debug endpoints at /debug/*.
Authentication Architecture
OpenClaw uses a layered authentication model. Device pairing is the primary security mechanism—new devices remain pending until an admin explicitly approves them via /_admin/. The gateway token provides remote access control for the web UI and WebSocket connections. Cloudflare Access adds a Zero Trust identity layer protecting admin and API routes. For local development, DEV_MODE bypasses all authentication entirely.
Persistent Storage with R2
By default, paired devices and conversation history are ephemeral and lost when containers restart. Binding an R2 bucket enables durable storage across deployments. This is optional but strongly recommended for production use cases where conversation continuity matters.
API Gateway Options
The project supports both direct Anthropic API access and Cloudflare's AI Gateway. AI Gateway provides unified billing, request routing, caching, and analytics—useful for multi-tenant deployments or organizations already using Cloudflare Zero Trust. Set AI_GATEWAY_API_KEY and AI_GATEWAY_BASE_URL to route Claude requests through the gateway instead of calling Anthropic directly.
Who This Is For
- Full-stack developers exploring serverless AI deployment patterns and edge computing
- Teams wanting a self-controlled AI assistant that doesn't require external SaaS subscriptions for core infrastructure
- Cloudflare users who already invest in Workers, Zero Trust, and R2, seeking integrated AI capabilities
- Multi-platform power users needing a single AI interface that bridges Telegram, Discord, and Slack
- Researchers and experimenters testing novel approaches to serverless AI workloads
Technology Stack
Built entirely in TypeScript and deployed as a Cloudflare Worker with Sandbox container support. The project includes test infrastructure via Vitest and end-to-end testing. Browser automation uses Cloudflare's native Browser Rendering API. Authentication is handled through Cloudflare Access and custom JWT validation.
Contributing and Support
The project includes a CONTRIBUTING.md guide and AGENTS.md documentation for extending agent capabilities. It's licensed under Apache 2.0, permitting commercial and private use. Since this is experimental, check the GitHub issues and discussions for community support—official Cloudflare support is not available for Sandbox-based deployments.
Resources and Links
- GitHub Repository — Source code, issues, and contributions
README.md— Complete setup and deployment guideCONTRIBUTING.md— Developer guidelines and architecture notesAGENTS.md— Agent capabilities and skill extension documentation- Cloudflare Workers Docs — Official platform documentation Cloudflare Workers
- Cloudflare Sandbox — Container runtime details
- Anthropic API — Claude model access
Source: GitHub repository hoanglt1223/moltbot-sandbox; Apache 2.0 licensed, last updated February 2026.
Original Source
https://github.com/hoanglt1223/moltbot-sandbox
Last updated: