Because a checked command can become unsafe after environment variables, shell state, or inherited context are poisoned. The security decision has to cover the state around execution, not just the command string that eventually runs.
Why sandbox controls must account for runtime context, not only the command
AI coding agents do not execute in a vacuum. A command that looks acceptable in isolation can become dangerous when the surrounding shell state, environment variables, inherited credentials, or workspace context are already contaminated. Effective sandboxing has to constrain the execution context that the agent inherits, not just inspect the string it eventually runs.
Runtime context matters because coding agents often assemble commands from multiple sources: files, prompts, tool output, repository content, and ambient environment state. If any of those inputs are poisoned, the agent can be steered into using a legitimate-looking command to do the wrong thing. That is why the real control boundary is the execution environment, not the command text alone.
In practice, this means sandbox design has to cover what the agent can read, what it can inherit, and what it can pass onward. A command allowlist is useful, but it is not sufficient when an attacker can influence variables such as PATH, HOME, proxy settings, cloud credentials, shell aliases, working directory, or injected arguments from surrounding tooling.
How runtime context turns a safe command into an unsafe action
The core failure mode is context poisoning. The command may be approved, but the state around it changes the meaning of that command. A shell that resolves a different binary, a process that inherits a sensitive token, or a repo that contains hidden instructions can all convert a benign action into one that exfiltrates data, modifies code, or reaches external services with excessive authority.
This is especially important for AI coding agents because they often operate with broad development privileges. If the sandbox does not separate trusted execution from untrusted context, the agent can be tricked into using developer credentials, reading secrets from the environment, or running commands that appear ordinary while actually targeting a poisoned dependency or malicious repository state.
That is why runtime controls should be designed around trust boundaries, not just syntactic validation. A command is only one step in a chain that also includes input selection, environment inheritance, tool invocation, and any side effects that occur after the process starts.
What a context-aware sandbox should actually constrain
A useful sandbox limits both authority and ambient influence. The agent should run with the smallest viable set of environment variables, file system access, network reachability, and inherited shell state. Where possible, command execution should be isolated from the developer’s interactive shell so that aliases, functions, and local configuration cannot silently rewrite behavior.
For coding agents, the most important question is often not “Is this command permitted?” but “What else can this command reach because of the current runtime state?” That includes credentials already loaded into the session, mounted files, inherited process state, and any workspace-specific trust exceptions that the agent can abuse.
A stronger design treats the sandbox as a policy enforcement layer around execution, with separate controls for command approval, context minimization, and post-execution observation. That approach is much harder to bypass than a static command filter, because the agent cannot rely on hidden state to expand its effective privileges.
Risk and Threat Considerations
Context-poisoned execution creates a real privilege escalation path: an attacker does not need to make the agent run an obviously malicious command if they can first poison the environment that interprets it. The same command can behave differently depending on inherited variables, shell resolution, workspace content, or available credentials.
Failure mechanism: The agent executes an approved command inside a compromised runtime context, so the effective action is determined by hidden state rather than by the reviewed command string. That enables secret exposure, unauthorized network calls, and destructive operations that were not visible in the original approval decision.
Impact: Organisations can lose developer credentials, corrupt codebases, or let an agent act on systems it should never have reached. The blast radius grows quickly when the sandbox allows inherited trust to travel with the process into repositories, APIs, and cloud tooling.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Agentic AI Top 10 and OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST SP 800-53 Rev 5, CIS Controls v8 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Agentic AI Top 10 | ASI03 — Identity & Privilege Abuse | AI coding agents can misuse inherited privilege and context during execution. |
| ASI02 — Tool Misuse | Sandboxing must stop agents from turning trusted tools into unsafe actions. | |
| ASI09 — Human-Agent Trust Exploitation | Poisoned runtime context exploits the trust placed in an apparently valid agent action. | |
| Recommendation — Bind each agent action to least-privilege authorization and separate approval from inherited context. Restrict tool execution to approved scopes and isolate runtime state before calling tools. Add approval gates and runtime checks that validate context, not just the command string. | ||
| NIST SP 800-53 Rev 5 | AC-6 — Least Privilege | Minimising inherited authority reduces the harm from poisoned runtime context. |
| CM-7 — Least Functionality | Reducing available functions and ambient paths narrows what context can influence. | |
| SC-39 — Process Isolation | Isolation is central when runtime state can change the meaning of a command. | |
| Recommendation — Limit the agent to the minimum privileges required for the task. Disable unneeded shell features, binaries, and services in the agent sandbox. Isolate agent execution from the developer session and other untrusted processes. | ||
| CIS Controls v8 | CIS-6 — Access Control Management | Sandbox context control depends on restricting who and what the agent can reach. |
| CIS-8 — Audit Log Management | Runtime context abuse is easier to detect when execution is well logged and attributable. | |
| Recommendation — Restrict agent access paths and remove unnecessary credentials from its execution context. Log agent command execution, inherited context, and sensitive access events for review. | ||
| NIST Zero Trust (SP 800-207) | SC — Continuous Verification of Request and Context | Zero trust requires evaluating the request and its runtime context before execution. |
| Recommendation — Verify the agent, the request, and the execution context before allowing action. | ||
| OWASP Non-Human Identity Top 10 | NHI-04 — Insecure Authentication | Agent sandboxes often fail when runtime context exposes or reuses authentication material. |
| Recommendation — Prevent the agent from inheriting or replaying authentication material across executions. | ||
Practitioner Guidance
What to prioritise: Constrain the runtime environment before you perfect command allowlists. If the agent can inherit sensitive variables, writable paths, or broad network access, command review alone will not keep it safe.
What to verify: Check which values are inherited into the process, which binaries will actually resolve at runtime, and whether the agent can read secrets from the same session it uses to execute tools. That verification should happen in the real sandbox, not on paper.
Decision rule: If the command would be harmless in a clean environment but unsafe in a poisoned one, treat sandbox hardening as a context problem first and a command-policy problem second.
Practitioner takeaway: The right control objective is not “approve good commands,” it is “make dangerous context unable to alter a permitted command into a harmful action.”
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 10, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org