Why Security Matters

OpenClaw (Moltbot) has access to your files, commands, and potentially sensitive data through chat platforms. A security breach could expose your API keys, personal files, or give attackers control over your connected accounts.

This guide covers essential security practices to protect your installation whether you're running it on a VPS, Mac Mini, or home server.

1. API Key Protection

Your AI API keys are the most valuable targets for attackers. Protect them properly.

Use Environment Variables

# Never hardcode keys in config files
# Use environment variables instead
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."

Set Proper File Permissions

# Restrict config file access
chmod 600 ~/.openclaw/config.yaml
chmod 600 ~/.openclaw/.env
Important: Never commit API keys to Git! Add *.env and config.yaml to your .gitignore file.

2. Network Hardening

Restrict network access to minimize your attack surface.

Configure Firewall (UFW on Ubuntu)

# Allow SSH
sudo ufw allow 22/tcp
# Allow OpenClaw gateway port
sudo ufw allow 3000/tcp
# Enable firewall
sudo ufw enable

Use Reverse Proxy with HTTPS

# Install Nginx and get Let's Encrypt certificate
sudo certbot --nginx -d yourdomain.com

3. Access Control

Control who can interact with your OpenClaw.

Configure Allowed Users

# In config.yaml, whitelist allowed users
security:
  allowed_users:
    - user_id_telegram_1
    - user_id_discord_1
  admin_users:
    - your_user_id

Enable Rate Limiting

rate_limit:
  enabled: true
  max_requests_per_minute: 10

4. Sandbox Mode

OpenClaw includes a sandbox mode that restricts dangerous operations.

sandbox:
  enabled: true
  allowed_commands:
    - git
    - npm
    - docker
  allowed_paths:
    - /home/user/projects
    - /tmp
  block_file_delete: true
  block_system_commands: true

5. Monitoring & Logging

Keep tabs on your OpenClaw's activity.

Enable Audit Logging

logging:
  level: info
  audit_log: true
  log_file: /var/log/openclaw/audit.log

Set Up Alerts

alerts:
  enabled: true
  triggers:
    - new_user_joined
    - failed_login_attempts > 5

Frequently Asked Questions

How do I protect my OpenClaw API keys?

Never commit API keys to version control. Use environment variables, secure config files with restricted permissions (chmod 600), and consider secrets management tools like HashiCorp Vault for production deployments.

Should I run OpenClaw behind a firewall?

Yes, always run OpenClaw behind a firewall. Only expose the necessary ports (typically 3000 for the gateway) and restrict access to trusted IP addresses when possible.

What are the security risks of running OpenClaw at home?

Running OpenClaw on your home network exposes your local resources. Use network segmentation, enable sandbox mode, and consider running in a VM or container for isolation.