Browse guides
Back to Guides
IntermediateSecurity & HardeningOpenClaw

Security Hardening Guide: Lock Down Your Agent

Harden OpenClaw: start from the documented baseline, keep the Gateway on loopback with token auth, restrict exec and tools, vet skills and run the audit.

Mira Castellan35 minutes

Harden OpenClaw by starting from the documented hardened baseline: keep the Gateway on loopback with token auth, deny the risky tool groups and shell execution by default, require DM pairing, and re-enable capabilities per agent only when you need them. Then run it under a dedicated OS user on an encrypted disk, vet every skill before you install it, and make openclaw security audit part of your routine. The sections below take each layer in turn, with the exact config keys from OpenClaw's own security documentation.

#Why does an autonomous agent need hardening?

OpenClaw is not a passive tool. It reads files, runs commands, sends messages and calls external services on your behalf, so a misconfigured or compromised instance can:

  • Leak sensitive data: API keys, personal files and credentials stored on the machine
  • Run harmful commands: a malicious skill or a manipulated prompt can reach the shell if exec is allowed
  • Run up costs: unauthorized model usage is billed to your provider account
  • Reach other systems: an agent with network access can be used to probe the rest of your network

Prompt injection makes the last two worse. OpenClaw's hardened-baseline page is explicit that its per-requester controls "do not authenticate or sanitize other content in that model prompt, including quoted text, prior shared-room history, forwarded content, fetched content, attachments, tool results, or other prompt inputs". Content from someone else can steer a turn you started, so limiting what the agent can do matters more than trusting what it reads.

ThreatWhat it gives an attackerMain control
Malicious ClawHub skillCode running with the agent's permissionsSkill audits, tool policy, sandboxing
Prompt injection from shared contentThe agent's tools, steered by someone elseTool profile, exec policy, mention-gated groups
API key exposureBilled usage on your accountEnvironment or secret store, spending limits, rotation
Exposed GatewayControl of the agent and its sessionsLoopback bind, Gateway auth, Tailscale Serve
Compromised host accountEverything the OS user can reachDedicated OS user, file permissions, disk encryption

#What does the hardened baseline look like?

OpenClaw publishes a "Hardened baseline in 60 seconds" that you can paste into ~/.openclaw/openclaw.json (find the active path with openclaw config file, which "Prints the active config file path"):

json5
{
gateway: {
mode: "local",
bind: "loopback",
auth: { mode: "token", token: "replace-with-long-random-token" },
},
session: {
dmScope: "per-channel-peer",
},
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 },
},
channels: {
whatsapp: { dmPolicy: "pairing", groups: { "*": { requireMention: true } } },
},
}

The docs summarize what it does: it "Keeps the Gateway local-only, isolates DMs, limits session tools to the agent's own sessions, turns off ordinary cross-agent access, and disables control-plane/runtime tools by default. Re-enable tools selectively per trusted agent from there." Replace the token with a long random value, and adjust the channels block for the channels you actually use. One protection is built in regardless of config: "non-owner senders cannot use the cron or gateway tools".

If several people who do not trust each other talk to the same agent, the docs go further: "use separate gateways and ideally separate OS users or hosts when participants are mutually adversarial."

#How do you keep the Gateway private?

The Gateway serves its WebSocket API and the Control UI on one port, 18789 by default. gateway.bind decides who can reach it:

  • "loopback", the default on regular hosts: "only local clients can connect".
  • "lan", "tailnet" and "custom": reachable by more clients. The docs say to "Only use with gateway auth (shared token/password, or a correctly configured trusted proxy) and a real firewall", and that "Non-loopback startup requires configured auth and fails closed without it."
  • "auto": the default when the setting is omitted inside a detected container, where it resolves to 0.0.0.0. Set gateway.bind: "loopback" explicitly if you want a loopback-only listener there.

The docs' rules of thumb are short: "prefer Tailscale Serve over LAN binds (Serve keeps the Gateway on loopback and Tailscale handles access); if you must bind to LAN, firewall the port to a tight source-IP allowlist rather than port-forwarding broadly; never expose the Gateway unauthenticated on 0.0.0.0."

For remote access without Tailscale, forward the loopback port over SSH from your own machine:

bash
ssh -N -L 18789:127.0.0.1:18789 openclaw@your-server

Then open http://localhost:18789 locally. If you run OpenClaw in Docker behind UFW, note the network-exposure page's warning that published container ports "route through Docker's forwarding chains, not only host INPUT rules", and follow its DOCKER-USER rules rather than assuming UFW covers them.

#How do you control what the agent can execute?

Three layers decide whether a command runs, and each can only narrow the others.

Tool policy. tools.exec.security and tools.exec.ask set the baseline; the hardened config uses security: "deny" and ask: "always". tools.profile, tools.deny and tools.elevated decide which tools exist at all.

Session permission modes. Each session runs in one of four modes, which set its filesystem boundary and who reviews exec escalation:

