#14556: fix(cron): exclude sandbox from shallow merge in isolated agent config
size: XS
Cluster:
Cron Session Enhancements
## Summary
- **Bug**: When a per-agent `sandbox` config contains only `docker` overrides (e.g. `workdir`, `network`, `binds`), the `Object.assign` shallow merge in `runCronIsolatedAgentTurn` replaces the entire `agents.defaults.sandbox` — losing `mode`, `scope`, and `workspaceAccess`. This causes `resolveSandboxConfigForAgent` to fall back to `mode: "off"`, resulting in cron isolated agents executing directly on the **host** instead of inside the sandbox container.
- **Fix**: Exclude `sandbox` from the destructured agent config override. Sandbox resolution is already handled separately by `resolveSandboxConfigForAgent`, which properly merges global defaults with per-agent overrides via `agents.list[].sandbox`.
## Reproduction
1. Set `agents.defaults.sandbox.mode: "all"` and `scope: "agent"`
2. Add a per-agent `sandbox.docker` override (e.g. custom `workdir`, `network`, or `binds`) in `agents.list[]`
3. Create a cron job with `sessionTarget: "isolated"` for that agent
4. Run the cron job and execute `hostname && whoami` — it prints the **host** hostname and user instead of the container's
## Root cause
```
src/cron/isolated-agent/run.ts:130-136
Object.assign({},
params.cfg.agents.defaults, // sandbox: { mode:"all", scope:"agent", ... }
agentOverrideRest, // sandbox: { docker: { ... } } ← overwrites entirely
)
// Result: sandbox.mode is gone → defaults to "off"
```
Related: #4171
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change updates the cron isolated-agent runner to avoid shallow-merging a per-agent `sandbox` override into `agents.defaults`.
Previously, `runCronIsolatedAgentTurn` built `cfgWithAgentDefaults` by doing a top-level `Object.assign({}, agents.defaults, agentOverrideRest)`. If the per-agent override included only `sandbox.docker` keys, that shallow merge replaced the entire `sandbox` object and dropped `mode/scope/workspaceAccess`, causing downstream sandbox resolution to fall back to `mode: "off"` and run cron “isolated” turns on the host.
The fix destructures `sandbox` out of the per-agent override before the shallow merge, relying on the existing `resolveSandboxConfigForAgent` path (which merges `agents.defaults.sandbox` with `agents.list[].sandbox` field-by-field) to handle sandbox configuration correctly.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The commit is narrowly scoped (excludes `sandbox` from a shallow merge) and aligns with the existing sandbox resolution flow (`resolveSandboxConfigForAgent` merges global defaults with per-agent overrides). No other files are touched in the head SHA, and the change prevents a real configuration regression without affecting unrelated agent defaults.
- src/cron/isolated-agent/run.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#20477: fix(cron): prevent sandbox config clobbering in hook/cron agent path
by olyashok · 2026-02-19
89.3%
#12310: cron: pass agentDir to embedded runner for isolated sessions
by magendary · 2026-02-09
81.1%
#22707: fix: pass agentDir to runEmbeddedPiAgent in cron isolated sessions
by mrlerner · 2026-02-21
80.9%
#11816: fix(cron): forward agent-specific exec config to isolated cron sess...
by AnonO6 · 2026-02-08
79.8%
#16390: fix(cron): jobs land in wrong agent session when agentId isn't in a...
by yinghaosang · 2026-02-14
79.3%
#4226: Fix/sandbox containerworkdir rw access
by ozgur-polat · 2026-01-29
79.0%
#23501: fix(cron): force new session ID for isolated cron jobs (#23470)
by stakeswky · 2026-02-22
78.7%
#21646: fix(cron): pass agentDir to runEmbeddedPiAgent for correct auth res...
by zhangjunmengyang · 2026-02-20
78.4%
#20991: fix(sandbox): fall back to gateway UID:GID when no user is configur...
by cluster2600 · 2026-02-19
77.3%
#11474: fix(cron): respect subagents.model in isolated cron sessions
by AnonO6 · 2026-02-07
76.8%