Skip to main content

Security Best Practices

Running an AI assistant that can execute commands, read files, and browse the web requires serious security consideration. This guide covers essential hardening for your ClawBook instance, based on OpenClaw's official security recommendations.

The Security Mindset

When you give an AI model the ability to execute shell commands or read files, you're trusting it with significant power. OpenClaw mitigates this through:

  1. Docker Sandboxing — Commands run in isolated containers
  2. Pairing System — Only approved contacts can trigger the AI
  3. Tool Restrictions — Dangerous tools can be disabled
  4. Network Isolation — Gateway binds to localhost by default

No system is perfectly secure. The goal is to limit the blast radius if something goes wrong.

Quick Security Checklist

Complete these immediately after setup:

  • Run the security audit: openclaw security audit
  • Enable Docker sandboxing
  • Configure pairing for all channels
  • Restrict dangerous tools (exec, write, browser)
  • Set up firewall rules
  • Bind Gateway to loopback only
  • Verify file permissions

Docker Sandboxing

OpenClaw can run tool executions inside Docker containers, preventing a misbehaving AI from affecting your host system.

Enabling Sandboxing

# Enable sandbox for all tools
openclaw config set agents.defaults.sandbox.mode "all"

# Set isolation scope to per-agent (default)
openclaw config set agents.defaults.sandbox.scope "agent"

# Workspace access: none (most secure), ro (read-only), rw (read-write)
openclaw config set agents.defaults.sandbox.workspaceAccess "none"

Sandbox Modes

ModeDescriptionUse Case
allAll tools run in DockerProduction, security-first
dangerousOnly shell/exec tools sandboxedBalance of security and speed
noneNo sandboxing (tools run on host)Development only

Hardened Docker Configuration

ClawBook instances use a hardened Docker setup:

# Security options applied:
--security-opt=no-new-privileges # No privilege escalation
--cap-drop=ALL # Drop all Linux capabilities
--read-only # Read-only root filesystem

This means even if the AI tries something malicious, it can't escape the container or escalate privileges.

Gateway Security

The Gateway is the nerve center of OpenClaw—it handles all incoming messages and outgoing responses.

Bind to Loopback Only

By default, ClawBook configures the Gateway to listen only on localhost:

# Verify binding
openclaw config get gateway.bind
# Should return: "loopback"

# If not, set it:
openclaw config set gateway.bind "loopback"

This means the Gateway only accepts connections from the same machine. To access the dashboard remotely, use SSH tunneling:

# On your local machine:
ssh -L 18789:localhost:18789 root@YOUR_SERVER_IP

# Then open: http://localhost:18789

Gateway Authentication

Enable token-based authentication for the Gateway:

# Generate a random token
TOKEN=$(openssl rand -base64 32)

# Set it in config
openclaw config set gateway.auth.mode "token"
openclaw config set gateway.auth.token "$TOKEN"

# Restart gateway
openclaw gateway restart

Pairing and Access Control

The pairing system is your first line of defense against unauthorized access.

DM Policies

PolicyDescriptionSecurity Level
pairingUnknown senders get a code to approveRecommended
allowlistOnly pre-approved contacts can chatHigh security
openAnyone can chatNot recommended
disabledIgnore all DMsMaximum security

Configure per channel:

# WhatsApp
openclaw config set channels.whatsapp.dmPolicy "pairing"

# Telegram
openclaw config set channels.telegram.dmPolicy "pairing"

Managing the Allowlist

# View allowlist
cat ~/.openclaw/credentials/whatsapp-allowFrom.json

# Add a number to allowlist (example JSON format)
# ["+15551234567", "+15559876543"]

Group Chat Security

For groups, always require mentions:

openclaw config set channels.whatsapp.groups.*.requireMention true

This prevents the AI from responding to every message in a busy group.

Tool Restrictions

Some OpenClaw tools are high-risk. You can disable them entirely or restrict to certain agents.

High-Risk Tools

ToolRiskRecommendation
exec / shellArbitrary command executionSandbox + restrict
write / editFile modificationRestrict or sandbox
browserWeb browsing, logged-in sessionsDedicated profile
web_fetchExternal requestsMonitor for prompt injection

Restricting Tools

Create a restricted agent profile:

