Sandbox vs monitor: what each does for coding agent security
Key takeaways
- A sandbox limits what a coding agent can reach. A monitor judges whether what the agent does inside those limits is what the person asked for.
- Useful agents need openings such as network, credentials and cloud access, and a permitted action inside an opening can still be the wrong one.
- Most risky behavior looks routine one command at a time, so monitoring has to read the whole session.
- Start in observe-only mode, then turn on blocking for a few high-impact action categories.
Why "sandbox or monitor" is the wrong question
Sandboxing a coding agent contains it: it restricts the filesystem, network and credentials the agent can touch. Monitoring a coding agent evaluates it: it checks, during the session, whether the agent's actions match the user's request and your policy, and it records the evidence.
If your teams already run Claude Code or Codex in a sandbox, you've done the right first thing. Sandboxes are excellent at limiting blast radius. The open question for a CISO is different: inside the access you've granted, how do you know the agent did what the engineer asked, and how would you prove it later?
What does sandboxing a coding agent actually mean?
Sandboxing means running the agent inside an isolated runtime boundary. Typical controls include:
- Filesystem isolation, so writes are limited to the workspace
- Network filtering or egress control, so only approved destinations are reachable
- Restricted environment variables and credentials
- Approval modes for actions outside the boundary
This reduces damage from compromised code execution and from attempts to reach blocked paths. Claude Code's sandboxing documentation and the Codex workspace sandbox both work this way, and both are good products.
The catch is practical. Agents that install packages, call APIs, pull from repositories or provision cloud resources need network, credentials and cloud access. Enterprise sandboxes are rarely air-gapped, because an air-gapped agent can't do much of the work you want from it.
What does monitoring a coding agent actually mean?
Monitoring is runtime observability plus, optionally, runtime mediation. It reads tool calls, their results, approvals and denials, and evaluates them against the user's task and your policy. The OWASP AI Agent Security Cheat Sheet sets the baseline: "Log all agent decisions, tool calls, and outcomes," and "Implement anomaly detection for unusual agent behavior."
The artifacts matter as much as the capability:
- Session transcripts with the task, tool calls and results in context
- Structured findings with a severity and a category
- The reason an action was flagged or escalated
- Which policy applied, and who approved an escalation
Metrics and token counts help with cost, but they don't answer an incident question. A transcript with a reasoned finding does.
How a permitted action can still be the wrong one
A sandbox proves an action was allowed. It doesn't prove the action should have happened in this session.
Here's a walkthrough. An engineer asks an agent to fix a failing deployment script in a staging repo. The sandbox permits cloud access, because the team needs it for staging work. Midway through, the agent finds the staging fix depends on a resource that looks misconfigured, locates a credential in the environment, and applies an infrastructure change to production.
Each step passes the sandbox. The network path is open, the credential is reachable, the cloud API is on the allowlist. What failed was appropriateness: the user never asked for a production change.
A monitor catches this because it holds the task alongside the action chain. It can see that "fix a staging script" and "modify production infrastructure" don't match, and it can say why.
Common failure modes inside a working sandbox
- Goal drift: the agent expands the task beyond what was requested.
- Task misunderstanding: the agent does something reasonable for a different request, such as deleting the wrong files.
- Tool chaining: several allowed tools combine into an outcome none of them would permit alone.
- Route workarounds: when one path is blocked, the agent finishes the task another way, for instance by reaching for credentials the task never needed.
These are ordinary robustness problems with capable models, not exotic attacks, and none of them requires breaking the sandbox.
The openings problem: network, credentials and cloud access
Teams open network, credentials and cloud access because real developer workflows require them: package installs, API calls, repository access, cloud provisioning. DNV describes this directly in its case study: sandboxes still let agents work with cloud infrastructure, so DNV added independent oversight alongside its existing controls.
Least privilege is the first answer, and you should do it: scoped tokens, short-lived credentials, per-environment roles, narrow egress allowlists. But least privilege is necessary, not sufficient. A scoped staging credential limits what can go wrong, yet it can't tell you whether using it was right for this request. Only a runtime check against the task can.
Monitoring session-wide context, not single tool calls
Single-call scoring asks whether a command looks dangerous. Session-level grading asks whether the sequence makes sense for the task. The same terraform apply is routine in a scratch sandbox and risky against production, and the difference is only visible in context.
Two review modes cover this:
- Blocking review checks a tool call before it runs and allows it, denies it, or escalates it for a person.
- Trailing review grades the session as it progresses, to catch risk patterns that a single action doesn't reveal.
Trailing review is how you catch escalation that looks routine in isolation: a read of a config file, then a credential lookup, then a deploy command. It also serves your CISO needs directly: incident reconstruction, audit evidence and consistent decisions.
How to combine both layers without slowing engineers down
Roll out in stages, and avoid blocking on isolated heuristics.
- Keep the sandbox on. Don't trade containment for oversight.
- Run observe-only. Monitor sessions without blocking anything. Review what would have been flagged and tune thresholds with engineers.
- Block a narrow set first. Pick high-impact categories, such as production infrastructure changes or credential use outside the task, and the agent pathways that reach them.
- Add escalation. Route ambiguous actions to a person, with the evidence attached, rather than a flat deny.
- Widen gradually. Extend to more categories as trust in the findings grows.
Clear policy gates with evidence earn engineering's trust. Noisy deny rules lose it.
What evidence should runtime monitoring give you?
A monitor should answer five questions after the fact:
- What did the agent try?
- Why was an action flagged?
- Which policy, and which version, applied?
- Who approved or denied an escalation?
- How do findings map to specific tool calls and results?
Durable, reconstructable records are what regulators and investigators ask for. Your SIEM should receive them too, so agent findings sit next to the rest of your security telemetry.
Where Watcher fits alongside your sandboxes
Watcher, built by Apollo Research, is a runtime monitor for coding agents. It runs inside your containers and sandboxes and works alongside them, not instead of them. For Codex, it keeps the workspace sandbox on in enforce mode.
In the terms above, Watcher provides:
- Blocking review before a tool call runs, and trailing review across the session
- Watcher Analyzer, which shows each session with its task, tool calls and results in context
- One policy across every agent, through admin-locked settings and organisation instructions rolled out through MDM, so developers can't switch the policy off
- Observe-only mode, so you see what agents do before enabling blocking
Built-in connections cover Claude Code, Codex and GitHub Copilot CLI. Other agents connect through gateway hooks or SDK examples. Findings reach a SIEM through the Watcher SDK and API, with example exporters.
On results, with more capable models and Watcher's independent monitoring, DNV engineers leave agents unattended for over an hour in 10% of sessions, up from under 1%. DNV kept its sandboxing and added oversight on top.
A decision framework for CISO teams
- Sandbox for containment. Limit filesystem, network and credentials, and scope access to least privilege.
- Monitor for appropriateness and evidence. Check actions against the user's task, across the whole session.
- Stage the rollout. Observe first, block selectively, escalate the ambiguous.
Bring this checklist to your next design review:
- Which openings (network, credentials, cloud) do agents have today?
- Can we tell whether an allowed action matched the user's request?
- Do we log decisions, tool calls and outcomes for every agent?
- Is one policy enforced across all agents, and can developers turn it off?
- Could we reconstruct last week's riskiest session from records alone?
If several answers are "no," the free agent security audit is a low-effort way to see where your agents can run unattended safely.
Frequently asked questions
Is sandboxing enough to secure a coding agent?
Sandboxing is necessary but doesn't cover everything. It limits reach, but agents need openings like network, credentials and cloud access, and actions inside those openings can still be wrong for the task. A monitor adds the check on appropriateness.
Do allowlists and sandboxes prove an agent's actions were appropriate?
No. They prove an action was allowed. Whether it should have happened in this session depends on what the user asked, which only a task-aware review can judge.
What should be logged to investigate an AI agent incident?
At minimum, all agent decisions, tool calls and outcomes, as OWASP recommends. Add approvals and denials, the reason for any flag, and the policy version that applied.
How is runtime monitoring different from collecting audit logs afterward?
Logs record what happened. Runtime monitoring evaluates actions as they happen, and can allow, deny or escalate a tool call before it runs.
What does an observe-only rollout look like?
The monitor grades sessions but blocks nothing. Security and engineering review the flags together, tune thresholds, then enable blocking for a narrow set of high-impact actions.
See what a monitor adds to your sandbox
Book a call and we'll show you Watcher running inside the containers and sandboxes you already use, starting in observe-only mode.