Self-Host OpenClaw on Google Cloud
This guide covers deploying OpenClaw on a Google Cloud Compute Engine instance using Docker. GCP offers competitive pricing, a generous free tier, and straightforward tooling. By the end, you will have OpenClaw running in a Docker container on a Debian VM, accessible through a secure SSH tunnel.
Quick Path
For users comfortable with gcloud:
gcloud initand create or select a project- Enable the Compute Engine API
- Create an
e2-smallinstance with Debian 12 and a 20 GB boot disk, no external IP tag for HTTP/HTTPS - SSH in, install Docker and Docker Compose
- Create persistent directories,
.env, anddocker-compose.yml docker compose up -d- Access via SSH tunnel:
gcloud compute ssh openclaw-vm -- -L 18789:127.0.0.1:18789 - Open
http://localhost:18789
Prerequisites
- A Google Cloud account with billing enabled
- The Google Cloud CLI installed and initialized
- An Anthropic API key
- Docker knowledge is helpful but not required
Verify your gcloud installation:
Step 1: Initialize and Configure the Project
If you have not already initialized gcloud, do so now:
Create a dedicated project for OpenClaw (or use an existing one):
Link a billing account to the project. You can find your billing account ID in the Cloud Console:
Step 2: Enable the Compute Engine API
This may take a minute the first time. You can verify it is enabled:
Step 3: Create the Compute Engine Instance
Create a VM with Debian 12, an appropriately sized boot disk, and no public-facing HTTP tags:
The instance gets a public IP by default (needed for outbound package downloads), but no firewall rules allow inbound HTTP/HTTPS traffic. SSH access is permitted by the default GCP firewall rules.
Machine Type Comparison
| Machine Type | vCPUs | RAM | Monthly Cost | Notes |
|---|---|---|---|---|
| e2-micro | 2 (shared) | 1 GB | Free tier eligible | Tight on memory, may OOM |
| e2-small | 2 (shared) | 2 GB | ~$12/mo | Minimum recommended |
| e2-medium | 2 (shared) | 4 GB | ~$25/mo | Comfortable headroom |
| e2-standard-2 | 2 | 8 GB | ~$49/mo | Heavy workloads |
The e2-small is the sweet spot for most users. If you run into out-of-memory issues, resize to e2-medium without downtime using the process described in the troubleshooting section.
Step 4: SSH into the Instance and Install Docker
Connect to the VM:
The first time you connect, gcloud generates SSH keys automatically and propagates them to the instance. This can take 30-60 seconds.
Once connected, install Docker:
Verify Docker is working:
Step 5: Set Up OpenClaw with Docker Compose
Create the directory structure for persistent data:
Create the environment file:
Set restrictive permissions on the env file:
Create the Docker Compose configuration:
The 127.0.0.1:18789:18789 binding ensures the port is only accessible from localhost, not from the public internet.
Step 6: Start OpenClaw
Check that the container is running and healthy:
Wait until you see a log line indicating the server is ready, then press Ctrl+C to stop following logs.
Step 7: Access OpenClaw via SSH Tunnel
From your local machine (not the VM), create an SSH tunnel that forwards the OpenClaw port:
The -N flag tells SSH not to open a shell, just maintain the tunnel. Leave this terminal running.
Open your browser and navigate to:
You now have secure access to OpenClaw without any public-facing endpoints.
Service Account Security
The default Compute Engine service account has broad permissions. For production deployments, create a dedicated service account with minimal privileges:
When creating the VM (or updating it), attach this service account instead of the default one:
Updating OpenClaw
To pull the latest version:
Docker Compose will detect the updated image and recreate the container. Your data in ./data and ./workspace persists across container recreations.
Cost Optimization
Preemptible / Spot VMs
If your OpenClaw usage is intermittent, a Spot VM can save up to 60-91%:
Spot VMs can be preempted (stopped) by GCP when capacity is needed. The STOP termination action preserves the disk so you can restart manually.
Scheduled Start/Stop
If you only use OpenClaw during work hours:
Automate this with Cloud Scheduler and Cloud Functions, or use the Instance Schedule feature in the GCP Console.
Committed Use Discounts
For predictable, always-on usage, 1-year committed use discounts save ~57% and 3-year discounts save ~70%.
Security Best Practices
- No inbound HTTP firewall rules: The VM has no firewall tags allowing HTTP/HTTPS traffic. All access is through SSH tunnels.
- OS Login enabled: The
enable-oslogin=TRUEmetadata flag uses IAM identities for SSH instead of project-wide SSH keys, providing better audit trails and centralized access control. - Least-privilege service account: The custom service account limits what the VM can do within GCP.
- Encrypted boot disk: GCP encrypts all data at rest by default using Google-managed keys. For additional control, use Customer-Managed Encryption Keys (CMEK).
- Automatic security updates: Enable unattended upgrades on Debian:
Troubleshooting
SSH key propagation delay
After creating a new VM, gcloud compute ssh may fail for the first 30-60 seconds while OS Login propagates keys. Wait and retry:
If it shows RUNNING but SSH still fails, wait another 30 seconds and try again.
Out-of-memory (OOM) crashes
If the Docker container keeps restarting, check for OOM kills:
Resize the machine type without deleting the instance:
Then SSH back in and run docker compose up -d to restart OpenClaw.
OS Login issues
If you get permission denied errors with OS Login:
You need at least roles/compute.osLogin (or roles/compute.osAdminLogin for sudo access):
Docker Compose not found
If docker compose (v2) is not recognized, you may have the older v1 installed:
If neither works, reinstall the Docker Compose plugin:
Cleanup
Remove all resources to stop billing:
Deleting the project removes all resources, firewall rules, service accounts, and billing associations.