How to Run Your Own AI Agent on Cloudflare for $5 (No Servers Required)
Letās be real: paying $20/month for every AI tool adds up fast. But what if you could run your own powerful, personalized AI assistant for just $5 a month?
Thatās exactly what OpenClaw (formerly Moltbot) allows you to do. Itās an open-source AI agent that runs entirely on Cloudflare Workers. Itās fast, itās private, and you own the data. Best of all, you donāt need to manage a bulky serverāCloudflareās edge network handles everything.
Whether you prefer clicking buttons (No-Code) or typing commands (Code), Iāve got you covered. Here is the complete guide to setting it up.
š The Essentials (You need these first)
Before we start, make sure you have:
- A Cloudflare Account: Youāll need the Workers Paid Plan ($5/mo). The free tier wonāt cut it because the AI container needs a bit more juice (CPU limits).
- An Anthropic API Key: This is the ābrain.ā Get it from Anthropicās console.
- Git Account: (GitHub or GitLab) to save your workerās code.
š£ļø Choose Your Path
Option A: The āSpeed Runā (No-Code / Low-Code)
Best if you want to get up and running in 5 minutes without touching a terminal.
1. The One-Click Deploy
Click the button below to instantly clone the project into your Cloudflare account.

Follow the prompts to connect your GitHub account and click āSave and Deploy.ā
(Note: The first deploy might show an error. Relax, thatās normalāwe havenāt given it the passwords yet!)
2. Add Your Secrets
Go to your Cloudflare Dashboard, find your new Worker (usually named moltworker), and navigate to Settings ā Variables and Secrets.

Click Add and input these:
ANTHROPIC_API_KEY: Your key starting withsk-ant....MOLTBOT_GATEWAY_TOKEN: A made-up password (long and random!) that you will use to log in.
3. Add Storage (Donāt let it get amnesia)
To make sure your bot remembers chats after a restart:
- Go to R2 on the left sidebar and create a bucket named
moltbot-data. - Back in your Workerās Settings ā Variables and Secrets, scroll to R2 Bucket Bindings.
- Click Add Binding. Name the variable
BUCKETand select yourmoltbot-databucket.
4. Redeploy
Go to the Deployments tab and click Redeploy to save your changes.
Option B: The āVibe Coderā Route (CLI)
Best if you love the terminal and want full control.
1. Clone the Repo
Fire up your terminal and grab the code:
git clone https://github.com/cloudflare/moltworker.git
cd moltworker
npm install
2. Set Your Secrets
Instead of the dashboard, we use wrangler to securely upload your keys.
# 1. The Brain
npx wrangler secret put ANTHROPIC_API_KEY
# (Paste your key when prompted)
# 2. The Gatekeeper (Generate a random token)
openssl rand -hex 32
# Copy this output!
npx wrangler secret put MOLTBOT_GATEWAY_TOKEN
# (Paste the token you just generated)
3. Deploy
Push it live!
npm run deploy
š The Critical Step: Security (Both Paths)
This is where most people get stuck, so read carefully! We need to lock the admin panel (/_admin) so random bots donāt hijack your agent. We use Cloudflare Access (Zero Trust) for this.
-
Enable Access:
- Go to your Worker ā Settings ā Domains & Routes.
- Find the
workers.devsection and click Enable Cloudflare Access. - Follow the prompts to create a āTeamā if you havenāt already.
-
Get the Keys:
Once enabled, you will see an Audience Tag (AUD) on that screen. COPY IT.
You also need your Team Domain (e.g.,my-team.cloudflareaccess.com), found in the Zero Trust Dashboard (SettingsāCustom Pages). -
Update the Worker:
-
No-Code Users: Go back to Settings ā Variables and add two new secrets:
CF_ACCESS_AUDandCF_ACCESS_TEAM_DOMAIN. -
CLI Users: Run:
npx wrangler secret put CF_ACCESS_AUD npx wrangler secret put CF_ACCESS_TEAM_DOMAIN
-
-
Final Redeploy: Hit deploy one last time to lock everything down.
š Launch Time
Youāre done! Here is how to access your new AI employee.
-
Construct your URL:
It will look like this:
https://your-worker-name.your-subdomain.workers.dev/?token=YOUR_GATEWAY_TOKEN
(ReplaceYOUR_GATEWAY_TOKENwith that long random password you created earlier). -
Log In:
Youāll be hit with a Cloudflare Access screen. Enter your email, get the code, and youāre in. -
Pair Devices:

Want to connect a terminal or a different browser? Go tohttps://.../workers.dev/_adminto approve new devices.
š” Pro Tips for a Smooth Ride
- Cold Starts: If the page hangs for ~30 seconds the first time, donāt panic. The container is just waking up.
- Cost Control: This runs on the $5 Workers plan, but R2 storage and AI usage might add pennies. Itās still cheaper than a $20 subscription!
- Custom Domain: Use the āTriggersā tab in Cloudflare to connect
ai.yourdomain.comfor a more professional feel.

Happy building! š ļø