Skip to main content
Run autonomous Swarms agents on Cloudflare Workers — schedule them with cron triggers, fetch real-time data from external APIs, and dispatch results to email or downstream systems. Workers run in 330+ cities worldwide, giving sub-100ms latency to data sources.

What this pattern is good for

  • Scheduled execution — agents trigger automatically on cron schedules.
  • 📊 Real-time data fetch — pull from Yahoo Finance, news feeds, custom APIs.
  • 🤖 Multi-agent analysis — call the Swarms API with several specialized agents.
  • 📧 Automated actions — email reports, webhook posts, push notifications.
  • 🌍 Global edge — Cloudflare’s network is closer to your users and data sources than a single VM.

Reference implementation

A complete, production-ready stock analysis agent is published at: 🔗 github.com/The-Swarm-Corporation/Swarms-CloudFlare-Deployment The repository ships two implementations: Both implementations cover the same workflow: fetch market data, run multi-agent analysis via the Swarms API, generate a report, send it via email, and expose a small web dashboard for manual triggers.

Architecture

Step 1: Clone and install

Option A — JavaScript

Option B — Python

Step 2: Configure environment

Create a .dev.vars file:
For production, store these as Cloudflare Workers secrets via wrangler secret put.

Step 3: Set the cron schedule

Cron triggers are configured in wrangler.jsonc:
Common patterns: Use crontab.guru to validate expressions.

Step 4: Run locally

Step 5: Deploy

Customization

Stock symbols

In JavaScript:

Custom Swarms agents

Cost notes

  • Cloudflare Workers — free tier covers 100,000 requests/day.
  • Swarms API — monitor usage in the dashboard; switch to gpt-4o-mini for cost-sensitive runs.
  • External APIs — most of the providers listed above (Yahoo Finance, FMP free tier, Mailgun free tier) are free at low volume.

Security checklist

  • Store API keys as Wrangler secrets, never in source.
  • Validate incoming requests + apply per-IP rate limits.
  • Audit AI decisions and persist compliance logs.
  • Use HTTPS for every outbound call.

Troubleshooting

See also