#19566: [AI-Assisted] feat: add openclaw sandbox run command
docs
cli
commands
docker
size: M
## Summary
- **Problem:** Users lacked a way to manually test and debug sandbox environments without initiating a full agent session.
- **Why it matters:** Simplifies dependency verification, permission debugging, and environment validation for developers and operators.
- **What changed:** Added a new `openclaw sandbox run <command>` CLI command that mirrors agent-based `exec` tool execution.
- **What did NOT change:** Existing agent execution logic and tool implementation remain untouched.
## Change Type (select all)
- [ ] Bug fix
- [x] Feature
- [ ] Refactor
- [x] Docs
- [ ] Security hardening
- [ ] Chore/infra
## Scope (select all touched areas)
- [x] Gateway / orchestration
- [x] Skills / tool execution
- [ ] Auth / tokens
- [ ] Memory / storage
- [ ] Integrations
- [ ] API / contracts
- [x] UI / DX
- [ ] CI/CD / infra
## User-visible / Behavior Changes
Added `openclaw sandbox run <command>` subcommand with support for:
- `--agent <id>`: Target specific agent configurations (image, user, env).
- `--session <key>`: Target specific session containers.
- `--workdir <path>`: Auto-map host paths to container paths using existing mapping logic.
## Security Impact (required)
- New permissions/capabilities? (`No`)
- Secrets/tokens handling changed? (`No`)
- New/changed network calls? (`No`)
- Command/tool execution surface changed? (`Yes`)
- Data access scope changed? (`No`)
- **Risk + Mitigation:** Adds a CLI entry point to the existing tool execution surface. It enforces the same sandbox boundaries, user permissions, and filesystem policies as agent-invoked tools.
## Repro + Verification
### Environment
- **OS:** Linux
- **Runtime:** Docker/Podman
- **Model/provider:** AI-assisted ([Gemini CLI](https://github.com/google/gemini-cli))
### Steps
1. Run `openclaw sandbox run "ls -la"` to verify standard execution.
2. Run `openclaw sandbox run "whoami" --agent <custom-agent>` to verify user/image overrides.
3. Run `openclaw sandbox run "pwd" --workdir <host-path>` to verify host-to-container path mapping.
### Expected
- Commands execute inside the designated container with correct isolation.
- Exit codes are propagated to the host CLI.
### Actual
- Commands executed successfully.
- Exit codes correctly reflected status (e.g., `false` returns 1).
- Path mapping correctly identified subdirectories within mounted volumes.
## Evidence
- [x] E2E tests passing: `src/commands/sandbox-run.e2e.test.ts`
- [x] Manual verification logs available in branch history.
## Human Verification (required)
- **Verified scenarios:** Standard execution, agent image overrides, read-only workspace enforcement (`workspaceAccess: ro`), host-to-container path mapping.
- **Edge cases checked:** Non-zero exit codes, large output handling, non-existent workdir warnings.
- **What you did NOT verify:** Browser-specific container execution (focused on standard code sandboxes).
## Compatibility / Migration
- Backward compatible? (`Yes`)
- Config/env changes? (`No`)
- Migration needed? (`No`)
## Failure Recovery (if this breaks)
- **Revert:** Revert changes to `src/cli/sandbox-cli.ts` and delete `src/commands/sandbox-run.ts`.
## Risks and Mitigations
- **Risk:** Accidental exposure of host paths via `--workdir`.
- **Mitigation:** Uses existing `resolveSandboxWorkdir` logic which validates paths against the sandbox root and falls back to safe defaults if unauthorized.
Most Similar PRs
#21756: [AI-Assisted] Sandbox: add support for env_file in Docker sandboxes
by ronaldslc · 2026-02-20
73.5%
#16929: fix(security): block access to sensitive directories from within sa...
by CornBrother0x · 2026-02-15
71.4%
#8137: feat: openclaw-env hardened sandbox generator (MVP)
by krahimov · 2026-02-03
70.8%
#9200: Fix: Strip dangerous env vars from baseEnv in host execution
by vishaltandale00 · 2026-02-05
70.6%
#4226: Fix/sandbox containerworkdir rw access
by ozgur-polat · 2026-01-29
70.6%
#3907: fix(sandbox): use absolute /bin/sh path + add allowedReadPaths config
by pvoo · 2026-01-29
70.3%
#11820: fix(sandbox): remap container paths in sandboxed file tools
by steflsd · 2026-02-08
69.9%
#11497: feat(exec): inject agent identity env vars for subagents
by NOVA-Openclaw · 2026-02-07
69.6%
#23811: Config: fail closed when exec host=sandbox but sandbox mode is off
by bmendonca3 · 2026-02-22
69.1%
#8567: fix: Sandbox browser runs Chromium as root with --no-sandbox
by coygeek · 2026-02-04
68.9%