AI agent security

Sandbox vs monitor: what each does for coding agent security

Key takeaways

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:

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:

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

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:

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.

  1. Keep the sandbox on. Don't trade containment for oversight.
  2. Run observe-only. Monitor sessions without blocking anything. Review what would have been flagged and tune thresholds with engineers.
  3. 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.
  4. Add escalation. Route ambiguous actions to a person, with the evidence attached, rather than a flat deny.
  5. 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:

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:

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

  1. Sandbox for containment. Limit filesystem, network and credentials, and scope access to least privilege.
  2. Monitor for appropriateness and evidence. Check actions against the user's task, across the whole session.
  3. Stage the rollout. Observe first, block selectively, escalate the ambiguous.

Bring this checklist to your next design review:

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.