# ParseGap: Testing What Coding Agents Authorize and What Shells Execute

> Coding agents approve commands based on their own parse while shells execute a different one, enabling systematic policy bypasses that ShellPlan eliminates via single-interpretation direct execve dispatch.

- **Source:** [arXiv](https://arxiv.org/abs/2611.29546)
- **Published:** 2026-11-28
- **Permalink:** https://picx.dev/p/Av48Qv
- **Whiteboard:** https://picx.dev/p/Av48Qv/image

## Summary

# 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 `execve` without 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 $G = (parse_G, rules_G, \kappa_G)$ parses command string $s$ into simple commands via $parse_G$, decides $\delta_G(s) = rules_G(\twoheadrightarrow e_G(s)) \in \{\text{allow}, \text{ask}, \text{deny}\}$, and on allow dispatches the raw string $s$ to a system shell under confinement configuration $\kappa_G(s)$.

**Definition 3.2 (Active Input and Policy Violation)**: An input $s$ is *active* under policy $\Pi$ if $Eff(s, \sigma)$ contains at least one $\Pi$-prohibited effect. A gate commits a violation if $s$ is active and $\delta_G(s) = \text{allow}$.

**Definition 3.3 (Divergence Boundaries)**:
- **(D1) Parse divergence**: $parse_G(s)$ and $cmds_B(s)$ 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 $\kappa_G(s)$ produces prohibited effects that the user-configured sandbox would prevent

---

## Methodology

### ParseGap: Differential Testing Framework

ParseGap operates across four evaluation stages:

1. **Component Evaluation**: Measures unmodified vendor checkers, isolated OS sandboxes, and ShellPlan on unified corpora
2. **Entrypoint Confirmation**: Verifies CLI execution under fixed mock model outputs
3. **Live Product Trials**: Drives unmodified vendor CLIs with frontier LLMs
4. **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`/`execveat` calls via `strace -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:

$$P := c \mid P; P \mid P \&\& P \mid P \mid\mid P \mid P \mid P, \qquad c := \langle A, w_0 w_1 \dots w_n, R \rangle$$

where $A$ holds prefix assignments, $w_0$ is a static literal program word, and $R$ 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 `cd` chains)
- **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) and `nl` (68) accounted for 198/221 (89.6%) of read-only escalations

### Formal Guarantees

**Theorem 6.1 (Single Interpretation)**: If $\text{Compile}(s) = \text{Escalate}(r)$ or $\Pi \nvdash P \text{ ok}$, ShellPlan dispatches no command node and opens none of the redirection targets. If $\Pi \vdash P \text{ ok}$, every child process is either the direct `execve` dispatch or a probe in $\mathcal{H}$. No substring of $s$ 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

1. **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.
2. **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.
3. **Positive Specifications Over Denylists**: ShellPlan's positive capability specifications (e.g., `uniq` accepts at most one operand, `sort` rejects `-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 `cd` chains** (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.

---

_Markdown view of https://picx.dev/p/Av48Qv, served by PicX — AI-generated visual whiteboard summaries of research papers._
