PRECEPT: Security Self-Improvement of Coding Agents via Evolving Principles

PRECEPT (arXiv:2611.33519) solves a persistent flaw in AI coding agents: while Codex, Claude Code, and Qwen Code patch 85.7% of vulnerabilities when shown failing tests, they reintroduce the exact same CWE class 26.7% of the time in new sessions. PRECEPT evolves codebase-grounded security principles, lifting secure working code to 97.1–98.5%.
PRECEPT: Security Self-Improvement of Coding Agents via Evolving Principles: PRECEPT (arXiv:2611.33519) solves a persistent flaw in AI coding agents: while Codex, Claude Code, and Qwen Code patch 85.7% of vulnerabilities when shown failing tests, they reintroduce the exact same CWE class 26.7% of the time in new sessions. PRECEPT evolves codebase-grounded security principles, lifting secure working code to 97.1–98.5%. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Closes Cross-Session Security Amnesia: Cuts CWE reintroduction rate (RR) from 27.5% baseline down to 11.5% in new sessions across held-out task chains.
- 97.1%–98.5% Secure Working Code: Raises conditional security share (S|P) on unseen tasks to 98.5% (Codex), 97.8% (Qwen Code), and 97.1% (Claude Code).
- Functional Safety Floor: Uses constrained search over a revision ledger so security rules never break valid functional tests (pass@1 stays ≥ baseline).
- Outperforms ACE, SkillOpt & RuleEvolve: Beats generic prompt playbooks and full 218-item OWASP lists by targeting exact activation triggers.
import { createAgent } from '@smoke-monkey/harness';// Configure a coding agent with PRECEPT-style trigger-scoped security principlesconst secureCoder = createAgent({agentId: 'precept-hardened-coder',provider: 'anthropic',model: 'claude-sonnet-4-5',workspacePath: process.cwd(),systemPrompt:'Before writing code to shared caches or subprocess calls, load matching PRECEPT principles. ' +'CWE-770: Bound both entry count and payload size on long-lived stores while preserving valid writes. ' +'CWE-327/347: Never downgrade signature algorithms or accept unverified JWT tokens.',permissions: {read_file: 'allow',write_file: 'allow',run_command: 'ask',},});async function implementBoundedCache() {const res = await secureCoder.run('Implement session cache store with unit tests and security boundary checks.');console.log('Verified Output:', res.summary);}implementBoundedCache().catch(console.error);
Watch: Related Video Guides
OWASP Top 10 for Agentic Applications 2026 Explained (AI Agent Security)
OWASP Agentic Top 10 Explained: The New Security Risks of AI Agents
Why Coding Agents Reintroduce Security Bugs Across Sessions
In a motivating study across 14 task sequences spanning CWE-77, CWE-79, CWE-94, CWE-200, CWE-327, CWE-347, CWE-770, and CWE-1333, researchers at the University at Buffalo (arXiv:2611.33519) showed that frontier coding agents already know how to fix vulnerabilities—they just fail to activate that knowledge in fresh sessions.
When shown a failing security test, Codex, Claude Code, and Qwen Code fixed the bug 85.7% of the time on average (78.6%, 85.7%, and 92.9%, respectively). Yet when placed in a new session on a follow-up task, those same agents reintroduced the exact same CWE class 26.7% of the time—virtually identical to agents that had never seen the vulnerability (27.5% baseline reintroduction rate).
Supplying all 218 OWASP Secure Coding Practices in the prompt only trimmed the reintroduction rate from 27.5% to 24.2% (+3.3 RG), because human-written guidelines such as 'Validate data length' lack the concrete activation predicate $a(\sigma)$, security property $k(\sigma)$, and validity bound $v(\sigma)$ required to fire during code generation.
How PRECEPT Evolves Executable Security Principles
PRECEPT treats a project's security guidance library $B$ as a structured, evolving codebase artifact governed by formal acceptance criteria: $\max_{B \in \mathcal{F}} J(B)$ subject to $P(B) \ge P(B_\varnothing) - \epsilon_F$, where $J(B)$ is secure-pass@1 and $P(B)$ is functional pass@1.
Each principle $\pi$ models $a(\sigma) \Rightarrow (k(\sigma) \wedge v(\sigma))$: when condition $a$ matches code state $\sigma$, enforce security constraint $k$ while preserving valid behavior $v$. When an execution record fails either security or functional tests, PRECEPT diagnoses four failure classes and applies targeted mutations:
| Failure Cause | Execution Evidence | Mutation Primitives Applied |
|---|---|---|
| Missing | Security test fails; no matching principle | add(d, pi), edit(a) |
| Unread | Matching principle exists, file unopened before edit | entry(d, t), move(pi, d), hub(d, D') |
| Misapplied | Principle read, but security property violated | edit(k), edit(a) |
| Too Strict | Functional test fails on legitimate input | edit(v), edit(a) |
A revision $\delta_t$ enters the library only if paired validation across training tasks confirms higher secure-pass@1 without regressing functional pass@1.
Held-Out Task Family Benchmarks Across Codex, Claude Code & Qwen Code
Across held-out task families never seen during principle evolution, PRECEPT outperformed no guidance, generic security reminders, the full OWASP seed library, ACE, SkillOpt, and RuleEvolve across every coding agent:
| Agent | Guidance Method | pass@1 (%) | secure-pass@1 (%) | S\ | P (Secure Share of Working Code) |
|---|---|---|---|---|---|
| Codex | No Guidance | 51.3 | 41.7 | 81.3 | |
| Codex | RuleEvolve | 51.8 | 43.7 | 84.4 | |
| Codex | PRECEPT | 51.4 | 50.6 | 98.5 | |
| Claude Code | No Guidance | 46.3 | 36.9 | 79.7 | |
| Claude Code | ACE | 42.1 | 36.9 | 87.7 | |
| Claude Code | PRECEPT | 49.8 | 48.5 | 97.1 | |
| Qwen Code | No Guidance | 45.0 | 36.9 | 81.9 | |
| Qwen Code | Seed Library | 47.6 | 40.7 | 85.5 | |
| Qwen Code | PRECEPT | 48.9 | 47.8 | 97.8 |
On individual CWE classes such as Broken Cryptography (CWE-327) and Signature Verification (CWE-347), PRECEPT raised conditional security share $S|P$ from 0.0% to 100.0% and from 50.0% to 100.0%, respectively.
# Run automated functional + security verification gate inside Smoke Monkey
npx @smoke-monkey/harness verify --functional "npm test" --security "semgrep --config auto --error"Structure Principles as Trigger + Invariant + Exception
When authoring AGENTS.md or CLAUDE.md security rules, replace vague imperatives with explicit activation triggers and non-breaking bounds so agents enforce them without rejecting valid inputs.
Frequently Asked Questions
Q:Why didn't adding all 218 OWASP principles to the prompt stop AI coding vulnerabilities?
In the PRECEPT evaluation, adding all 218 OWASP principles reduced vulnerability reintroduction from 27.5% to only 24.2% because general rules like 'Validate data length' lack concrete code-level activation triggers and behavioral bounds.
Q:How does PRECEPT prevent security rules from breaking functional tests?
PRECEPT uses constrained evolution with a strict acceptance gate: a principle mutation is only committed if paired executions improve secure-pass@1 while keeping functional pass@1 within epsilon_F of the unaided baseline.
Q:What secure code rates does PRECEPT achieve on unseen task families?
Among working implementations (S|P), PRECEPT reaches 98.5% secure code on Codex (up from 81.3%), 97.8% on Qwen Code (up from 81.9%), and 97.1% on Claude Code (up from 79.7%).
Q:How does PRECEPT compare to ACE and SkillOpt?
ACE drops Claude Code pass@1 from 46.3% to 42.1% (36.9% sp@1) and SkillOpt reaches 37.6% sp@1, whereas PRECEPT improves both functional pass@1 (49.8%) and secure-pass@1 (48.5%) simultaneously.
Related Alternatives & Comparisons
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.