PRECEPT: Security Self-Improvement of Coding Agents via Evolving Principles
Organizations: University at Buffalo
Abstract
AI coding agents increasingly write and submit code with limited human review, and much of it passes functional tests while remaining insecure. We show that these failures persist. Across 14 task sequences, Codex, Claude Code, and Qwen Code fixed a vulnerability 85.7% of the time when shown the failing security test, then reintroduced the same vulnerability class in a new session 26.7% of the time, about as often as agents that had never seen it (27.5%). The capability is present; the retention is not. Neither recording the repair in the agent's persistent context nor supplying published secure coding principles closed the gap: the recorded fix stayed tied to the family of the task it came from, and the principles, written for human developers, remained too general to apply to the code at hand. The knowledge exists; it is not activated. We call the missing ability security self-improvement: an agent learns from its own security failures so that each lesson persists across sessions, applies to new code, and does not break what works. We present PRECEPT, which equips coding agents with this ability through an evolving library that starts from authoritative secure coding principles and revises them against the agent's own failures, so that each principle comes to fire on the code where that agent actually goes wrong. A revision is kept only if fresh executions show it makes code more secure while keeping functional success within a small tolerance of the agent without the library. Improvement continues across evolution steps rather than saturating after the first. On task families never seen during evolution, PRECEPT's weakest agent reaches 97.1% secure working code, above the strongest unaided agent at 81.9% and the strongest baseline at 87.7%.
Figures & tables
| Agent | FR | BIR | RR | RG |
|---|---|---|---|---|
| Codex | 78.6 | 30.0 | 24.8 | |
| Claude Code | 85.7 | 27.5 | 25.6 | |
| Qwen Code | 92.9 | 25.4 | 29.2 | |
| All | 85.7 | 27.5 | 26.7 |
| Same family (BIR 36.7) | Other family (BIR 18.3) | ||||
|---|---|---|---|---|---|
| Condition | RR | RG | RR | RG | |
| New session | 0 | 35.6 | 21.7 | ||
| 3 | 35.8 | 18.9 | |||
| 6 | 30.6 | 17.8 | |||
| Same session | 0 | 13.9 | 20.0 | ||
| 3 | 17.1 | 24.0 | |||
| Guidance | RR | RG |
|---|---|---|
| None (BIR) | 27.5 | – |
| (a) Security reminder | 25.3 | |
| (b) All 218 OWASP principles | 24.2 | |
| (c) Relevant OWASP principles | 23.3 | |
| (d) Class-specific principle | 16.7 | |
| (e) Guidance written for the task | 6.9 |
| Primitive | Effect |
|---|---|
| Content | |
| add to document | |
| set field of to text | |
| , | separate or rejoin its details |
| combine two principles into one | |
| , | add or remove a relation |
| Cause | Condition at | Evidence in the records | Primitives |
|---|---|---|---|
| Missing | no has | security test fails | , |
| Unread | with unopened | document not opened before the first edit | , , |
| Misapplied | read, misses the property | security test fails after is read | , |
| Too strict | enforced where holds | functional test fails on valid input | , |
| RG by distance | All | ||||
| Condition | 0 | 3 | 6 | RR | RG |
| (a) At the later task: 36 pairs, BIR 27.5 | |||||
| New session | 26.7 | ||||
| Same session | 19.2 | ||||
| Own note (new session) | 15.0 | ||||
| Precept (new session) | 11.5 | ||||
| Agent | Guidance | p@1 | sp@1 | s@1 | |
|---|---|---|---|---|---|
| Codex | No guidance | 51.3 | 41.7 | 54.4 | 81.3 |
| Security reminder | 49.5 | 41.9 | 56.5 | 84.5 | |
| Seed library | 50.7 | 42.5 | 57.8 | 83.8 | |
| ACE | 44.2 | 37.5 | 47.3 | 84.9 | |
| SkillOpt | 49.3 | 38.8 | 48.4 | 78.8 | |
| RuleEvolve | 51.8 | 43.7 | 53.6 | 84.4 |
| Run | Kept | p@1 | sp@1 | s@1 | |
|---|---|---|---|---|---|
| Precept | 7 | 47.4 | 45.7 | 56.2 | 96.4 |
| w/o organization primitives | 6 | 47.6 | 44.5 | 60.1 | 93.5 |
| w/o acceptance criterion | 19 | 48.1 | 43.3 | 56.1 | 90.0 |
| w/o analyses | 7 | 46.0 | 41.9 | 57.9 | 91.2 |
| w/o revision ledger | 4 | 45.9 | 40.7 | 55.0 | 88.8 |
| w/o execution records | 5 | 46.5 | 39.7 | 54.7 | 85.3 |
| Guidance | p@1 | sp@1 | s@1 | |
|---|---|---|---|---|
| No guidance | 51.4 | 6.9 | 8.7 | 13.5 |
| Seed library | 52.8 | 5.6 | 5.9 | 10.5 |
| Learned on SeCodePLT | 52.1 | 6.9 | 7.3 | 13.3 |
| Learned on SusVibes | 53.5 | 6.9 | 9.7 | 13.0 |
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
| CWE | , same family | , other family | |
|---|---|---|---|
| CWE-77 | 869 | 865 | 851 |
| CWE-79 | 996 | 994 | 1001 |
| CWE-94 | 1128 | 1130 | 1377 |
| CWE-95 | 1180 | 1181 | 1211 |
| CWE-200 | 1266 | 140 | 1395 |
| CWE-327 | 1290 | 353 | 362 |
| Level | Sample guidance added to the task’s prompt |
|---|---|
| (a) | “Make sure to follow best practices for security and avoid common vulnerabilities.” |
| (b) | All 218 principles of the OWASP Secure Coding Practices [ 7 ] , e.g., “Validate data length.” |
| (c) | The three that apply to CWE-770: “Validate data range,” “Validate data length,” and “Truncate all input strings to a reasonable length before passing them to other functions.” |
| (d) | “When code adds caller-supplied data to a shared, long-lived store, bound both the number of entries and the size of each entry, and report the refusal in the way the specification says. Data within the bounds must be stored as before.” |
| (e) | “Store the user’s data only while the cache holds fewer than a fixed maximum of entries and the data has fewer than a fixed maximum of fields; otherwise return False.” |
| (f) | “The reference fix stores the data only if the cache has fewer than 10000 entries and the data has fewer than 1000 items, returning False otherwise.” |
| Codex | Claude Code | Qwen Code | ||||
|---|---|---|---|---|---|---|
| Later task’s family | same | other | same | other | same | other |
| No earlier fix | 31.6 | 52.6 | 31.4 | 54.3 | 25.7 | 60.0 |
| Same session as fix | 71.6 | 67.4 | 70.9 | 70.9 | 79.4 | 60.0 |
| New session after fix | 32.6 | 60.5 | 29.7 | 52.6 | 29.1 | 54.3 |
| New session, verbatim record | 51.1 | 62.6 | 44.6 | 62.9 | 62.3 | 50.9 |
| p@1 | sp@1 | s@1 | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CWE | Name | None | Seed | Precept | None | Seed | Precept | None | Seed | Precept | None | Seed | Precept | ||
| 74 | Injection (downstream) | 40 | 10 | 4.0 | 9.0 | 6.0 | 2.0 | 3.0 | 1.0 | 15.0 | 30.0 | 3.3 | 50.0 | 33.3 | 16.7 |
| 77 | Command injection | 21 | 10 | 69.0 | 62.0 | 46.0 | 69.0 | 62.0 | 46.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 |
| 79 | Cross-site scripting | 40 | 1 | 100.0 | 100.0 | 90.0 | 100.0 | 100.0 | 80.0 | 100.0 | 100.0 | 88.9 | 100.0 | 100.0 | 88.9 |
| 94 | Code injection | 40 | 1 | 100.0 | 70.0 | 80.0 | 100.0 | 70.0 | 80.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 |
| 95 | Eval injection | 30 | 11 | 94.5 | 94.5 | 87.3 | 81.8 | 91.8 | 87.3 | 86.9 | 97.2 | 100.0 | 86.5 | 97.1 | 100.0 |
LLM Agent Self-Improvement
Large language model agent self-improvement studies how agents use experience and feedback to improve their behavior, tools, and workflows.
See all 307 papers