Guide
How to Run a Security Review With Cursor (Agent-Driven)
Point the agent at a repo, name the vulnerability classes you care about, and have it fan out one sub-agent per class to build a findings table. Then make it prove every finding with the attack chain, code snippets and a working proof of concept. Many false positives fall apart at that step, before a human reads them.

On this page
- What are the operating principles for security work with an agent?
- How do I review an unfamiliar repository for the first time?
- Are agents better than static code-scanning tools for security review?
- How do I orchestrate a thorough multi-class review?
- How do I stop the agent reporting false-positive vulnerabilities?
- Which Cursor mode and model should I use for security work?
- How do I build secure infrastructure with Plan mode?
- How should I threat-model prompt injection in an AI tool?
- How do I keep credentials away from the agent and gate risky commands?
- How do hooks, rules and Bugbot fit into the review pipeline?
- What stays human, and where does this approach fall short?
What are the operating principles for security work with an agent?
Treat the agent as a fast, fallible delegate. The practitioner who built this workflow works from four tenets:
- Give it real context. Be clear about the work and what good looks like. You no longer need hours of prompt engineering.
- Assume it can be wrong, and build the workflow around any single fact being false.
- Ask for proof when you doubt a claim.
- Ask it anything. An agent can ramp you into an unfamiliar system fast.
Security people are uniquely good at distrusting a confident source, and that instinct transfers directly to working with a model. Distrust is not the same as dismissal.
Being suspicious of the model will come naturally to us. It doesn't mean that it's useless. It just means that you build workflows around assuming that any individual fact you get could be wrong.
The payoff is depth. Agents don't tire, so you can run a deep review on every change instead of a sampled few, and threat-modeling every PR goes from untenable to tenable. The practitioner estimates they became roughly 5x more effective on older models and 7.5 to 10x more effective on the models current at the workshop. Those numbers are self-reported, so read them as one person's estimate.
This is covered hands-on in Agent Mode Foundations — 6 short Units, free to read.
Rather do it than read about it? Run 11 interactive Cursor walkthroughs in a simulated editor. Free, no account needed.
How do I review an unfamiliar repository for the first time?
Ask the agent the questions a security reviewer asks on day one. It returns a digest that would take a long time to assemble by hand, and you can keep asking follow-ups until you understand the system.
- 1Give the agent the repo pointer. A GitHub URL is enough.
- 2Ask how old the repo is, and for the top 10 contributors with their contribution counts and tenure.
- 3Ask for the project's goals, security policy, CI setup and development process.
- 4Ask for a top-level architecture summary, then for an architecture diagram.
- 5Read the disclosure policy: what is in scope, what is out of scope, and whether there is a bug bounty.
Asking for an architecture diagram is one of the strongest ways to ask for proof. It forces the model to commit to a structure you can question. If it picks unreadable colors, say so: "I can't read the diagram with the contrast you have, would you mind fixing that?" It fixes it. A critique costs you one prompt, so ask for fixes freely.
Are agents better than static code-scanning tools for security review?
For most review work, the practitioner's answer is yes. A static rule can't trace context through a codebase the way an agent can, so writing one that follows the full data flow is very hard. In a vulnerability scan, the agent picks the right linter-style checks as it goes. The practitioner's hybrid feeds linter and scanner output to the agent and has it triage.
Agents bring one new failure mode: they make things up. That leaves two problems to manage. A false negative is a vulnerability the agent misses, and a false positive is a non-issue it flags with confidence. They need different countermeasures, because one comes from a vague prompt and the other from the model's drive to be helpful.
- Failure mode
- False negative
- Why it happens
- A bare "find vulnerabilities" doesn't tell it what you care about
- Mitigation
- Prime by vulnerability class ("I'm looking for XSS"), and run parallel runs for the classes you care about most
- Failure mode
- False positive
- Why it happens
- Models are built to be helpful and will fabricate a finding
- Mitigation
- Send every finding through the validation loop: attack chain, code and a working PoC
| Failure mode | Why it happens | Mitigation |
|---|---|---|
| False negative | A bare "find vulnerabilities" doesn't tell it what you care about | Prime by vulnerability class ("I'm looking for XSS"), and run parallel runs for the classes you care about most |
| False positive | Models are built to be helpful and will fabricate a finding | Send every finding through the validation loop: attack chain, code and a working PoC |
Priming by class cuts false negatives, and the validation loop catches fabricated findings.
How do I orchestrate a thorough multi-class review?
Start one agent and have it spawn sub-agents grouped by vulnerability class: infrastructure, AppSec, prompt injection, XSS, and dependencies (SCASoftware Composition Analysis. Scanning third-party dependencies for known vulnerabilities and license problems. Press Enter for the full definition.). Each sub-agentA child agent a main agent spawns to work in parallel with its own context window, handing results back so the parent's context stays clean. Press Enter for the full definition. produces a table of findings. For every finding, it then has to show the full attack chain with code snippets and write a simulated proof of concept.
Sub-agents help here for two reasons: each one runs the validation loop on its own findings, and each vulnerability class keeps its own isolated context. Run this way, sub-agents routinely discover that a chunk of their own findings were wrong.
Interactive diagram. Step through it with the Next and Previous controls below, or Tab to a region to read its detail.
One review run: prime, fan out per vulnerability class, validate every finding, then merge only what survives. Click a step to see what the agent does.
Most teams never review every PR in security depth. There isn't time. Sub-agents that never tire change the economics, so deep review on every change becomes realistic rather than aspirational.
I've never met a security team where every single PR at the company is reviewed in security depth. Things like threat modeling for any change that were previously untenable are now tenable.
How do I stop the agent reporting false-positive vulnerabilities?
Run a validation loop on anything that looks alarming. When the agent reports a finding, say a P0, copy it back and tell the agent you don't believe it. A prompt like this works: "Explain this in depth including the attack chain and relevant code snippets, tell me in detail how it would be exploited, and prove that the exploit works."
The agent re-investigates and often concludes that the finding isn't a vulnerability at all, for example because it is an intentional feature that users invoke themselves. Keep pushing each finding down to the docs and the code until you and the model reach ground truth.
Interactive diagram. Step through it with the Next and Previous controls below, or Tab to a region to read its detail.
Single-finding loop: demand proof, let the agent re-investigate, then accept or dismiss on evidence.
A current model like Opus 4.x is very good at security reasoning if you tell it to reason that way, and better still if you ask it to self-validate. Add this to your review prompt:
When you find security issues I want you to go and do a validation loop: generate a proof of concept and explain the entire chain end-to-end.
Hallucination is normal, and it isn't a reason to stop. In one session the agent claimed a doc line was cut off mid-sentence. A quick "check GitHub, here's the actual text" produced "You're right, I was wrong." Assume the model can and will fabricate, and make it show you the docs and the code. You reach ground truth faster that way than by reviewing alone.
Which Cursor mode and model should I use for security work?
Match the mode to the shape of the task. Use Ask when you want a question answered and don't want the agent touching code, and Agent for quick changes. Use Plan for anything net-new or non-trivial. In Plan modeA mode that makes no edits: it researches the codebase and produces an editable plan you review before any code changes. Press Enter for the full definition. the agent gathers context aggressively before it writes code, so it finds the injection points ahead of time and stays on track during execution.
Keep Debug modeA mode that diagnoses a failure: it reproduces the issue, adds instrumentation and watches the logs, rather than reviewing a pull request. Press Enter for the full definition. in the rotation too. The practitioner's advice is to try all four.
- Mode
- Ask
- Reach for it when
- You want an answer, no code edits
- In security review
- Interrogating a system without touching it
- Mode
- Agent
- Reach for it when
- Quick, contained changes
- In security review
- Small fixes and ad-hoc checks
- Mode
- Plan
- Reach for it when
- Building anything net-new or involved
- In security review
- Enumerate injection points before any code
- Mode
- Debug
- Reach for it when
- Tracing a stubborn failure
- In security review
- Saved real time on a recent hard bug
| Mode | Reach for it when | In security review |
|---|---|---|
| Ask | You want an answer, no code edits | Interrogating a system without touching it |
| Agent | Quick, contained changes | Small fixes and ad-hoc checks |
| Plan | Building anything net-new or involved | Enumerate injection points before any code |
| Debug | Tracing a stubborn failure | Saved real time on a recent hard bug |
Mode picks from the practitioner's own work. Plan mode is the one that won a skeptic over.
For models, pick a daily driver instead of switching all the time. You build an intuition for how one model approaches problems and where it gets stuck. At the workshop, the practitioner's daily driver was an Opus 4.x model. Some GPT-5.x models were very strong on hard problems but slower, so those were the pick when depth mattered more than speed.
When you're undecided, let Auto pick a model for each request. These picks are one practitioner's observations, not Cursor's ranking, so try the models yourself and form your own view.
Interactive widget. Tab through its controls; the result updates in the panel below as you change them.
Match task shape to model: daily-driver reasoning, hard-but-slow depth, design, or let Auto route.
A generated plan once defaulted to an older model name, an artifact of the model's training cutoff: it assumed that was what it had. Tell it explicitly which current model to use, and it updates the plan. Don't let the model's idea of what it is decide your model selection.
How do I build secure infrastructure with Plan mode?
Use Plan modeA mode that makes no edits: it researches the codebase and produces an editable plan you review before any code changes. Press Enter for the full definition. whenever you ship infrastructure, so you see the agent's thinking before it acts. In the worked example, the practitioner deployed a third-party AI tool for a coworker. The safe but usable answer was to keep the tool off the public internet and reach it over a Tailscale connector, which the tool's own docs recommended. It stayed locked down and still reachable from a phone.
In Plan modeA mode that makes no edits: it researches the codebase and produces an editable plan you review before any code changes. Press Enter for the full definition., the agent wrote Terraform into an infra/ directory with good defaults from the docs. The plan kept the tool closed to the internet and added reasonable plugins, so it wasn't trivially prompt-injected.
Read the generated plan carefully, because that is the moment to give feedback. Ask the adversarial question inside the plan: "What if somebody sends my boss something that says to ignore previous instructions and fire me?" Then have a security sub-agentA child agent a main agent spawns to work in parallel with its own context window, handing results back so the parent's context stays clean. Press Enter for the full definition. look for risks in the implementation before you open a PR, so you learn about real issues before the PR exists.
Plan modeA mode that makes no edits: it researches the codebase and produces an editable plan you review before any code changes. Press Enter for the full definition. makes the agent farm context aggressively before building anything, which surfaces the injection points up front and keeps execution on track. For involved or net-new work it's the default; for a one-line change, skip it.
If we're going to build anything net new or make changes to anything that's relatively involved, then I use plan because it will go and find ahead of time all of the injection points.
How should I threat-model prompt injection in an AI tool?
Start from the root cause: current models don't separate control from data. Instructions and untrusted content arrive on the same channel, and the model can't tell how far to trust whoever is feeding it information. Security has seen this mistake before, and AI repeats it. That one fact puts prompt injection at the center of every agent system's threat model.
Because instructions and data share a channel, any untrusted text the agent reads can act as a command. Threat-model accordingly: assume hostile content reaches the model, and design so a malicious instruction can't reach anything dangerous.
There's no separation of control and data... the models are built in a way where they don't understand different trust levels of who's giving them information.
Mitigate with limits on exposure and capability. Keep the tool off the public internet, behind a private network like Tailscale, and add guardrails and plugins so it isn't trivially injected. Then run the adversarial scenario on purpose: "what if an email tells the agent to ignore its instructions and take a harmful action?" Keep changing the design until it has an answer.
How do I keep credentials away from the agent and gate risky commands?
Never hand the agent your credentials, even if you are a GitHub and AWS admin. The practitioner uses a helper script instead: you type something like creds prod, and the script sets environment variables in the shell the agent drives. The agent can then run elevated AWS commands without the credentials entering its context, because it sees the terminal's output, not the shell's environment. That holds only while no command prints those variables.
Approve every state-mutating or network command, and let reads run free. Reading files is low risk. Mutations and network access ask for approval every time, because your user can reach more systems than you would trust the agent with. The agent writes a complex aws ... | jq command faster than a CLI expert could, so a second spent reading it costs little. You approved the command, so the outcome is yours.
The practitioner doesn't gate writes outside the workspace, because they work in git workspaces and reset anything the agent changes. Git can only restore files inside the repository, so check what else on your machine the agent could write to before you copy that choice.
Where you draw the auto-run line depends on your blast radiusHow much breaks if a change goes wrong; the scope of potential damage. Press Enter for the full definition.. A high-privilege admin gates network access and mutations because their user can reach production. A local crypto developer would set it up differently. In Cursor, the Run Mode you pick now draws this line, and depending on the mode, shell commands can run in a sandbox. Check the docs for the current options.
- Command type
- Read files
- Control
- Auto-run
- Why
- Low blast radiusHow much breaks if a change goes wrong; the scope of potential damage. Press Enter for the full definition.; reads are how the agent does its job
- Command type
- Mutate state
- Control
- Approve every time
- Why
- Your user can change things you don't want touched silently
- Command type
- Network access
- Control
- Approve every time
- Why
- Reaches systems where your permissions exceed the agent's trust
- Command type
- Write outside workspace
- Control
- Not gated in this setup
- Why
- Git workspaces let you reset changes, but only inside the repo
| Command type | Control | Why |
|---|---|---|
| Read files | Auto-run | Low blast radiusHow much breaks if a change goes wrong; the scope of potential damage. Press Enter for the full definition.; reads are how the agent does its job |
| Mutate state | Approve every time | Your user can change things you don't want touched silently |
| Network access | Approve every time | Reaches systems where your permissions exceed the agent's trust |
| Write outside workspace | Not gated in this setup | Git workspaces let you reset changes, but only inside the repo |
An allow-reads, gate-mutations-and-network policy, tuned to a high-privilege user's blast radius.
How do hooks, rules and Bugbot fit into the review pipeline?
Layer the controls across the lifecycle. Cursor hooks and rules work while the agent acts: hooks run validation in flight, and rules pin down facts about your codebase that the model keeps getting wrong. BugbotCursor's automated PR reviewer that posts inline findings and can push fix commits from isolated VMs. Press Enter for the full definition. runs at PR time as the last gate before merge. In between, you drive the agent by hand and tell it now and then to find its own bugs.
A rule earns its place when the model repeats a mistake. In one case the model kept assuming port 3000, so a rule stated that the service runs on port 40001.
Interactive diagram. Step through it with the Next and Previous controls below, or Tab to a region to read its detail.
Each control engages at a different point: in flight, then at PR, with manual bug-hunting throughout.
BugbotCursor's automated PR reviewer that posts inline findings and can push fix commits from isolated VMs. Press Enter for the full definition. has caught real security issues in code the practitioner wrote, and it is the final validation loop before merge. Findings come with a one-click Fix in Cursor link, and the older move of pasting the finding back to the agent to evaluate works too. Bugbot is far from the slowest step in the pipeline, and you want it comprehensive.
Rules that apply on every request use context every time, so keep the always-applied set lean. Prefer file-pattern rules, such as all Python files or all scripting files, and nested rules that apply to a folder and its subfolders. A lighter trick is a rule that says "for these top-level operations, consult this document," with the document organized into sections. The agent then knows where to look without loading everything into context.
What stays human, and where does this approach fall short?
Merging stays human.
The agent finds, proves and proposes, and you read every line you would ship and own the outcome. Don't accept "the model thinks it's a vulnerability, therefore it is", or the reverse.
For penetration testing, the workflow already finds bugs and writes proofs of concept, so running a PoC as a live exploit is a small step, and the practitioner sees teams chaining the two. Validation against the source of truth, with full visibility of code and config, is often enough without a live exploit. Never vouch for offensive work you haven't done yourself.
The approach has limits. The effectiveness multipliers are self-reported, not measured. Context-window management used to dominate the workflow, but modern compaction is good enough that a session of roughly 9 hours ran without a single reset. When an agent goes off the rails, recovery is still manual: have it summarize, copy that out, start a fresh agent and paste the summary in.
At the workshop, sandbox and PR security features were teased but not yet announced. Cursor has since documented a sandbox that shell commands can run in, depending on your Run Mode, and Security Agents, which include a reviewer that checks pull requests before they merge. Enterprise-wide controls, such as MCPModel Context Protocol. A standard that lets an AI agent pull in context from outside the repo, like Jira tickets or internal docs. Press Enter for the full definition. governance and org-level policy, are a separate topic from this single-reviewer workflow.
The division of labor that makes this work: the agent codes fast; the human thinks in systems, reasons from first principles and hunts failure cases. Most of the value is in asking the right questions, not typing the code.
Between the two of us, this very capable agent that writes code very fast and my analytical brain, we tend to do stuff well.
Frequently asked questions
Are AI agents better than static scanners for security review?
For most review work, the practitioner behind this workflow says yes. Static rules can't trace context through a codebase the way an agent can. Agents add one failure mode, fabrication, so prime them by vulnerability class to cut false negatives and run a validation loop to cut false positives. A good hybrid feeds linter and scanner output into the agent for triage.
What is the validation loop for agent-found vulnerabilities?
When the agent reports a finding, copy it back and demand proof: explain the attack chain, show the code snippets, describe exactly how it would be exploited, and prove the exploit works. The agent re-investigates and often concludes it isn't a real vulnerability, frequently because it is an intentional feature. You can also tell the model up front to self-validate every finding with a proof of concept.
How do I keep my credentials out of the coding agent?
Use a helper script. You type something like creds prod, and the script sets environment variables in the shell the agent drives. The agent sees terminal output, not the shell's environment, so it can run elevated commands without the credentials entering its context. That holds only while no command prints those variables, so read every elevated command before you approve it.
Which commands should I auto-run versus approve when reviewing with an agent?
Let reads run free, and approve every state-mutating and network command. Reads are low risk and are how the agent does its work. Mutations and network access touch systems where your user has more permission than you want to hand the agent. Git workspaces let you reset unwanted changes inside the repository. Your exact line depends on your own threat model.
Why is prompt injection so hard to defend against?
Because current models don't separate control from data. Instructions and untrusted content arrive on the same channel, and the model doesn't distinguish the trust levels of whoever feeds it information. Mitigate with limits on exposure and capability: keep tools off the public internet, put them behind a private network like Tailscale, add guardrails, and test the adversarial scenario on purpose.
When should I use Plan mode for security work?
Use Plan mode for anything net-new or non-trivial, especially infrastructure. In Plan mode the agent gathers context aggressively up front, finds injection points before it writes code and stays on track during execution. Read the generated plan carefully and give feedback there. For a quick one-line change, skip Plan mode and use Agent mode.
Sources & last verified
- Cursor: Plan mode
- Cursor: Bugbot code review
- Cursor: Rules
- Cursor: Hooks
- Cursor: Run Modes (sandboxing and approvals)
Cursor ships frequently. Last updated October 28, 2026.