The risks, in one minute
- Anyone who can message it can try to steer it. Every allowed sender can ask for tool calls, so who's allowed matters.
- Content is a threat, not just senders. Web pages, emails, attachments and pasted logs can carry hidden instructions, even if only you can DM the bot. OpenClaw's docs say plainly that prompt injection isn't solved.
- Tools run on the host by default. The sandbox is opt-in. Without it, tool calls run on the machine that hosts the gateway.
- Its state holds secrets. Anything under
~/.openclaw/may contain credentials, including channel logins, model auth and session transcripts. - An exposed gateway is a door. The gateway serves its Control UI and API on one port. Exposed without auth, that's remote control of your agent.
1. Give it a machine of its own
OpenClaw's docs call a dedicated host "not required, but recommended for reliability and isolation". A machine that holds nothing else, like a VPS or a spare Mac, means a mistake or an injected instruction can only reach the agent's own files. Your laptop, with your SSH keys, browser sessions and password manager, is the worst place for it.
For phone-number channels like WhatsApp, Signal and Telegram, the docs also suggest giving the bot its own number, so your personal conversations stay out of it.
2. Install it and keep Node.js current
OpenClaw needs Node.js 24.16+ or 26.1+, and its docs strongly recommend 24.22.1+ or 26.12.1+ for security. On Linux, Ubuntu LTS is the best-tested path.
$ curl -fsSL https://openclaw.ai/install.sh | bash
$ openclaw onboard --install-daemon
$ openclaw gateway status
3. Keep the gateway private
On a regular host the gateway binds to loopback, so only the machine itself can reach it, and it requires auth by default. Keep it that way, with a long random token (openssl rand -hex 32 makes one):
{
gateway: {
mode: "local",
bind: "loopback",
port: 18789,
auth: { mode: "token", token: "your-long-random-token" },
},
}
To open the Control UI from your laptop, tunnel to it instead of opening the port. Then visit http://localhost:18789:
$ ssh -N -L 18789:127.0.0.1:18789 you@your-server
The docs prefer Tailscale Serve over binding to your LAN, because Serve keeps the gateway on loopback. If you must bind beyond loopback, firewall the port to a tight list of source IPs, and never expose it unauthenticated on 0.0.0.0. Read OpenClaw's exposure runbook before changing gateway.bind.
4. Control who can message it
Every DM channel has a dmPolicy:
| Policy | What it does | Use it? |
|---|---|---|
pairing | The default. Unknown senders get a code that expires in an hour, and the bot ignores them until you approve. | Yes |
allowlist | Unknown senders are blocked, with no pairing handshake. | Yes |
open | Anyone can DM it. Needs "*" in the allowlist. | Not with tools |
disabled | Ignores DMs entirely. | For group-only bots |
Approve people with openclaw pairing list <channel> and openclaw pairing approve <channel> <code>. In groups, require a mention so the bot only reads what's meant for it:
{
channels: {
whatsapp: {
dmPolicy: "pairing",
groups: { "*": { requireMention: true } },
},
},
}
If more than one person can DM the bot, set session.dmScope: "per-channel-peer" so each person gets their own session instead of sharing the main one.
5. Turn on the tool sandbox
Sandboxing is off by default. When it's on, tool execution moves into a container (Docker is the default backend; Podman and SSH also work), while the gateway itself stays on the host.
{
agents: {
defaults: {
sandbox: {
mode: "all", // or "non-main"
scope: "session",
workspaceAccess: "none", // or "ro" / "rw"
},
},
},
}
Know what the modes cover. "non-main" sandboxes every session except the agent's main session, which is where your own DMs land by default. "all" sandboxes everything. Check what's actually in effect with openclaw sandbox explain. The docs are clear that a sandbox isn't a perfect boundary, which is why step 1 still matters.
6. Limit its tools
OpenClaw's hardened baseline starts from a messaging-only tool profile, denies the automation, runtime and filesystem groups, and requires approval for every command. Re-enable tools one agent at a time, only where you trust the inputs.
{
tools: {
profile: "messaging",
deny: ["group:automation", "group:runtime", "group:fs", "sessions_spawn", "sessions_send"],
fs: { workspaceOnly: true },
exec: { security: "deny", ask: "always" },
elevated: { enabled: false },
sessions: { visibility: "agent" },
agentToAgent: { enabled: false },
},
}
Keep web_search, web_fetch and browser off for tool-enabled agents unless you need them: they're the easiest way for untrusted content to get in. For mail and other untrusted inboxes, the docs suggest a read-only "reader" agent that summarizes, then hands the summary to your main agent.
7. Use a strong model for tool use
OpenClaw's docs say model choice "carries real weight" for prompt injection: smaller and older models are much easier to steer into misusing tools. Use the latest, best-tier model for any agent that can run tools or touch files and networks. A smaller model is fine for a chat-only assistant with trusted input and no tools.
8. Protect the secrets on disk
- Lock the state directory to your user:
chmod 700 ~/.openclawandchmod 600 ~/.openclaw/openclaw.json. - Put provider keys in
~/.openclaw/.envor the gateway's environment, not in a workspace.env. OpenClaw blocks provider keys in workspace.envfiles for this reason. - Remember that session transcripts and file logs keep the original text, including any credentials that passed through them. Treat disk access as the trust boundary.
9. Run the security audit
OpenClaw ships its own checker. Run it after setup and after any config change, and fix critical findings first:
$ openclaw security audit
$ openclaw security audit --deep
It flags things like a blank or short gateway token, an exposed bind and risky tool settings.
10. Plan for a bad day
Take snapshots or backups before risky work, so "the agent broke it" is a restore, not a rebuild. If you think the agent or gateway was compromised, OpenClaw's incident checklist comes down to:
- Contain: stop the gateway, set
gateway.bindback to"loopback", switch risky DMs todmPolicy: "disabled"and remove any"*"entries. - Rotate: the gateway token, remote client secrets, and every provider and channel credential.
- Audit: check
openclaw logsand the session transcripts, review recent config changes, and re-runopenclaw security audit --deep.
What no setup can do
Even a perfectly hardened OpenClaw acts with the permissions you give it. If it has a token that can send email or push code, an injected instruction can try to use it. Give it narrow, read-only credentials where you can, and remember that a snapshot restores the machine, not the messages it already sent.
Questions
Is OpenClaw safe to use?
It can be, if you set it up for it. Out of the box the gateway stays on loopback and unknown DMs get a pairing code, but the tool sandbox is off, so tools run on the host. Give it a dedicated machine, keep pairing on, turn the sandbox on, limit its tools and run openclaw security audit.
Should I set dmPolicy to open?
Not for an agent that can run tools. With open, anyone can DM it, and every sender can try to steer what it does. Use pairing (the default) or allowlist.
Does the non-main sandbox mode protect my own chats?
No. non-main sandboxes every session except the agent's main session, which is where your own DMs land by default. Use all to sandbox every session, or rely on the machine itself as the boundary for the main session.
What port does OpenClaw use, and should I open it?
The gateway uses port 18789 by default. Don't open it to the internet. Keep it bound to loopback and reach the Control UI through an SSH tunnel or Tailscale Serve.
What should I do if my OpenClaw gets compromised?
Stop the gateway, set it back to loopback and disable risky DMs. Then rotate the gateway token and every provider and channel credential, review the logs and session transcripts, and re-run openclaw security audit --deep.
Sources: OpenClaw's docs on security, hardened baselines, access control, network exposure, sandboxing, prompt injection, secrets and storage and incident response, checked November 16, 2026. Config examples are adapted from those pages; check them against your installed version. Next: OpenClaw hardware requirements.