Self-Hosting OpenClaw AI Agents on a Linux VPS

Your team has been clicking through a browser to reconcile invoices, update CRM fields, and draft follow-up emails. That is exactly the work OpenClaw is built to take off your plate. OpenClaw is an open-source AI agent framework (the actively maintained fork of the older Clawdbot/Moltbot codebase) that turns a Claude or GPT API key into autonomous agents: give it a task, it plans, uses tools, iterates, and reports back. This guide walks through self-hosting OpenClaw on a Linux VPS for real business automation, with Docker, a secure nginx reverse proxy, and the operational habits that keep it from becoming a toy.
Why run OpenClaw on your own VPS instead of a laptop
An agent that automates business tasks needs to be reachable and always on. A developer laptop goes to sleep, changes IP, and dies mid-run. A VPS sits in a datacenter with a static IPv4, survives restarts, and gives the agent a stable home. If your workflows touch Vietnamese partners, customers, or systems, running OpenClaw on a Linux VPS with a Vietnam IPv4 also keeps the traffic local, which matters for latency and for data-residency questions under local regulations.
Self-hosting also means the data stays yours. Every prompt, every tool call, every file the agent touches lives on hardware you control, not in a third-party SaaS. For a business handling customer records, that distinction is not paranoia, it is compliance homework.
Prerequisites
- A Linux VPS, Ubuntu 24.04 LTS or Debian 12, with at least 2 GB RAM and 2 vCPU (see what OpenClaw VPS plans need).
- Root access or a user with sudo.
- An Anthropic API key (Claude) or another supported LLM provider key.
- A domain name pointing to the VPS IP if you want HTTPS (recommended).
- Ports 80 and 443 reachable for the web UI.
Step 1: Install Docker and Docker Compose
OpenClaw ships as a Docker image, which is the only sane way to run it. Installing Docker on a fresh Ubuntu 24.04 box takes two commands, then you verify the daemon is up.
curl -fsSL https://get.docker.com | sh
systemctl enable --now docker
The install script adds the official Docker repository and installs both the engine and the compose plugin. Verify it works:
docker --version
docker compose version
Expected output shows Docker 27.x or newer and Compose v2. If you see an error about the compose plugin, install it separately with apt install docker-compose-plugin.
Step 2: Configure the OpenClaw data directory and environment
OpenClaw stores its configuration, agent state, and logs in a data folder. Create a dedicated directory and set the environment variables that point it at your LLM provider.
mkdir -p /opt/openclaw
cd /opt/openclaw
Now create the .env file that Docker Compose reads. Edit it with your editor of choice. The critical variable is the Anthropic API key; everything else is the agent personality and default model.
ANTHROPIC_API_KEY=sk-ant-xxxxxxxx
CLAUDE_MODEL=claude-sonnet-4-20260514
AGENT_NAME=business-agent
AGENT_CONFIG=default
把 OpenClaw 部署在越南 VPS 上,获得稳定的 IPv4 地址,让 AI 代理持续运行。
Running OpenClaw on a Vietnam VPS gives you a stable IPv4 address so your AI agents stay online around the clock.
You can swap the provider later. The framework supports OpenAI-compatible endpoints and local models through Ollama, but for business-grade reliability Anthropic or a paid OpenAI key is the realistic default. Cheaper local models will run, they are just noticeably dumber at multi-step tool use.
Step 3: Write the docker-compose.yml and start OpenClaw
The compose file defines the OpenClaw service, maps the data volume, and exposes the web interface on a local port. Create docker-compose.yml in the same directory:
services:
openclaw:
image: ghcr.io/openclaw/openclaw:latest
container_name: openclaw
restart: unless-stopped
env_file: .env
volumes:
- ./data:/data
ports:
- "127.0.0.1:8080:8080"
environment:
- PUID=1000
- PGID=1000
Note the binding: 127.0.0.1:8080. The web UI is reachable only on localhost, not the public interface. You will front it with nginx and TLS in the next step, which is how a self-hosted service should be exposed. Pull and start it:
docker compose up -d
docker compose logs -f
Wait for the log line that says the server is listening. Then verify the container stays up:
docker ps | grep openclaw
Expected: openclaw in the status Up X minutes. If the container keeps restarting, the API key is likely wrong or the model name does not exist. Check docker compose logs for the exact error.
Step 4: Set up nginx as a TLS reverse proxy
Exposing the OpenClaw web UI in plain HTTP over the public IP is how you get your agent hijacked. Install nginx and put it in front of the local port with a Let's Encrypt certificate.
apt install -y nginx certbot python3-certbot-nginx
Create the site configuration. Replace agent.yourdomain.com with your actual domain:
server {
listen 80;
server_name agent.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Point the file at the right path and enable it:
ln -s /etc/nginx/sites-available/openclaw /etc/nginx/sites-enabled/openclaw
nginx -t
systemctl reload nginx
Now get the certificate. Certbot reads the nginx config, issues the cert, and rewrites the config to serve HTTPS automatically.
certbot --nginx -d agent.yourdomain.com
Verify the whole chain:
curl -I https://agent.yourdomain.com
Expected: HTTP/2 200 or 302 with a valid certificate chain. If curl complains about the certificate, the DNS record was not propagated or certbot did not finish.
Step 5: Create a non-root user and secure the VPS
Running OpenClaw under root is a bad habit. Create a dedicated system user for the app and make sure the data directory is owned by it.
useradd -r -s /usr/sbin/nologin openclaw
chown -R openclaw:openclaw /opt/openclaw
Then tighten the SSH layer. These are the four settings that make the difference on any public server: key-only auth, no root login, a non-default port if you want to cut log noise, and fail2ban watching the auth log.
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519
ssh-copy-id youruser@your-vps-ip
Edit /etc/ssh/sshd_config and set:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
Then restart SSH and install fail2ban:
systemctl restart ssh
apt install -y fail2ban
Verify the SSH change before you disconnect, or you lock yourself out:
sudo sshd -t
If the test passes, reload. The firewall should only allow 22, 80, and 443. If you are using ufw on Ubuntu, that is three rules. On a system with firewalld, add the same three services. This setup follows the same discipline as hardening any Linux VPS, the agent does not change the rules.
Step 6: Build a business workflow and test it
OpenClaw is not a chatbot, it is a task runner. The pattern that works in production: give it a goal, a constrained scope, and the tools it should use, then let it report back. A typical business automation task looks like this:
Task: Read today's invoices from /data/invoices, extract the vendor, amount, and due date for each, then append them to /data/payables.csv. Flag any invoice over $5,000.
The agent will list the directory, open the files, reason about the content, and write the CSV. When it finishes, check the output file:
cat /data/payables.csv
If the CSV has the expected rows, the loop is proven. From here you extend it: connect the agent to your email inbox, your CRM via API, or a Slack channel. Start with one tool and one task shape. Agents are great at breadth and bad at undefined scope, so constrain them hard.
For recurring work, pair OpenClaw with a scheduler. A cron job can trigger a CLI command to the agent every morning, or you keep the web UI open and review runs. If you are already running n8n for other automation, OpenClaw complements it well: n8n owns the deterministic integrations and scheduled flows, OpenClaw owns the tasks that need judgment. See how much memory a full automation stack eats before you size the box, multiple n8n workflows plus an agent can chew through RAM fast.
Why OpenClaw over a SaaS agent tool
The honest comparison: a SaaS agent runs zero setup, but you pay per seat, your prompts go through their systems, and the agent is limited to their tool catalog. Self-hosting OpenClaw means one VPS bill, your own API key billed at usage, and the ability to give the agent any tool that speaks HTTP or reads a file. For a team doing serious automation, the control wins.
There is a real cost, it is operational. You own upgrades, backups, and uptime. That is why the Docker Compose setup with a restart policy and a TLS proxy matters, it makes the thing feel like infrastructure rather than a hobby. Run it on a box with monthly billing and snapshots so you can roll back when a prompt goes sideways and the agent does something creative with your production data.
FAQ
What hardware do I need to run OpenClaw?
OpenClaw itself is light, the model runs in the API, so a 2 GB RAM VPS with 2 vCPU is the realistic floor. The heavy consumers are the tools it orchestrates. If you also run n8n, a database, or a local model, size up to 4 GB or 8 GB.
Can OpenClaw use a local LLM instead of the Anthropic API?
Yes, OpenClaw supports Ollama and other OpenAI-compatible endpoints. Expect weaker multi-step tool use and slower iterations on a VPS-sized model. For business automation where correctness matters, a paid API model is the pragmatic default.
How do I back up my OpenClaw agents and workflows?
The /opt/openclaw/data directory holds state and configuration. Snapshot the VPS or rsync that directory to another host. A snapshot before any major prompt or tool change is the cheapest insurance.
Is OpenClaw safe to expose to the internet?
Only through the TLS reverse proxy with authentication. Never publish the raw port. Keep the Docker port bound to localhost, put nginx in front, and add basic auth if the UI has no login of its own.
Does OpenClaw replace n8n for automation?
No. n8n is deterministic and scheduled, OpenClaw is judgment-based and autonomous. Teams get the most value running both, n8n for the fixed pipelines, OpenClaw for the tasks that need a model to decide.
Related articles
- Self-hosting n8n for workflow automation on a VPS
- Deploy and secure n8n on a Debian VPS in Vietnam
- Self-hosting local LLMs on a VPS with Ollama
- Self-host an LLM API with Ollama on a VPS
在越南 VPS 上自建 OpenClaw
OpenClaw 是开源 AI 代理框架,可自动处理发票整理、CRM 更新等业务任务。部署在 Linux VPS 上,配合 Docker Compose 和 nginx 反向代理,就能获得稳定的运行环境和 HTTPS 访问。建议使用 Anthropic API 获得可靠的工具调用能力,并将数据目录放在可快照的 VPS 上以便回滚。对于需要判断力的自动化任务,OpenClaw 与 n8n 互补使用效果最佳。


