OpenClaw

OpenClaw Security & Sandboxing👨‍💻

Security in OpenClaw is built around the principle of least privilege applied at every layer. Per-agent sandbox modes control how agents execute commands. Tool allow/deny lists restrict what each agent can do. Channel access controls limit who can interact with agents. Secrets management keeps credentials out of configuration files. For production deployments, these controls are not optional -- they are the difference between a secure system and one that is vulnerable to prompt injection, credential leakage, and unauthorized access.

Key Takeaways

  • 1Three sandbox modes provide increasing isolation: `off` (no restrictions, only for trusted internal agents), `basic` (restricted shell with limited environment variables), and `strict` (full isolation with filesystem restrictions, no network, minimal system calls).
  • 2Sandbox scope determines inheritance: `agent` applies sandboxing only to the agent itself, while `tree` applies it recursively to the agent and all sub-agents it spawns. Always use `tree` for orchestrator agents.
  • 3Tool access is controlled per agent via `tools.allow` (whitelist of permitted tools) and `tools.deny` (blacklist of forbidden tools). The deny list acts as a safety net even when the allow list is already restrictive.
  • 4Channel access controls include `allowedUsers` (specific user IDs), `allowedGuilds` (Discord servers), and CORS origins (WebChat). These prevent unauthorized users from interacting with sensitive agents.
  • 5Secrets should never be hardcoded in openclaw.json. Use the `${VAR_NAME}` syntax to reference environment variables, and use a secrets manager or .env file for local development.
  • 6The elevated mode system provides controlled, auditable temporary access to restricted tools. It requires explicit user approval, is time-limited, and all actions are logged for audit.

Master openclaw security & sandboxing

Take the Introduction to OpenClaw course with hands-on lessons and challenges.

Examples

Per-agent sandbox configuration

json

The code-reviewer has strict sandboxing that extends to any sub-agents it spawns (scope: tree). It can only read files, search, and lint -- it cannot write files, run shell commands, or deploy. The deployer has basic sandboxing applied only to itself (scope: agent). Defense in depth: both agents have deny lists that explicitly block dangerous tools.

Channel access controls

json

Telegram is restricted to a single admin user -- nobody else can interact with the bot. Discord is restricted to a specific guild (server). WebChat only accepts requests from your company's domain. These restrictions prevent unauthorized users from triggering agent actions.

Secrets management with environment variables

bash

Environment variables keep secrets out of configuration files. The ${VAR_NAME} syntax is resolved at runtime when the Gateway starts. OpenClaw also supports custom paths via OPENCLAW_HOME, OPENCLAW_STATE_DIR, and OPENCLAW_CONFIG_PATH for production deployments that follow filesystem hierarchy standards.

Production security checklist

bash

This checklist covers the key security controls for a production OpenClaw deployment. Run it before going live and periodically as part of security audits. Each step verifies a different layer of defense: sandboxing, tool access, channel restrictions, secrets, and TLS.

Elevated access with audit logging

json

Elevation allows agents to temporarily request restricted tools with user approval. MaxDuration (300 seconds) limits how long the elevated access lasts. Audit logging tracks all tool calls for 90 days. Model request logging is disabled to reduce noise (and privacy concerns), but tool call logging stays on for accountability.

Common Mistakes

Mistake:

Setting sandbox mode to off during development and forgetting to change it before deploying to production

Fix:

Default to strict sandboxing and only relax when needed. Use separate configuration files for development and production, or use environment-specific overrides.

Mistake:

Using scope: agent for an orchestrator that spawns sub-agents, leaving the sub-agents unsandboxed

Fix:

Always use scope: tree for any agent that can spawn sub-agents. Without tree scope, sub-agents inherit the default sandbox, which may be less restrictive than intended.

Mistake:

Hardcoding API keys and bot tokens directly in openclaw.json and committing the file to Git

Fix:

Use ${VAR_NAME} syntax for all secrets. Add .env files to .gitignore. Use a secrets manager (AWS Secrets Manager, Vault, Doppler) for production deployments.

Mistake:

Not restricting channel access, allowing anyone who discovers the bot to interact with powerful agents

Fix:

Always configure allowedUsers, allowedGuilds, or CORS restrictions for channels connected to agents with sensitive tools. Public-facing agents should have the most restrictive tool access.

Best Practices

  • Start with strict sandboxing and explicit tool allow lists for every agent. Relax restrictions only when you have a documented reason.
  • Use scope: tree for all orchestrator agents. If an agent can spawn sub-agents, the sandbox must propagate down the tree.
  • Implement defense in depth: sandbox mode + tool deny lists + channel access controls. Each layer catches what the others might miss.
  • Run `openclaw config validate --strict` before every deployment. This catches common misconfigurations like missing secrets, sandbox: off, and unrestricted channels.
  • Rotate bot tokens and API keys periodically. Use a secrets manager that supports automatic rotation for production deployments.
  • Place the Gateway behind a reverse proxy (Nginx, Caddy) with TLS. Never expose the raw Gateway port to the public internet. Rate limit incoming requests to prevent abuse.

Summary

OpenClaw security is built on least privilege at every layer. Sandbox modes (off, basic, strict) control command execution. Scope (agent, tree) determines sandbox inheritance for sub-agents. Tool allow/deny lists restrict per-agent capabilities. Channel access controls limit who can interact with agents. Secrets use ${VAR_NAME} syntax -- never hardcode. For production: strict sandbox, tree scope, explicit tool lists, channel restrictions, reverse proxy with TLS, and audit logging.

Practice OpenClaw with hands-on challenges

Learn openclaw security & sandboxing hands-on in your IDE

Interactive lessons and challenges on Stanza, practice in VS Code, Cursor, or the web.

Related Concepts

Related Cheatsheets

Master OpenClaw with Stanza

Interactive lessons and challenges, right in your code editor.

Check the free courses. No credit card.