Part 2: Deploy OpenClaw on Fly.io
Fly.io runs your applications on lightweight Firecracker micro-VMs distributed across data centers worldwide. This gives you the control of a traditional server with the convenience of a managed platform. Deploying OpenClaw on Fly.io is well-suited for agents that need low latency, persistent storage, or fine-grained scaling control.
Prerequisites
Before you begin, make sure you have:
- A Fly.io account -- sign up at fly.io. A credit card is required at signup, but the free allowances cover most single-instance deployments.
- The
flyctlCLI installed and authenticated:
# macOS (Homebrew)
brew install flyctl
# Linux
curl -L https://fly.io/install.sh | sh
# Windows (PowerShell)
powershell -Command "iwr https://fly.io/install.ps1 -useb | iex"
# Authenticate with your Fly.io account
fly auth login
- Your OpenClaw project directory with a
package.jsonat the root. - Your API keys ready:
ANTHROPIC_API_KEYand/orOPENAI_API_KEY.
Verify your CLI installation:
fly version
# Output: fly v0.3.x (or later)
Step 1: Initialize the App
Navigate to your OpenClaw project directory and run:
fly launch
The interactive setup will prompt you for:
- App name -- choose something descriptive like
openclaw-agent(must be globally unique on Fly.io). - Organization -- select your personal org or a team org.
- Region -- pick the region closest to you or your users. Common choices:
iad(Virginia),lhr(London),nrt(Tokyo),sea(Seattle). You can deploy to multiple regions later. - Database -- select "No" unless your agent requires a managed database.
This generates a fly.toml configuration file and a Dockerfile in your project root.
Step 2: Configure fly.toml
Edit the generated fly.toml to match your OpenClaw requirements. Here is a complete, production-ready configuration:
# fly.toml -- Fly.io application configuration for OpenClaw
app = "openclaw-agent"
primary_region = "iad"
[build]
dockerfile = "Dockerfile"
[env]
NODE_ENV = "production"
OPENCLAW_LOG_LEVEL = "info"
PORT = "3000"
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 1
processes = ["app"]
[http_service.concurrency]
type = "requests"
hard_limit = 250
soft_limit = 200
[[http_service.checks]]
grace_period = "10s"
interval = "30s"
method = "GET"
path = "/health"
timeout = "5s"
[mounts]
source = "openclaw_data"
destination = "/app/data"
[[vm]]
size = "shared-cpu-1x"
memory = "512mb"
cpus = 1
If fly launch did not generate a Dockerfile, create one:
FROM node:20-slim
RUN npm install -g openclaw@latest
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
EXPOSE 3000
CMD ["openclaw", "start"]
Key configuration details:
auto_stop_machines: Set to"stop"to automatically stop machines when idle, saving costs. Set to"off"if your agent must be always-on.min_machines_running: Keeps at least 1 machine running at all times to avoid cold starts.mounts: Binds a Fly Volume to/app/datafor persistent storage (created in Step 5).
Step 3: Set Secrets
Fly.io manages sensitive values as encrypted secrets, separate from the fly.toml env block. Set your API keys:
# Set secrets (they are encrypted and never logged)
fly secrets set ANTHROPIC_API_KEY=sk-ant-your-key-here
fly secrets set OPENAI_API_KEY=sk-your-key-here
# Verify secrets are set (values are not shown)
fly secrets list
You can also set multiple secrets at once:
fly secrets set \
ANTHROPIC_API_KEY=sk-ant-your-key-here \
OPENAI_API_KEY=sk-your-key-here \
OPENCLAW_WEBHOOK_SECRET=whsec-your-secret
Secrets are injected as environment variables at runtime. They persist across deployments and are not included in your Docker image.
Step 4: Deploy
With your fly.toml, Dockerfile, and secrets configured, deploy your application:
fly deploy
Fly.io will:
- Build your Docker image using a remote builder.
- Push the image to Fly.io's internal registry.
- Create or update the Firecracker micro-VM.
- Run health checks.
- Route traffic to the new version once healthy.
Monitor your deployment:
# Check application status
fly status
# Stream live logs
fly logs
# Open the app in your browser
fly apps open
Your application will be available at https://openclaw-agent.fly.dev. Fly.io provisions a TLS certificate automatically for the .fly.dev subdomain.
To set up a custom domain:
# Add a custom domain
fly certs create agent.yourdomain.com
Then add a CNAME record in your DNS pointing agent.yourdomain.com to openclaw-agent.fly.dev. Fly.io will automatically issue a Let's Encrypt certificate.
Step 5: Persistent Storage with Volumes
Fly Volumes are persistent NVMe-backed storage attached to your micro-VM. Create a volume before your first deploy if you configured a [mounts] section in fly.toml:
# Create a 1 GB volume in your primary region
fly volumes create openclaw_data --region iad --size 1
# List existing volumes
fly volumes list
Important notes about Fly Volumes:
- Volumes are pinned to a specific region. If you scale to multiple regions, each region needs its own volume.
- Volumes persist across deployments but are tied to a specific machine. If the machine is destroyed, the volume remains and will be reattached.
- Data is not replicated across volumes. For critical data, implement your own backup strategy:
# SSH into the running machine to inspect volume contents
fly ssh console
ls /app/data/
Configure OpenClaw to use the mounted volume:
# In fly.toml [env] section or via fly secrets
OPENCLAW_DATA_DIR=/app/data
Step 6: Scaling
Fly.io gives you fine-grained control over scaling:
# Scale to a specific number of machines
fly scale count 1
# Change VM size (CPU and memory)
fly scale vm shared-cpu-1x --memory 512
# View current scale settings
fly scale show
Available VM sizes for OpenClaw workloads:
| VM Size | vCPU | RAM | Best For |
|---|---|---|---|
shared-cpu-1x | 1 (shared) | 256 MB | Testing and light workloads |
shared-cpu-1x | 1 (shared) | 512 MB | Typical single-agent deployment |
shared-cpu-2x | 2 (shared) | 1 GB | Multiple concurrent agent sessions |
performance-1x | 1 (dedicated) | 2 GB | High-throughput production agents |
To deploy across multiple regions for lower latency:
# Add a machine in London
fly scale count 2 --region iad,lhr
# Fly.io automatically routes users to the nearest region
Cost Breakdown
Fly.io's free allowances (per organization) include:
| Resource | Free Allowance |
|---|---|
| Shared CPU VMs | Up to 3 shared-cpu-1x VMs with 256 MB RAM |
| Bandwidth | 100 GB outbound transfer |
| Volumes | 1 GB of persistent storage |
Beyond free allowances, pricing is usage-based:
| Resource | Price |
|---|---|
| shared-cpu-1x (per month) | ~$1.94 per 256 MB RAM |
| Additional RAM (per GB/mo) | ~$7.20 |
| Volume storage (per GB/mo) | $0.15 |
| Bandwidth (per GB over 100 GB) | $0.02 |
A single OpenClaw instance on a shared-cpu-1x with 512 MB RAM and 1 GB volume costs approximately $3-5/month, well within or just above the free tier. With auto_stop_machines enabled, idle machines cost nothing for compute.
Pros and Cons
Advantages:
- Global edge deployment -- run your agent in 30+ regions worldwide for minimal latency
- Generous free tier covers a single always-on instance for most use cases
- Full control over VM resources, regions, and scaling behavior
- Persistent volumes with NVMe-backed storage
- SSH access to running machines for debugging (
fly ssh console) - Auto-stop/start machines to reduce costs during idle periods
- WireGuard-based private networking between machines
Limitations:
- Steeper learning curve than fully managed platforms like Railway
flyctlCLI is required for most operations (no full-featured web dashboard for deploys)- Volumes are region-locked and not replicated -- you must manage backups yourself
- Credit card required at signup even for free-tier usage
- Build times can be slower when the remote builder queue is busy
- IPv6-first networking can occasionally cause compatibility issues with upstream services
Comparison: Railway vs. Fly.io
| Factor | Railway | Fly.io |
|---|---|---|
| Setup time | ~10 minutes | ~25 minutes |
| Difficulty | Beginner-friendly | Intermediate |
| Deployment | Git push or CLI | CLI (fly deploy) |
| SSL | Automatic | Automatic |
| Custom domains | Dashboard UI | CLI command |
| Persistent storage | Volumes (dashboard) | Volumes (CLI) |
| Multi-region | No | Yes (30+ regions) |
| Auto-scaling | Limited | Full control |
| SSH access | No | Yes |
| Free tier | $5 credit/month (Trial) | 3 shared VMs + 100 GB bandwidth |
| Typical cost | $5-15/month | $0-10/month |
| Best for | Fast prototyping, small teams | Production agents, global distribution |
Choose Railway if you want the fastest possible path to production with minimal configuration. Choose Fly.io if you need global distribution, persistent storage, SSH access, or fine-grained control over your infrastructure.