{
"agents": [{
"id": "safe-assistant",
"sandbox": {
"mode": "all",
"workspaceAccess": "ro"
},
"tools": {
"deny": ["exec", "write", "edit", "shell", "browser"]
}
}]
}

Read-Only Agent Example

For maximum safety, create an agent that can only read and respond:

openclaw config set agents.readonly.sandbox.mode "all"
openclaw config set agents.readonly.sandbox.workspaceAccess "ro"
openclaw config set agents.readonly.tools.deny '["write", "edit", "exec", "process"]'

Firewall Configuration

ClawBook instances come with UFW pre-configured, but verify the rules:

# View current rules
sudo ufw status numbered

# Expected rules:
# 22/tcp ALLOW IN (SSH)
# 18789/tcp ALLOW IN (OpenClaw Gateway - consider removing if using loopback)
# 80/tcp ALLOW IN (HTTP for Let's Encrypt)
# 443/tcp ALLOW IN (HTTPS)

Tightening Firewall Rules

If you're only accessing via SSH tunnel, you can block the Gateway port externally:

# Remove public Gateway access
sudo ufw delete allow 18789

# Gateway still works via localhost

Rate Limiting SSH

# Limit SSH to 6 connections per 30 seconds
sudo ufw limit ssh

Prompt Injection Awareness

Prompt injection is when malicious content tricks the AI into doing something unintended. Sources include:

  • Web pages fetched by web_fetch
  • Files read from untrusted sources
  • Messages from unknown users

Mitigations

  1. Use modern, instruction-hardened models — Claude Opus 4.5 is notably resistant
  2. Sandbox everything — Even if tricked, damage is contained
  3. Disable tools you don't need — Reduce attack surface
  4. Use separate agents for untrusted content — A "reader" agent with no tools summarizes content first

Example: Safe Web Research

{
"agents": [{
"id": "web-reader",
"tools": {
"allow": ["web_fetch"],
"deny": ["exec", "write", "browser"]
}
}]
}

Browser Control Security

If you use browser automation, be aware that the AI can access any site you're logged into in that browser profile.

Recommendations

  1. Use a dedicated browser profile (default: openclaw profile)
  2. Never point the AI at your personal browser profile
  3. Disable browser control for sandboxed agents unless necessary
  4. Treat browser downloads as untrusted input

File Permissions

Verify permissions on sensitive files:

# Run the built-in audit
openclaw security audit --fix

# Expected permissions:
# ~/.openclaw/ drwx------ (700)
# ~/.openclaw/config -rw------- (600)
# ~/.openclaw/credentials/* -rw------- (600)

Credential Storage

Sensitive files and their locations:

FilePathContains
WhatsApp creds~/.openclaw/credentials/whatsapp/<id>/creds.jsonSession token
LLM auth~/.openclaw/agents/<id>/agent/auth-profiles.jsonAPI keys
Gateway config~/.openclaw/config.jsonGateway token

Treat these files as highly sensitive. Don't expose them in logs or backups.

Security Audit Command

Run this regularly (especially after config changes):

# Basic audit
openclaw security audit

# Deep audit with network checks
openclaw security audit --deep

# Auto-fix permission issues
openclaw security audit --fix

Audit Checks

The audit verifies:

  • Inbound access policies (pairing, allowlists)
  • Tool permissions (high-risk tools in open channels)
  • Network exposure (bind mode, auth settings)
  • File permissions and symlink safety
  • Model selection (modern vs. legacy)

Incident Response

If you suspect a compromise:

1. Contain

# Stop the gateway immediately
openclaw gateway stop

# Block all inbound connections
sudo ufw default deny incoming

2. Rotate Credentials

# Change Gateway token
openclaw config set gateway.auth.token "$(openssl rand -base64 32)"

# Re-authenticate WhatsApp (invalidates old session)
openclaw channels logout whatsapp

# Rotate LLM API keys at provider console

3. Audit

# Check recent logs
openclaw logs --limit 500 | grep -i "exec\|write\|error"

# Review session transcripts
ls ~/.openclaw/agents/*/sessions/

# Check for config changes
git diff ~/.openclaw/config.json # if version controlled

4. Report

Contact support@clawbook.io with:

  • Timestamp of suspected incident
  • Any unusual behavior observed
  • Relevant log excerpts