ModeControl UI labelFilesystem accessExec escalation reviewer
read-onlyRead onlyReads under the session rootNone; exec is denied
guardedAsk meReads and writes under the session rootA human, after the allowlist fast path
workspaceAuto-reviewReads and writes under the session rootAn LLM review that can allow, deny or ask a human
fullFull accessUnrestrictedNone

Exec approvals. When a command would run on a real host, "Commands run only when policy + allowlist + (optional) user approval all agree", and approvals "can only tighten config-derived security/ask, never loosen them". Be clear about what they are not: the docs say approvals "reduce accidental execution risk, but are not a per-user auth boundary or filesystem read-only policy. Once approved, a command can mutate files according to the selected host or sandbox filesystem permissions."

Start with exec denied or in read-only and guarded sessions, and widen it per agent once you know what the agent actually needs. Reserve full for sessions you supervise.

#Should you turn on sandboxing?

For any agent that runs tools on content you do not control, yes. Sandboxing "is off by default" and is enabled with agents.defaults.sandbox for every agent or agents.entries.*.sandbox for one. When it is on, "The Gateway process always stays on the host; only tool execution moves into the sandbox", using a backend such as Docker, Podman, SSH or OpenShell.

Keep expectations realistic. OpenClaw's own description is that it "is not a perfect security boundary, but it materially limits filesystem and process access when the model does something dumb." Use it together with tool policy, not instead of it.

#How do you protect the host and its files?

Run OpenClaw under a dedicated OS user. OpenClaw's storage docs recommend a "dedicated OS user account if the host is shared". A standard (non-admin) account cannot read other users' home directories or change system files without explicit sudo grants. On Linux:

$sudo adduser --system --group --home /home/openclaw --shell /bin/bash openclaw

On macOS, create a Standard account, not an Administrator, in System Settings under Users & Groups. Never run OpenClaw as root or from your primary admin account.

Keep the state directory private. The same page asks for "~/.openclaw/openclaw.json: 600 (user read/write only)" and "~/.openclaw: 700 (user only)", because everything under ~/.openclaw/ may hold secrets, including SQLite auth stores.

$chmod 700 ~/.openclaw && chmod 600 ~/.openclaw/openclaw.json

Keep file tools inside the workspace. tools.fs.workspaceOnly: true, as in the baseline, stops file tools from reaching outside the agent's workspace.

Encrypt the disk. The storage docs also recommend "full-disk encryption on the gateway host". On macOS, turn on FileVault in System Settings under Privacy & Security. FileVault asks for a password at boot, which conflicts with unattended restarts: either accept that a reboot needs someone at the machine, or keep the machine physically secure. On Linux, enable LUKS full-disk encryption, ideally when you install the OS.

#How do you vet skills before installing them?

Skills run with the agent's own permissions, so treat every third-party skill as untrusted code. ClawHub runs a security audit on each release and reports a status:

StatusWhat ClawHub says it means
PassNo visible issue above low risk was found
ReviewRead the findings before installing; the release may still be legitimate
WarnUse extra caution; a high-impact concern or warning signal was found
MaliciousDo not install

ClawHub adds that audits "are strong safety signals, but they are not a guarantee that a release is risk-free", and that "A Pass is reassuring, but it does not replace your own judgment." Before installing, check the audit, the requested credentials and permissions, and the owner and source, then read the SKILL.md yourself. From the CLI, --card prints the generated Skill Card for a release:

$openclaw skills verify @owner/<slug> --card

Work through the Skill Security Audit Checklist for anything that touches credentials or the shell. If you find an unsafe listing, use ClawHub's Report skill button; ClawHub says reports are for unsafe marketplace content, and that vulnerabilities in a skill's own code should go to its publisher, because "ClawHub does not maintain or patch third-party skill or plugin code." ClawDocx does not vet, endorse or certify any third-party skill.

#How do you protect API keys and spending?

Keep provider keys out of openclaw.json: put them in the Gateway's environment or ~/.openclaw/.env, or in OpenClaw's secret store with a SecretRef pointing at them. API key setup covers both.

Set a spending limit on every provider account that offers one, so a leaked key has a ceiling. Rotate keys on a schedule and immediately after any suspected leak. Watch usage from the Gateway, which can "Fetch usage-cost summaries from session logs":

$openclaw gateway usage-cost --days 7 --all-agents

An unexplained spike is a reason to rotate first and investigate second.

#How do you keep it patched and recoverable?

Update with the built-in updater, and read the release notes before you do. OpenClaw uses calendar version numbers such as v2026.11.3, so the version alone does not tell you whether a release is a patch; the release notes do.

$openclaw update

Take a verified backup before upgrades and on a schedule, so recovery is a restore rather than a rebuild:

$openclaw backup create --verify

#How do you audit the configuration?

openclaw security has one job, "Security tools: audit plus optional safe fixes". Plain security audit "stays on the cold config/filesystem/read-only path", and --deep "adds best-effort live Gateway checks and plugin-owned security audit collectors":

$openclaw security audit
$openclaw security audit --deep

