โ† All Guides

๐Ÿ“ฆ Sandboxing Deep Dive

OpenClaw can run tools inside Docker containers to reduce blast radius. If the AI does something dumb, the damage stays in the sandbox. This guide covers every sandbox setting, network isolation, bind mounts, and per-agent overrides.

Advanced ยท SecurityDocker sandboxReduces blast radius

๐Ÿ›ก๏ธ Why sandbox?

Without sandboxing, OpenClaw tools (exec, filesystem, browser) run directly on your host. If the AI hallucinates a destructive command โ€” rm -rf /, delete a database, overwrite config โ€” it happens on your actual system.

Sandboxing runs tool execution inside Docker containers. The gateway stays on the host; only tool execution is isolated. This is not perfect security, but it materially limits filesystem and process access.

๐Ÿ”„ How it works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Gateway (Host)         โ”‚     โ”‚  Sandbox Container       โ”‚
โ”‚                          โ”‚โ”€โ”€โ”€โ”€โ–บโ”‚                          โ”‚
โ”‚   - AI model calls       โ”‚     โ”‚  - exec (shell commands) โ”‚
โ”‚   - Session management   โ”‚     โ”‚  - filesystem read/write โ”‚
โ”‚   - Channel routing      โ”‚     โ”‚  - browser (optional)    โ”‚
โ”‚                          โ”‚โ—„โ”€โ”€โ”€โ”€โ”‚                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  Host stays safe                 Damage contained here

Tools sandboxed: exec, read, write, edit, apply_patch, process, and optionally the browser.

โš™๏ธ Sandbox modes

ModeWhat's sandboxedUse case
offNothing (default)Trusted, single-user setup
"non-main"Sub-agents + cron sessionsProtect host from automated tasks
"all"All sessions including mainMaximum isolation
{
  "agents": {
    "defaults": {
      "sandbox": {
        "mode": "non-main"
      }
    }
  }
}

โœ… Recommended: Start with "non-main". This sandboxes sub-agents and cron jobs (automated, less trusted) while keeping your main interactive session on the host (faster, full access).

๐Ÿ“‹ Configuration

{
  "agents": {
    "defaults": {
      "sandbox": {
        "mode": "non-main",
        "docker": {
          "image": "openclaw-sandbox:bookworm-slim",
          "network": "none",
          "readOnlyRoot": true,
          "user": "1000:1000",
          "workspaceAccess": "rw",
          "binds": [],
          "env": {}
        }
      }
    }
  }
}

Build the sandbox image

# Build once (required before enabling sandbox)
openclaw sandbox build

# Or manually:
docker build -t openclaw-sandbox:bookworm-slim \
  -f ~/.openclaw/sandbox/Dockerfile .

โš ๏ธ The default image doesn't include Node.js. If skills need Node (or other runtimes), bake a custom image or use setupCommand.

๐ŸŒ Network isolation

By default, sandbox containers have no network access (network: "none").

SettingAccessUse case
"none"No network (default, safest)File processing, code analysis
"bridge"Docker bridge networkSkills that need API access
"host"Full host networkโš ๏ธ Defeats isolation purpose
# Allow network for skills that need API calls
{
  "sandbox": {
    "docker": {
      "network": "bridge"
    }
  }
}

โš ๏ธ Package installs fail with network: "none". If using setupCommand to install packages, you need "bridge" during setup.

๐Ÿ“ Bind mounts

Mount host directories into the sandbox:

{
  "sandbox": {
    "docker": {
      "binds": [
        "/home/user/source:/source:ro",
        "/var/data/myapp:/data:ro"
      ]
    }
  }
}

Security rules:

  • OpenClaw blocks dangerous sources: docker.sock, /etc, /proc, /sys, /dev
  • Use :ro for read-only access wherever possible
  • Sensitive mounts (SSH keys, secrets) should always be :ro
  • Global and per-agent binds are merged (not replaced)
  • Under scope: "shared", per-agent binds are ignored

๐ŸŒ Browser sandboxing

The browser tool can also run in a separate sandboxed container:

{
  "agents": {
    "defaults": {
      "sandbox": {
        "browser": {
          "enabled": true,
          "autoStart": true,
          "autoStartTimeoutMs": 30000
        }
      }
    }
  }
}
  • Sandbox browser uses a dedicated Docker network (openclaw-sandbox-browser)
  • browser.binds overrides docker.binds for the browser container specifically
  • Browser auto-starts when the browser tool first needs it

๐Ÿ”ง Setup command

Run a one-time setup command when the sandbox container is created:

{
  "sandbox": {
    "docker": {
      "setupCommand": "apt-get update && apt-get install -y python3 git",
      "network": "bridge",
      "readOnlyRoot": false,
      "user": "0:0"
    }
  }
}

Pitfalls:

  • network: "none" โ†’ package installs fail (no network)
  • readOnlyRoot: true โ†’ writes fail (can't install)
  • user: "1000:1000" โ†’ no sudo access for installs (use "0:0")
  • Runs once after creation, not on every run
  • Sandbox exec does not inherit host process.env โ€” use docker.env for API keys

๐Ÿ”€ Per-agent overrides

{
  "agents": {
    "defaults": {
      "sandbox": { "mode": "all" }
    },
    "list": [
      {
        "id": "main",
        "sandbox": { "mode": "off" }
      },
      {
        "id": "public-bot",
        "sandbox": {
          "mode": "all",
          "docker": {
            "network": "none",
            "readOnlyRoot": true,
            "binds": []
          }
        }
      },
      {
        "id": "coding",
        "sandbox": {
          "docker": {
            "binds": ["/mnt/projects:/projects:rw"]
          }
        }
      }
    ]
  }
}

Pattern: main agent unsandboxed (trusted), public bot fully locked down, coding agent with project access.

๐Ÿ”ง Troubleshooting

ProblemFix
Sandbox image not foundRun openclaw sandbox build first.
Package install failsSet network: "bridge", readOnlyRoot: false, user: "0:0".
Skill API key not availableSandbox doesn't inherit host env. Add keys to docker.env.
Filesystem writes blockedCheck readOnlyRoot and workspaceAccess settings.
Container won't startCheck Docker is running: docker info. Check disk space.
Bind mount permission deniedCheck host directory permissions. Use user: "0:0" for root access.
dangerouslyAllowContainerNamespaceJoinBreak-glass only. Required for network: "container:<id>". Avoid if possible.