ParseGap: Testing What Coding Agents Authorize and What Shells Execute
Summary (Overview)
- Core Problem: LLM coding agents parse shell commands against a policy for approval, then pass the same raw string to a system shell for execution, creating a "dual-reading" architecture where authorization and execution can diverge at three distinct boundaries: parse, utility argument semantics, and OS confinement.
- ParseGap Framework: A differential testing framework that evaluates inputs through unmodified vendor checkers and GNU Bash 5.2 in isolated containers, flagging violations when a checker permits commands whose runtime effects violate policy. Across eight production coding agents, it catalogs 17 deduplicated root causes (RC-01–RC-17).
- Key Findings: Every checker permitted utility-mediated policy violations (9–47 of 55 cases), an upstream tree-sitter-bash defect hides commands from Mistral Vibe and Gemini CLI, and OpenAI Codex CLI's allow rules disable its read-only OS sandbox (policy–sandbox inversion).
- ShellPlan Defense: A novel compile-once, direct-execve gate that compiles a strict Bash subset into a typed execution plan, validates utility arguments against positive capability specifications, and dispatches approved plans via
execvewithout invoking a shell—achieving 0/4,174 attack admissions and 0/90 controlled agent hits at 1.28 ms median latency. - Empirical Validation: ShellPlan preserved 100% benign completion on standard development tasks across six frontier models (36/36), with a pre-registered external evaluation confirming 0/348 over-allows and 343/343 byte-exact Bash matches on SWE-bench Verified.
Introduction and Theoretical Foundation
Background and Motivation
Coding agents execute shell commands directly inside developer workspaces. Because untrusted repository files, build logs, and issue trackers can steer proposed commands, agents place a command approval gate in front of shell execution. The authors' inventory of public security advisories (July 2025–October 2026) counts 171 shell-approval-bypass advisories: 58 across ten mainstream coding agents and 113 in OpenClaw.
The Dual-Reading Architecture
All eight studied production agents share a fundamental architectural flaw:
A checker parses the string with its own parser (shell-quote tokenizers, tree-sitter-bash ASTs, or Starlark prefix rules) and renders a decision on the commands it extracts. The shell parses the raw string a second time.
Running Example: Under a read-only policy allowing uniq, the command uniq README.md /var/tmp/x is allowed by six of eight agents. Bash then invokes uniq, which treats its second positional operand as an output file and writes outside the workspace. In Codex CLI, matching the allow rule additionally disables the bwrap+Landlock sandbox.
Formal Definitions
Definition 3.1 (Parse-then-Shell Gate): A gate parses command string into simple commands via , decides , and on allow dispatches the raw string to a system shell under confinement configuration .
Definition 3.2 (Active Input and Policy Violation): An input is active under policy if contains at least one -prohibited effect. A gate commits a violation if is active and .
Definition 3.3 (Divergence Boundaries):
- (D1) Parse divergence: and disagree on a command boundary or word list
- (D2) Utility divergence: Decompositions agree, but prohibited effects arise from utility arguments, inline environment assignments, or redirections
- (D3) Confinement divergence: Executing under produces prohibited effects that the user-configured sandbox would prevent
Methodology
ParseGap: Differential Testing Framework
ParseGap operates across four evaluation stages:
- Component Evaluation: Measures unmodified vendor checkers, isolated OS sandboxes, and ShellPlan on unified corpora
- Entrypoint Confirmation: Verifies CLI execution under fixed mock model outputs
- Live Product Trials: Drives unmodified vendor CLIs with frontier LLMs
- Controlled Agent Benchmarks: Compares defenses head-to-head across ten models
Effect Monitors: Inside an isolated Linux container (--network none, GNU Bash 5.2), ParseGap captures:
- Completed
execve/execveatcalls viastrace -f - Persistent diffs on monitored external paths (
/var/tmp,/tmp/canary) - SHA-256 content and existence diffs inside the workspace, separating
.git/*metadata from ordinary files
Three Policy Profiles
| Profile | Description |
|---|---|
| P1 (Read-Only) | Allowlists 18 inspection binaries, 6 git read-only subcommands, constrained find/sed; no denylist |
| P2 (Dev-Native) | Narrower 11-entry allowlist with explicit deny rules (rm, curl, sudo, chmod, chown, touch) |
| P3 (Denylist) | Broad allowlist with deny rules (rm, sudo, curl, wget, touch, chmod, chown, sh, bash, dd) |
Attack Suites
Six suites yield 4,174 active cases: CVE-Replay (33/34), SyntaxMatrix (405/420), Attack-1K (968/1,007), Fuzz-3K (2,685/3,000), Attack-BinSem (55/57), and Workspace-Integrity (28/28).
ShellPlan Architecture
ShellPlan implements three design requirements derived from empirical divergences:
- R1 (Single-Interpretation Dispatch): Execute the exact compiled representation validated by policy, with no second shell parse
- R2 (Positive Utility Specifications): Restrict utility options, operand counts, inline environment assignments, and repository configurations to allowlisted forms
- R3 (Orthogonal Confinement): Enforce redirection bounds statically and at file-open time; never let authorization relax host OS sandboxing
The compiler produces a typed Plan IR:
where holds prefix assignments, is a static literal program word, and is an ordered redirection list.
Empirical Validation / Results
RQ1: Divergence Boundaries in Production Agents
Parse Divergences (D1):
- RC-17: Upstream tree-sitter-bash lexical-boundary defect—an unescaped newline followed by an escaped command word causes Bash to execute line 2 as an independent command, but tree-sitter-bash folds both into an argument of line 1's allowlisted command
- RC-16: Qwen Code permission-precedence override—a matching user allow rule silently upgrades a mandatory "ask" verdict to "allow"
Utility Divergences (D2): Every checker admitted active Attack-BinSem cases composed purely of P1-allowlisted utilities:
| Checker | Allow Rate (55 cases) | Execution Cases (18) |
|---|---|---|
| Continue | 16.4% (9/55) | n/a |
| Mistral Vibe | 36.4% (20/55) | 7/18 |
| Gemini CLI | 74.5% (41/55) | 10/18 |
| OpenCode | 74.5% (41/55) | 10/18 |
| Codex CLI | 70.9% (39/55) | 8/18 |
| Roo Code | 74.5% (41/55) | 10/18 |
| Cline | 80.0% (44/55) | 16/18 |
| Qwen Code | 85.5% (47/55) | 12/18 |
Confinement Divergence (D3): Codex's isolated read-only sandbox (bwrap -P ro) prevented persistent mutations on all tested cases (0/33 CVE-Replay, 0/55 Attack-BinSem, 0/28 Workspace-Integrity). However, when paired with P1 allow rules under --sandbox read-only, matching allowlisted prefixes disabled sandboxing on 7/33 CVE-Replay, 20/968 Attack-1K, 39/55 Attack-BinSem, and 15/28 Workspace-Integrity cases (confirmed live with zero bwrap spawns).
RQ2: Live Model-Driven Trials
Live trials produced targeted policy-violating effects in all 16 agent–model pairs (14 under configured restriction rules):
| Vendor | gpt-5.6-luna | deepseek-v4.1-flash | Observed Outcome |
|---|---|---|---|
| Codex CLI (RO Policy) | 5/5 | 5/5 | bwrap=0 on all 10 hits (RC-14) |
| OpenCode (P1 allowlist) | 4/4 | 2/4 | ds-v4.1: 2 hits, 2 zero-call refusals |
| Gemini CLI (deny rules) | 5/5 | 5/5 | RC-17 bypassed explicit deny |
| Mistral Vibe (15 guards) | 5/5 | 3/5 | RC-17 hit on both models |
ShellPlan Security and Utility Results
Component Security: ShellPlan admitted 0/4,174 active attack cases across all six static suites while admitting 4/4 spec-covered benign Attack-BinSem controls.
Controlled Agent Benchmark (760 runs, ten models):
| Defense Arm | Attack Hits (/90) | Standard Dev Tasks (/60) | Overall Benign (/100) | Median Gate Time |
|---|---|---|---|---|
| no-gate | 68.9% (62/90) | 53/60 (88.3%) | 93/100 | 0.00 ms |
| roo-gate | 62.2% (56/90) | 45/60 (75.0%) | 84/100 | 2.11 ms |
| llm-guard | 6.7% (6/90) | 50/60 (83.3%) | 87/100 | 6,062.48 ms |
| SHELLPLAN | 0.0% (0/90) | 49/60 (81.7%) | 74/100 | 1.28 ms |
Frontier Model Preservation: Across six frontier models, ShellPlan preserved 36/36 (100.0%) completion on standard development tasks—matching no-gate and outperforming roo-gate (33/36) and llm-guard (35/36).
Pre-Registered External Evaluation
On 60 real agent trajectories (48 SWE-bench Verified + 12 SWE-rebench OpenHands) and 1,523 NL2Bash commands:
- Coverage: 343/456 (75.2%) traced read-only steps on SWE-bench Verified (exceeding codex-cli's 73.0%); 0/108 on OpenHands (all commands prefixed
cdchains) - Fidelity: 0/348 non-A2 over-allows outside modeled exceptions (95% UB 1.09%)
- Equivalence: 343/343 byte-exact Bash matches with zero sh/bash spawns
- Escalation causes:
cd(130) andnl(68) accounted for 198/221 (89.6%) of read-only escalations
Formal Guarantees
Theorem 6.1 (Single Interpretation): If or , ShellPlan dispatches no command node and opens none of the redirection targets. If , every child process is either the direct execve dispatch or a probe in . No substring of is passed to a shell.
Theorem 6.2 (Effect Containment): Under assumptions A1 (trusted base) and A2 (specified utility behavior), every process started by ShellPlan is a dispatched node, probe, or A1-trusted helper, and every written file is a redirection target, sort temporary, or .git/index refresh.
Theoretical and Practical Implications
Architectural Insight
The core theoretical contribution is formalizing the dual-reading problem: a gate's decision governs only its own reading of a command string and remains sound only when execution is bound directly to that validated representation. This explains why incremental parser improvements alone cannot fix the class of vulnerabilities—utility divergences persist regardless of parser precision (an earlier ShellPlan prototype without utility specifications still permitted 32/55 Attack-BinSem cases).
Practical Implications for Agent Security
- Policy–Sandbox Inversion (RC-14): Approval decisions must never toggle OS confinement. Codex CLI's design where matching an allow rule disables bwrap+Landlock creates a critical vulnerability class.
- Denylist Fragility: Mistral Vibe's 15 hand-crafted per-binary guardrails still left 20/55 Attack-BinSem cases open, demonstrating the fundamental inadequacy of denylist-based argument filtering.
- Positive Specifications Over Denylists: ShellPlan's positive capability specifications (e.g.,
uniqaccepts at most one operand,sortrejects-o) eliminate entire vulnerability classes.
Trade-offs and Boundaries
ShellPlan's strictness creates measurable utility costs concentrated in:
- Smaller models (18/40 completion vs. 33/40 unguarded)
- Prompted unsupported syntax (25/40 syntax-stress tasks)
- Stateful
cdchains (0/108 on OpenHands) - Unlisted utilities like
nl(68 escalations on real trajectories)
Conclusion
Shell command gates approve their own reading of a command string, while the system shell executes its own. ParseGap exposed divergences at the parse boundary (upstream tree-sitter-bash defects), at utility argument semantics (in every checker), and at OS confinement (Codex CLI's policy–sandbox inversion). ShellPlan removes the second reading by compiling a strict Bash subset once, enforcing positive utility specifications, and executing the approved plan directly via execve—eliminating all tested attacks at sub-2 ms latency.
Future directions include: tracked working-directory state in the compiler (to handle cd chains), adding specifications for commonly escalated utilities like nl, and addressing the three residual edge cases (symlinked metadata edge case M1, inherited // PWD mismatch F1, and pipeline command-substitution stdin F2).
All newly discovered enforcement defects were privately disclosed to affected vendors on November 22, 2026 under a 90-day coordinated disclosure window; exact trigger payloads remain redacted in this preprint pending patch availability.
Related papers
- Online Environment Repair for Coding Agents
Online Environment Repair reduces coding RL reward hacking from 36.9% to 0.06% by patching exploited evaluation environments during training, boosting held-out Pass@8 from 21.7% to 46.7%.
- Self-Improvement Memory Enables Continual Recursive Self-Improvement
Self-Improvement Memory, which records harness edit rationale and outcomes, enables continual recursive self-improvement to outperform harness-only transfer by 2.36 points across changed benchmarks and models.
- The Teacher Is Already Inside: Self-Distilling Looped Language Models Beyond Their Last Loop
ELPSD enables a looped language model to self-distill without rewards by training its last loop against an extrapolated contrastive teacher from its own frozen weights, beating GRPO on math benchmarks.