How to lock down a self-hosted OpenClaw gateway
A self-hosted agent gateway is a powerful thing to leave on the open internet. Exposed instances get found, and an agent with tools and keys is a bigger prize than a plain web app. This checklist covers the settings that matter most before you go live.
Direct answer
How do I secure a self-hosted OpenClaw gateway?
Do not expose it directly to the internet. Bind the gateway to loopback or a private network like Tailscale, require authentication in front of it, store keys as least-privilege secrets outside your code, keep the runtime updated, and limit what the agent can reach so a mistake or compromise has a small blast radius.
Self-hosted gateway hardening checklist
| Area | Do this | Why it matters |
|---|---|---|
| Network | Bind to loopback; reach it over Tailscale or a VPN. | Keeps the agent off the public internet. |
| Auth | Require a token or an authenticated proxy. | Stops anyone from driving your agent. |
| Secrets | Least-privilege keys in a secret store. | Limits the damage if one credential leaks. |
| Updates | Patch the runtime on a schedule. | Closes known holes before they are used. |
| Blast radius | Non-root user, spend caps, human review. | Keeps a single mistake small. |
Do not bind it to a public interface
The most common mistake is running the gateway on 0.0.0.0 and reaching it by public IP. Exposed agent and LLM endpoints are a recurring research finding, not a theoretical risk: while disclosing CVE-2024-37032, Wiz reported on the order of a thousand Ollama servers reachable from the open internet, and anything listening on a public port is indexed by scanners like Shodan within hours. CISA considers exposed management interfaces serious enough that it directs US federal agencies to remove them from the internet. An agent gateway holding tools and credentials is a bigger prize than either. OpenClaw's gateway listens on loopback (ws://127.0.0.1:18789) by default; verify nothing has rebound it, and reach it over a private network instead.
- Keep the gateway on 127.0.0.1, never 0.0.0.0.
- Reach it over Tailscale, a VPN, or an SSH tunnel, not a public port.
- If it must be public, put it behind a reverse proxy that enforces auth and TLS.
Verify the gateway is not listening publicly
# The local address should be 127.0.0.1:18789, not 0.0.0.0:18789 or [::]:18789
ss -tlnp | grep 18789Reach it privately instead: SSH tunnel or Tailscale
# From your machine: forward the gateway to localhost over SSH
ssh -N -L 18789:127.0.0.1:18789 agent-host
# Or expose it only inside your tailnet
tailscale serve --bg 18789Firewall: default-deny inbound, allow only SSH
ufw default deny incoming
ufw allow OpenSSH
ufw enable
ufw status verboseSources: Wiz: CVE-2024-37032 and exposed Ollama servers · CISA BOD 23-02: internet-exposed management interfaces
Require authentication in front of the agent
An agent endpoint with no auth is an open door. Put authentication in front of it so only you, or your own systems, can send it instructions. If the gateway must be reachable beyond loopback, terminate TLS at a reverse proxy that enforces a credential on every request.
- Require a token or an authenticated proxy for every request.
- Do not treat an obscure URL or port as a secret.
- Rotate the credential if it is ever shared, logged, or leaked.
Caddy: TLS + basic auth in front of the gateway
agent.example.com {
reverse_proxy 127.0.0.1:18789
basic_auth {
# generate the hash with: caddy hash-password
operator $2a$14$...hash...
}
}Handle keys and secrets carefully
An agent's model keys, tokens, and integration credentials are the real target. Treat them as least-privilege secrets that live outside your code and can be rotated on their own. On a self-hosted box, that means an environment file owned by the agent's user, readable by no one else, and loaded by the service manager rather than pasted into shells or prompts.
- Store secrets in an env file or a secret store, never in the repo or the prompt.
- Give each integration the narrowest scope it can work with.
- Use separate credentials per agent so one leak does not unlock everything.
Lock the env file down and load it via systemd
install -m 600 -o openclaw-agent -g openclaw-agent .env /etc/openclaw/agent.env
# in the unit file:
[Service]
EnvironmentFile=/etc/openclaw/agent.envKeep it updated and limit the blast radius
Agents move fast and so do their dependencies. Patch the runtime on a schedule, and assume any single agent could misbehave, so nothing it can reach is catastrophic on its own. The unit file below is the same pattern Qoren uses in production for every managed OpenClaw gateway: a dedicated non-root user, automatic restarts, and hard memory and CPU ceilings, with a few standard systemd hardening directives added on top.
- Update the runtime and dependencies on a schedule, not just after an incident.
- Run the agent as a non-root user with only the file and network access it needs.
- Set spend limits and human review on any action that touches money or customers.
Update the runtime deliberately
npm install -g openclaw@latest && openclaw --versionA hardened systemd unit for the gateway
[Unit]
Description=OpenClaw gateway
After=network.target
[Service]
User=openclaw-agent
WorkingDirectory=/home/openclaw-agent/workspace
EnvironmentFile=/etc/openclaw/agent.env
ExecStart=/usr/bin/env openclaw gateway run
Restart=always
RestartSec=3
MemoryMax=1024M
CPUQuota=80%
NoNewPrivileges=true
ProtectSystem=strict
ReadWritePaths=/home/openclaw-agent
PrivateTmp=true
[Install]
WantedBy=multi-user.targetSources: OWASP Top 10 for LLM Applications
Where managed hosting fits
If keeping all of this current is not how you want to spend your time, managed hosting does it by default. Qoren runs OpenClaw, Hermes, and Codex agents in isolated environments with authentication, secret storage, updates, and hard spend caps handled for you, so the secure path is the default one.
Related guides
Managed OpenClaw hosting
Managed OpenClaw hosting: what is included, and what it really costs
Managed OpenClaw hosting from $39 a month: what is included, and a line-by-line cost comparison with a VPS, model tokens, and the hours self-hosting takes.
Read guideDeployment trade-offs
Self-hosted vs managed agents: what changes when the agent must stay online
Compare local, VPS, and managed deployment for OpenClaw, Hermes, and Codex agents. What changes for uptime, security, cost, and operations when you self-host.
Read guideAlways-on OpenClaw
Run OpenClaw without leaving your laptop on
Your laptop sleeps and the agent dies. Here is why local runs stop, and the practical ways to keep OpenClaw working 24/7 without babysitting a machine.
Read guideFrequently asked questions
Why is exposing an agent gateway dangerous?
An agent is not a static site. It holds keys, can use tools, and can take actions. If its gateway is reachable without authentication, anyone who finds it can make it act with your credentials, which is why exposed instances are a documented and recurring problem.
Should I bind OpenClaw to localhost or a public IP?
Bind it to localhost, 127.0.0.1, and reach it over a private network such as Tailscale, a VPN, or an SSH tunnel. Avoid binding to 0.0.0.0 or opening a public port unless a proxy in front enforces authentication and TLS.
How should I store an agent's API keys?
Keep them out of your code and prompts. Use environment variables or a secret store, give each integration the narrowest scope that works, and use separate credentials per agent so one leak does not unlock everything.
Does managed hosting remove the need for security decisions?
No. You still choose tool permissions, review points, and spend limits. Managed hosting handles the network, authentication, secret storage, and updates by default, so the common mistakes are harder to make.
What is the single most important step?
Do not expose the gateway to the open internet. Binding it to a private network removes the largest class of risk before any other setting matters.
Run OpenClaw, Hermes or Codex agents 24/7, without the homework.
Qoren runs the machine, the secrets, the updates and the logs, with a hard cap on credit spend. Start from a template and have an agent working today.