AI Agents for Vulnerability Discovery: Architecture and Implementation Essentials
AI agents are increasingly being applied to vulnerability discovery, but simple code-review prompts often produce generic findings. This article outlines an engineering approach: code understanding and call-chain analysis, hypothesis generation with sandbox validation and human review, and structured reporting. It also covers least-privilege tool configuration, reusable skill modules, a cloud-native deployment checklist, and applicability boundaries. It emphasizes authorized targets, isolated environments, audit logging, and reproducible findings, while noting that current AI vulnerability-discovery statistics are inconsistent and should not be generalized.
In the past year or two, more security teams have begun experimenting with LLMs in vulnerability discovery. Unlike the early approach of pasting code into a model and asking whether it contains vulnerabilities, more mature workflows let AI agents work the way a security researcher does: read code, form hypotheses, write validation scripts, observe results, and organize reports. It is important to note that current figures on the number and proportion of vulnerabilities found with AI often come from disclosures by individual vendors or research teams, and their statistical definitions vary. They should not be directly generalized as industry-wide conclusions. This article discusses technical methods and engineering essentials only, without judging specific proportions.
Why Simple Prompting Falls Short
Asking a model to review code directly often produces generic advice such as “strengthen input validation” or “watch buffer boundaries.” Such conclusions apply to most code, so they are of limited help in locating a specific defect and tend to generate many false positives. The root cause is that the model sees only code fragments, without a runtime environment or validation steps.
Two forms need to be distinguished. Code completion or syntax-checking plugins only provide hints in an editor and are auxiliary tools. Automated discovery agents can read code, execute commands, observe runtime results, and complete full validation around a hypothesis. The difference lies in whether they form a closed loop of “analysis, validation, and re-analysis.”
Basic Agent Architecture
1. Code Understanding and Call-Chain Analysis
Large projects often contain hundreds of thousands of lines of code. Agents usually start with static analysis tools or code retrieval tools to build indexes of entry functions, call relationships, and data flows, and then let the model reason along a data path. The model’s long-context capability determines how much context it can analyze, while retrieval tools determine whether it can find cross-file associations. If either is insufficient, the reliability of conclusions drops noticeably.
2. Hypothesis Generation and Sandbox Validation
When an agent finds a suspicious point, it proposes a testable hypothesis, for example: “a parameter that exceeds the expected length and is not filtered may cause an out-of-bounds write.” The hypothesis must be falsifiable. The agent then writes test cases in an isolated environment, executes them, and records the results. This step must satisfy three constraints.
First, failure criteria. Before validation begins, it should be clear what result counts as “confirmed” and what counts as “not confirmed,” such as a crash signal, an abnormal return code, or specific response content. Without criteria, agents can mistake intermittent phenomena for vulnerabilities.
Second, human review. Any conclusion that enters a report should be reproduced by an engineer in the same environment to confirm that no false positive has arisen from environment differences.
Third, sandbox limits. CPU, memory, disk, and network egress should be restricted to prevent test code from affecting the host or external systems. The sandbox itself may also have escape risks, so it needs regular updates and should be included in security baseline management.
3. Report Generation
After validation passes, the agent summarizes trigger conditions, key logs, crash stacks, and minimized PoC code, and writes root-cause analysis and remediation suggestions. Report quality can be evaluated with the following checklist: whether the conclusion is reproducible, whether the impact scope is clearly stated, whether remediation advice is specific, and whether the PoC has removed irrelevant content.
How to Configure a Security Agent
1. Toolchain and Permissions
Common tools for agents include code search, sandbox execution, and network capture. Each tool should have an independent permission declaration and expose only the minimum capability needed to complete the task. Below is an illustrative configuration; fields should be adjusted to the team’s actual workflow:
{"task": "Check authorized open-source web service source code for unauthorized access","target_scope": {"repository": "internal audit repository, branch audit-2026q4","allowed_hosts": ["192.168.10.0/24"],"authorization_ref": "audit contract number or written authorization document number"},"tool_permissions": {"code_search": "read_only","sandbox_exec": "isolated_container","network_capture": "allowed_hosts_only"},"sandbox_limits": {"cpu_cores": 2,"memory_mb": 2048,"egress": "deny_all","timeout_sec": 300},"max_iterations": 15,"stop_conditions": ["Hypothesis validated or falsified","max_iterations reached","target_scope exceeded or sandbox limit triggered"],"failure_criteria": "If the response status code differs from the baseline and cannot be reproduced, mark it for review; do not count it as a vulnerability","audit_log": "Record the time, parameters, and return summary of each tool call","human_review": "A security engineer must reproduce and confirm before the finding enters the report"}
The fields serve the following purposes. target_scope limits the test objects and prevents the agent from accessing hosts outside the authorized scope. tool_permissions sets permissions by tool; code search only needs read-only access. sandbox_limits controls resource usage and denies egress by default. stop_conditions prevent infinite loops. audit_log makes every operation traceable. human_review is the final gate.
Validation actions may only target systems for which written authorization has been obtained, run in isolated sandboxes, and use least-privilege accounts. Production environments and unauthorized systems must not be used as validation targets.
2. Accumulating Skill Modules
When a general-purpose model lacks domain-specific experience, it often tries ineffective paths repeatedly. Security experts can codify past analysis approaches, fuzzing templates for certain protocols, and audit priorities for specific codebases into skill modules that agents load in relevant scenarios. Skill modules also need version management and review so that outdated or incorrect experience does not affect judgment over time.
Cloud-Native Deployment Checklist
Running security agents involves compilation, sandbox execution, and log analysis, which places high demands on resource quotas and environment isolation. The following items can be checked one by one during deployment.
- Container isolation: each validation task uses a separate container that is destroyed after the task ends; runtime environments are not reused.
- Network policy: deny outbound traffic by default and allow only authorized target addresses.
- Object storage permissions: set minimum read/write permissions separately for source packages, vulnerability signature databases, and intermediate validation data, and enable access logs.
- Log redaction: execution logs may contain secrets, tokens, or personal information and must be filtered before being written to storage.
- Resource quotas: set CPU, memory, and runtime limits for each task to prevent a single task from exhausting cluster resources.
- Behavior monitoring: track tool call frequency, failure rate, and resource consumption to detect anomalous behavior and adjust policies.
Applicability Boundaries and Alternatives
Agents work relatively well in scenarios with large codebases, repeated checks for similar patterns, and validation steps that can be automated. Their effectiveness is clearly limited when business logic depends on a large amount of implicit context, when vulnerability reproduction requires physical devices or complex environments, or when the model lacks knowledge of a certain protocol.
If a team does not yet have sandbox and audit infrastructure, it can start with traditional static analysis tools plus manual review, or use mature fuzzing frameworks to complete part of the work. The main value of agents is shortening the cycle from hypothesis to validation; they cannot replace a complete security process.
Conclusion
LLMs are expected to significantly change how security auditing is performed. They can take on a large amount of repetitive work such as reading code, writing tests, and organizing logs, allowing security engineers to focus on judgment and decision-making. Whether they can further replace human work depends on model capability, authorization scope, tool quality, and the maturity of review mechanisms. Before introducing agents, teams should define authorization boundaries, establish sandbox and audit processes, and then gradually expand their use.
