#14308: fix(sandbox): pass docker.env config to container creation
docker
agents
size: S
## Summary
- The `docker.env` configuration was being resolved correctly but never passed to `docker create`
- Added missing loop to pass environment variables as `-e` flags in `buildSandboxCreateArgs()`
## Problem
Users setting `agents.list[N].sandbox.docker.env` in config had no way to pass environment variables to sandboxed containers. The env object was correctly merged in `resolveSandboxDockerConfig()` but the resulting values were never added to the docker create command.
## Solution
Added a simple loop after the binds handling:
```typescript
for (const [key, value] of Object.entries(params.cfg.env ?? {})) {
args.push("-e", `${key}=${value}`);
}
```
## Test plan
- [x] `pnpm build` passes
- [x] `pnpm check` passes (format + lint)
- [x] `pnpm test` passes (267/267 tests)
- [x] Manually verified: env vars appear in `docker inspect .Config.Env`
- [x] Manually verified: env vars accessible inside container via `printenv`
## AI-assisted
Yes - Claude Code identified the bug and generated the fix. Human verified the fix works correctly in a real OpenClaw deployment.
🦞 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Fixes a bug where `docker.env` config values were resolved and merged correctly in `resolveSandboxDockerConfig()` but never actually passed as `-e` flags to `docker create`. The 3-line addition follows the same pattern used for other optional config fields (`binds`, `dns`, `extraHosts`) in `buildSandboxCreateArgs()`.
- Added loop to emit environment variable flags from `params.cfg.env` in `buildSandboxCreateArgs()`
- The `?? {}` fallback correctly handles the optional `env` field
- Values are passed as separate `spawn()` args (not shell-interpolated), so no injection concern
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — minimal, well-scoped bug fix following existing patterns.
- The change is 3 lines, follows the exact pattern of adjacent code for other config fields (binds, dns, extraHosts), the type system constrains env values to strings, and the nullish coalescing handles the optional field correctly. No new dependencies or architectural changes.
- No files require special attention.
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#8161: fix(sandbox): block dangerous environment variables from Docker con...
by yubrew · 2026-02-03
81.1%
#13873: fix(sandbox): prevent Windows PATH from poisoning docker exec
by alessandrorodi · 2026-02-11
80.1%
#10174: fix(docker): exclude .env files from Docker build context
by coygeek · 2026-02-06
78.8%
#11878: fix: add missing error handler to execDocker child process
by Yida-Dev · 2026-02-08
78.7%
#16509: Fix sandbox path validation rejecting Docker bind mount paths
by Clawborn · 2026-02-14
77.7%
#20991: fix(sandbox): fall back to gateway UID:GID when no user is configur...
by cluster2600 · 2026-02-19
77.5%
#13953: feat(docker): add .env template and improve Dockerfile
by n24q02m · 2026-02-11
77.0%
#4226: Fix/sandbox containerworkdir rw access
by ozgur-polat · 2026-01-29
77.0%
#20477: fix(cron): prevent sandbox config clobbering in hook/cron agent path
by olyashok · 2026-02-19
76.9%
#7133: feat: Automated Docker setup with environment-based configuration
by synetalsolutions · 2026-02-02
76.6%