#7851: feat: secure sandbox defaults for new installs
docs
gateway
docker
stale
Cluster:
Sandbox Enhancements and Fixes
#7827
### Summary
This PR introduces a safer sandbox default for new installations, aligning runtime behavior and examples with the “reasonably safe” posture described in the gateway security/sandboxing docs, without changing behavior for existing configs.
### What’s changed
1. **Conditional secure sandbox defaults**
In the config defaulting pipeline (`src/config/defaults.ts`), `agents.defaults.sandbox` now gets a secure default **only when it is missing**:
- `mode: "non-main"` – sandbox non-main sessions by default.
- `scope: "session"`.
- `workspaceAccess: "none"` – no host workspace access unless explicitly enabled.
- `docker.network: "none"` – no outbound network from sandbox containers by default.
If the user provides any `agents.defaults.sandbox` object, their values are preserved as-is and nothing is overridden.
2. **Docs and example config updates**
- `docs/gateway/configuration.md`: updated the `~/.openclaw/agents.json5` example to include the above sandbox block as the **recommended secure default for new installs**, with short inline comments explaining each field.
- `docs/gateway/sandboxing.md`: updated the minimal example to:
- include `docker.network: "none"`,
- clearly label this configuration as the recommended starting point for “reasonably safe” deployments.
3. **Tests**
- Added `src/config/agent-sandbox-defaults.test.ts` to lock in the behavior:
- when `agents.defaults.sandbox` is absent, the secure defaults are injected;
- when any `agents.defaults.sandbox` is present, it is preserved and not modified.
### Non-goals
- No changes to `dmScope` / DM isolation presets.
- No changes to public/untrusted agent profiles or tool allow/deny policies.
- No changes to existing user configs on disk; this only affects configs that omit `agents.defaults.sandbox` and the new-install documentation examples.
### Rationale
The security docs already recommend running with sandboxing, non-root containers, no network egress from the sandbox, and isolated workspaces for most real deployments. This PR makes that posture easy to get by default for new setups, while keeping existing installations and advanced operators’ custom configs untouched.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the config defaulting pipeline so that `agents.defaults.sandbox` gets a secure baseline **only when the sandbox block is missing**, leaving any user-provided sandbox config untouched. It also updates the gateway docs/examples to recommend that baseline for new installs, and adds a Vitest to lock in the “inject when absent / preserve when present” behavior.
The changes fit into the existing defaults pattern in `src/config/defaults.ts` (mutate-on-demand with early returns), extending agent defaults to include sandbox posture alongside the existing concurrency defaults.
<h3>Confidence Score: 5/5</h3>
- This PR looks safe to merge with minimal risk.
- Changes are localized to config defaulting, guarded to only apply when sandbox config is absent, and covered by a focused unit test; docs/examples align with the new defaults.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#7874: docs: add public/untrusted agent profile
by ichbinlucaskim · 2026-02-03
84.0%
#20991: fix(sandbox): fall back to gateway UID:GID when no user is configur...
by cluster2600 · 2026-02-19
81.1%
#4226: Fix/sandbox containerworkdir rw access
by ozgur-polat · 2026-01-29
79.1%
#16929: fix(security): block access to sensitive directories from within sa...
by CornBrother0x · 2026-02-15
79.1%
#23811: Config: fail closed when exec host=sandbox but sandbox mode is off
by bmendonca3 · 2026-02-22
79.0%
#4897: fix: config logic issues (#4689, #4654)
by lailoo · 2026-01-30
78.6%
#7826: feat(sandbox): add Docker Sandboxes (microVM) as alternative backend
by HODL-Community · 2026-02-03
78.5%
#17402: fix:sandbox path issue
by luckylhb90 · 2026-02-15
78.3%
#15757: feat(security): add hardening gap audit checks
by saurabhsh5 · 2026-02-13
78.1%
#4022: fix: apply sandbox tools denials in /tools/invoke
by davidbors-snyk · 2026-01-29
78.0%