Run the plain audit after every config change and the deep one after upgrades or new plugins.

#Security checklist

  • Running under a dedicated, unprivileged OS user
  • gateway.bind is "loopback", with token or password Gateway auth set
  • Remote access goes through Tailscale Serve or an SSH tunnel, not an open port
  • Tool profile, tools.deny and tools.exec start from the hardened baseline
  • Elevated mode and cross-agent access are off unless an agent needs them
  • Sandboxing is on for agents that handle content you do not control
  • ~/.openclaw is 700 and openclaw.json is 600, on an encrypted disk
  • DMs require pairing and group replies require a mention
  • Every installed skill's ClawHub audit and SKILL.md have been reviewed
  • Provider keys live outside openclaw.json, with spending limits set
  • OpenClaw is current, and a verified backup exists
  • openclaw security audit --deep reports no unresolved critical findings

#What do you do after a compromise?

OpenClaw's operator incident-response runbook has four stages:

  1. Contain

    Stop the Gateway: stop the macOS app if it supervises the Gateway, or terminate the openclaw gateway process. Set gateway.bind: "loopback" or disable Tailscale Serve and Funnel. Switch risky DMs and groups to dmPolicy: "disabled" or require mentions, and remove any "*" allow-all entries.

  2. Rotate

    Rotate Gateway auth (gateway.auth.token or gateway.auth.password), remote client secrets on every machine that can call the Gateway, and every provider and channel credential, including model API keys.

  3. Audit

    Read the Gateway logs with openclaw logs, review the session transcripts under ~/.openclaw/agents/<agentId>/sessions/, and check recent changes to gateway.bind, gateway.auth, DM and group policies, tools.elevated and plugins. Re-run openclaw security audit --deep and confirm the critical findings are resolved.

  4. Collect for a report

    Note the timestamp, host OS and OpenClaw version, the relevant transcripts and a redacted log tail, what the attacker sent and what the agent did, and whether the Gateway was exposed beyond loopback. If a ClawHub skill was the vector, report it on ClawHub.

#Next steps

Frequently asked questions

What is the fastest way to harden an OpenClaw install?
Start from the hardened baseline in OpenClaw's security docs: keep gateway.bind on loopback with token auth, use the messaging tool profile, deny the automation, runtime and filesystem tool groups, set tools.exec.security to deny with ask always, disable elevated mode and cross-agent access, and require DM pairing. Then run openclaw security audit and re-enable tools only for agents that need them.
Is the OpenClaw Gateway safe to expose to the internet?
Not directly. The Gateway binds to loopback by default, and any non-loopback bind requires configured Gateway auth and fails closed without it. OpenClaw's docs prefer Tailscale Serve, which keeps the Gateway on loopback, or an SSH tunnel, and say never to expose the Gateway unauthenticated on 0.0.0.0.
Do exec approvals make OpenClaw safe to run untrusted commands?
No. OpenClaw's docs describe exec approvals as reducing accidental execution risk, not as a per-user auth boundary or a read-only filesystem policy: once approved, a command can change files according to the host or sandbox permissions. Combine approvals with a tight tools.exec policy, a session permission mode and, for untrusted work, a sandbox.
Is sandboxing on by default in OpenClaw?
No. Sandboxing is off by default and is turned on with agents.defaults.sandbox or per agent. When enabled, only tool execution moves into the sandbox while the Gateway stays on the host, and the docs say it is not a perfect security boundary but materially limits filesystem and process access.
How do I check a ClawHub skill before installing it?
Read its ClawHub security audit, which reports a status such as Pass, Review, Warn or Malicious along with findings and requested credentials, and run openclaw skills verify @owner/<slug> --card to see the generated Skill Card. ClawHub says a Pass is reassuring but does not replace your own judgment, so read the SKILL.md as well.
What should I do first if my agent is compromised?
Contain it: stop the Gateway process, set gateway.bind back to loopback or disable Tailscale Serve and Funnel, and switch risky DMs and groups to disabled or mention-only. Then rotate Gateway auth and every provider and channel credential, review logs and transcripts, and re-run openclaw security audit --deep.

Sources

  1. OpenClaw: Security
  2. OpenClaw: Hardened baselines
  3. OpenClaw: Network exposure
  4. OpenClaw: Remote access
  5. OpenClaw: Session permission modes
  6. OpenClaw: Exec approvals
  7. OpenClaw: Sandboxing
  8. OpenClaw: Secrets, storage, and logs
  9. OpenClaw: Operator incident response
  10. OpenClaw: Security CLI
  11. OpenClaw: Skills CLI
  12. OpenClaw: Backup CLI
  13. OpenClaw: Config CLI
  14. OpenClaw: Gateway query commands
  15. ClawHub: Security Audits
  16. ClawHub: Moderation and Account Safety

Skip the trial and error

ClawDocx members get 500+ tested prompts, ready-to-install SKILL.md files, SOUL.md and CLAUDE.md templates, and an MCP server so your agent can pull all of it directly while it works.