Security
~9 min readUpdated: November 2026

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

PRECEPT Evolving Security Principles Loop for Autonomous Coding Agents

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%.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

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.

Key Architectural Takeaways
Quick Implementation Exampleprecept-security-gate.ts
precept-security-gate.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Configure a coding agent with PRECEPT-style trigger-scoped security principles
const 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);
Video Guides

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 CauseExecution EvidenceMutation Primitives Applied
MissingSecurity test fails; no matching principleadd(d, pi), edit(a)
UnreadMatching principle exists, file unopened before editentry(d, t), move(pi, d), hub(d, D')
MisappliedPrinciple read, but security property violatededit(k), edit(a)
Too StrictFunctional test fails on legitimate inputedit(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:

AgentGuidance Methodpass@1 (%)secure-pass@1 (%)S\P (Secure Share of Working Code)
CodexNo Guidance51.341.781.3
CodexRuleEvolve51.843.784.4
CodexPRECEPT51.450.698.5
Claude CodeNo Guidance46.336.979.7
Claude CodeACE42.136.987.7
Claude CodePRECEPT49.848.597.1
Qwen CodeNo Guidance45.036.981.9
Qwen CodeSeed Library47.640.785.5
Qwen CodePRECEPT48.947.897.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.

bash
# 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.

Google Search Questions & Answers

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 guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness