2026-01-10 20:28:34 +01:00
---
title: Sandbox CLI
2026-03-15 20:35:56 -07:00
summary: "Manage sandbox runtimes and inspect effective sandbox policy"
read_when: "You are managing sandbox runtimes or debugging sandbox/tool-policy behavior."
2026-01-10 20:28:34 +01:00
status: active
---
2026-01-09 09:40:46 +01:00
# Sandbox CLI
2026-03-15 20:35:56 -07:00
Manage sandbox runtimes for isolated agent execution.
2026-01-09 09:40:46 +01:00
## Overview
2026-03-15 20:35:56 -07:00
OpenClaw can run agents in isolated sandbox runtimes for security. The `sandbox` commands help you inspect and recreate those runtimes after updates or configuration changes.
Today that usually means:
- Docker sandbox containers
2026-03-15 21:35:20 -07:00
- SSH sandbox runtimes when `agents.defaults.sandbox.backend = "ssh"`
2026-03-15 20:35:56 -07:00
- OpenShell sandbox runtimes when `agents.defaults.sandbox.backend = "openshell"`
2026-01-09 09:40:46 +01:00
2026-03-15 21:38:22 -07:00
For `ssh` and OpenShell `remote` , recreate matters more than with Docker:
- the remote workspace is canonical after the initial seed
- `openclaw sandbox recreate` deletes that canonical remote workspace for the selected scope
- next use seeds it again from the current local workspace
2026-01-09 09:40:46 +01:00
## Commands
2026-01-30 03:15:10 +01:00
### `openclaw sandbox explain`
2026-01-10 20:28:34 +01:00
Inspect the **effective** sandbox mode/scope/workspace access, sandbox tool policy, and elevated gates (with fix-it config key paths).
```bash
2026-01-30 03:15:10 +01:00
openclaw sandbox explain
openclaw sandbox explain --session agent:main:main
openclaw sandbox explain --agent work
openclaw sandbox explain --json
2026-01-10 20:28:34 +01:00
```
2026-01-30 03:15:10 +01:00
### `openclaw sandbox list`
2026-01-09 09:40:46 +01:00
2026-03-15 20:35:56 -07:00
List all sandbox runtimes with their status and configuration.
2026-01-09 09:40:46 +01:00
```bash
2026-01-30 03:15:10 +01:00
openclaw sandbox list
openclaw sandbox list --browser # List only browser containers
openclaw sandbox list --json # JSON output
2026-01-09 09:40:46 +01:00
```
**Output includes:**
2026-01-31 21:13:13 +09:00
2026-03-15 20:35:56 -07:00
- Runtime name and status
- Backend (`docker` , `openshell` , etc.)
- Config label and whether it matches current config
2026-01-09 09:40:46 +01:00
- Age (time since creation)
- Idle time (time since last use)
- Associated session/agent
2026-01-30 03:15:10 +01:00
### `openclaw sandbox recreate`
2026-01-09 09:40:46 +01:00
2026-03-15 20:35:56 -07:00
Remove sandbox runtimes to force recreation with updated config.
2026-01-09 09:40:46 +01:00
```bash
2026-01-30 03:15:10 +01:00
openclaw sandbox recreate --all # Recreate all containers
openclaw sandbox recreate --session main # Specific session
openclaw sandbox recreate --agent mybot # Specific agent
openclaw sandbox recreate --browser # Only browser containers
openclaw sandbox recreate --all --force # Skip confirmation
2026-01-09 09:40:46 +01:00
```
**Options:**
2026-01-31 21:13:13 +09:00
2026-01-09 09:40:46 +01:00
- `--all` : Recreate all sandbox containers
- `--session <key>` : Recreate container for specific session
- `--agent <id>` : Recreate containers for specific agent
- `--browser` : Only recreate browser containers
- `--force` : Skip confirmation prompt
2026-03-15 20:35:56 -07:00
**Important:** Runtimes are automatically recreated when the agent is next used.
2026-01-09 09:40:46 +01:00
## Use Cases
2026-03-15 20:35:56 -07:00
### After updating a Docker image
2026-01-09 09:40:46 +01:00
```bash
# Pull new image
2026-01-30 03:15:10 +01:00
docker pull openclaw-sandbox:latest
docker tag openclaw-sandbox:latest openclaw-sandbox:bookworm-slim
2026-01-09 09:40:46 +01:00
# Update config to use new image
2026-01-10 20:28:34 +01:00
# Edit config: agents.defaults.sandbox.docker.image (or agents.list[].sandbox.docker.image)
2026-01-09 09:40:46 +01:00
# Recreate containers
2026-01-30 03:15:10 +01:00
openclaw sandbox recreate --all
2026-01-09 09:40:46 +01:00
```
### After changing sandbox configuration
```bash
2026-01-10 20:28:34 +01:00
# Edit config: agents.defaults.sandbox.* (or agents.list[].sandbox.*)
2026-01-09 09:40:46 +01:00
# Recreate to apply new config
2026-01-30 03:15:10 +01:00
openclaw sandbox recreate --all
2026-01-09 09:40:46 +01:00
```
2026-03-15 21:35:20 -07:00
### After changing SSH target or SSH auth material
```bash
# Edit config:
# - agents.defaults.sandbox.backend
# - agents.defaults.sandbox.ssh.target
# - agents.defaults.sandbox.ssh.workspaceRoot
# - agents.defaults.sandbox.ssh.identityFile / certificateFile / knownHostsFile
# - agents.defaults.sandbox.ssh.identityData / certificateData / knownHostsData
openclaw sandbox recreate --all
```
For the core `ssh` backend, recreate deletes the per-scope remote workspace root
on the SSH target. The next run seeds it again from the local workspace.
2026-03-15 20:35:56 -07:00
### After changing OpenShell source, policy, or mode
```bash
# Edit config:
# - agents.defaults.sandbox.backend
# - plugins.entries.openshell.config.from
# - plugins.entries.openshell.config.mode
# - plugins.entries.openshell.config.policy
openclaw sandbox recreate --all
```
For OpenShell `remote` mode, recreate deletes the canonical remote workspace
for that scope. The next run seeds it again from the local workspace.
2026-01-19 01:35:17 +00:00
### After changing setupCommand
```bash
2026-01-30 03:15:10 +01:00
openclaw sandbox recreate --all
2026-01-19 01:35:17 +00:00
# or just one agent:
2026-01-30 03:15:10 +01:00
openclaw sandbox recreate --agent family
2026-01-19 01:35:17 +00:00
```
2026-01-09 09:40:46 +01:00
### For a specific agent only
```bash
# Update only one agent's containers
2026-01-30 03:15:10 +01:00
openclaw sandbox recreate --agent alfred
2026-01-09 09:40:46 +01:00
```
## Why is this needed?
2026-03-15 20:35:56 -07:00
**Problem:** When you update sandbox configuration:
2026-01-31 21:13:13 +09:00
2026-03-15 20:35:56 -07:00
- Existing runtimes continue running with old settings
- Runtimes are only pruned after 24h of inactivity
- Regularly-used agents keep old runtimes alive indefinitely
2026-01-09 09:40:46 +01:00
2026-03-15 20:35:56 -07:00
**Solution:** Use `openclaw sandbox recreate` to force removal of old runtimes. They'll be recreated automatically with current settings when next needed.
2026-01-09 09:40:46 +01:00
2026-03-15 20:35:56 -07:00
Tip: prefer `openclaw sandbox recreate` over manual backend-specific cleanup.
It uses the Gateway’ s runtime registry and avoids mismatches when scope/session keys change.
2026-01-20 15:00:03 +00:00
2026-01-09 09:40:46 +01:00
## Configuration
2026-01-30 03:15:10 +01:00
Sandbox settings live in `~/.openclaw/openclaw.json` under `agents.defaults.sandbox` (per-agent overrides go in `agents.list[].sandbox` ):
2026-01-09 09:40:46 +01:00
```jsonc
{
2026-01-11 02:24:35 +00:00
"agents": {
"defaults": {
"sandbox": {
2026-01-31 21:13:13 +09:00
"mode": "all", // off, non-main, all
2026-03-15 21:35:20 -07:00
"backend": "docker", // docker, ssh, openshell
2026-01-31 21:13:13 +09:00
"scope": "agent", // session, agent, shared
2026-01-11 02:24:35 +00:00
"docker": {
2026-01-30 03:15:10 +01:00
"image": "openclaw-sandbox:bookworm-slim",
2026-01-31 21:13:13 +09:00
"containerPrefix": "openclaw-sbx-",
2026-01-11 02:24:35 +00:00
// ... more Docker options
},
"prune": {
2026-01-31 21:13:13 +09:00
"idleHours": 24, // Auto-prune after 24h idle
"maxAgeDays": 7, // Auto-prune after 7 days
},
},
},
},
2026-01-09 09:40:46 +01:00
}
```
## See Also
2026-01-09 13:52:00 +01:00
- [Sandbox Documentation ](/gateway/sandboxing )
- [Agent Configuration ](/concepts/agent-workspace )
- [Doctor Command ](/gateway/doctor ) - Check sandbox setup