Guide
How to Tell an AI Coding Agent What Not to Touch
Tell an AI coding agent what not to touch by naming protected files, generated code, public contracts, data migrations and style-only areas before it edits anything. Each non-goal you name is a guardrail that keeps the diff small enough to review carefully.

On this page
What does a reviewable agent task look like?
Give the agent one named task, only the context it needs and a check you can rerun. A task shaped this way produces a diff small enough to review and a result you can repeat.
- Move
- Start with a bounded task
- Use this when
- You have a named owner, target files and a clear done state
- Proof to save
- Issue, files, checks and owner are named
- Move
- Give the agent context
- Use this when
- The repo has patterns the agent must follow
- Proof to save
- Prompt cites files, errors and constraints
- Move
- Review the diff
- Use this when
- The task changes production code
- Proof to save
- Changed files, test output and risks are visible
| Move | Use this when | Proof to save |
|---|---|---|
| Start with a bounded task | You have a named owner, target files and a clear done state | Issue, files, checks and owner are named |
| Give the agent context | The repo has patterns the agent must follow | Prompt cites files, errors and constraints |
| Review the diff | The task changes production code | Changed files, test output and risks are visible |
Each move leaves proof that a reviewer can check later.
Each move fails in its own way. Without a boundary, the agent edits files you never meant to open, and the diff becomes hard to read. Thin context fails more quietly: the code compiles and the tests pass, but the change ignores patterns the rest of the repo follows. Without a check you can rerun, you are taking the agent's word that the work is done.
Asking for a plan before the agent writes code is the easiest step to skip. It means a short wait while nothing visible happens, and the price of skipping it shows up later, in review.
If the plan names files you didn't expect, you learn that before any code exists. If it names the right files, you have a list to check the diff against. Once four hundred lines of diff are on screen, changing the approach means throwing that work away.
Interactive widget. Tab through its controls; the result updates in the panel below as you change them.
Open each stage to see what a reviewer should be able to inspect.
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 should a team run each agent task?
The habit that matters most for a team is leaving a trail the next reviewer can follow. The steps below keep the prompt and its proof attached to the change.
- 1Pick one real backlog item with a clear owner and expected result.
- 2Add only the context the agent needs: files, failing output, constraints and done state.
- 3Ask for a plan before code when the task touches more than one file.
- 4Run checks that match the risk: unit test, typecheck, visual pass or review checklist.
- 5Capture the prompt, diff, result and reviewer note so the workflow can be repeated.
Match the effort to the change. A one-file fix needs a clear done state and a typecheck, and a plan adds little. A change across several files is where a plan pays for itself, and where the check should include tests and a reviewer who knows that code.
What should you keep after the run?
Keep whatever lets someone rerun the work or pick it up later. A finished task is the merged code plus a short trail that shows how it got there.
- The prompt or plan that shaped the work.
- The files changed and the reason each file changed.
- The command, screenshot or review note that proved the result.
- The rule, checklist or template you would reuse next time.
The last item pays off over time. A rule or template saved from one good run means the next run starts from what already worked, not from a blank prompt.
Should the boundary live in the prompt, a rule, or a hook?
Use all three, in that order, and stop as soon as the boundary holds. A non-goal in the prompt covers one task, and a rule covers a convention. A hook covers what must not happen even when the model has talked itself into a good reason.
The rule layer is an .mdc file under .cursor/rules/ with a glob in its frontmatter. A rule scoped to **/*.tsx with alwaysApply: false is attached only when a matching file is in context. That makes file-scoped boundaries cheap enough to keep several of them.
Enforcement is what separates the third layer from the first two. Rules are instructions the model tries to follow, so they shift the odds without setting a floor. A hook is a script you write and check into the repo. It runs at fixed points in the agent loop, including before a file read and before a shell command, and your code returns allow or deny, whatever the model decided.
Put anything load-bearing in a hook, and set failClosed: true on it. By default, a hook that crashes or times out lets the action through.
Escalate when you catch yourself repeating a boundary. The second time you type the same non-goal into a prompt, turn it into a rule. When you watch the agent walk past a rule, turn that rule into a hook.
Does .cursorignore stop the agent touching a file?
Not reliably. .cursorignore keeps files out of agent file reading and context selection, which is useful. Cursor's docs call it a convenience feature, not a security boundary. Users can still open an ignored file by hand, and terminal commands and 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. tools can still read it.
The risk is a false belief. You add a path, watch it disappear from context, and treat that part of the tree as fenced off. Then an agent with shell access reads the file through a command, because the shell does not know the editor was told to look away.
For anything that must not be read, Cursor's documented answer is file system permissions or encryption, with a hook on top to scan or block access. Keep .cursorignore for what it does well: keeping secrets and noise out of the context you pay for.
What goes wrong if I just list everything the agent must not touch?
Every other instruction gets slightly worse. A rule that carries one instruction plus three hundred others spreads the model's attention across all of them, and that attention is finite.
When Cursor's field engineers explain output quality, they put model choice ahead of context, at something like 60/40 to 70/30. Context is still the share you control, so filling it with prohibitions that have nothing to do with today's task is a poor trade. A presenter in Cursor's JetBrains workshop said Cursor's own rules run about eight lines.
So add a boundary when you catch the agent crossing it, instead of listing everything it could conceivably do. Leave style rules to the linter, because deterministic tooling enforces deterministic rules better than a paragraph of English.
Team size changes who owns the list. On a small team, two or three scoped rules plus a line in the prompt match the risk. In a larger organization, the boundaries that matter ship as enterprise hooks through MDM. Every matching hook runs and a deny from any of them wins, so a developer's own hooks can't override that block. Rules and hooks can also ship as plugins in a team marketplace that admins limit to selected Organization Groups, so the design team doesn't load the security team's prohibitions.
Frequently asked questions
Who is this guide for?
Developers and team leads trying to reduce agent overreach.
What should I do next?
List the non-goals for your next task in the prompt. When you type the same one a second time, make it a scoped rule, and move anything load-bearing into a hook with failClosed: true.
Does .cursorignore stop an agent from reading a file?
Not reliably. It keeps files out of agent file reading and context selection, but Cursor's docs call it a convenience feature, not a security boundary. Terminal commands and MCP tools can still read an ignored file. For anything that must not be read, use file system permissions or encryption, with a hook that blocks access.
Should a boundary go in the prompt, a rule or a hook?
Escalate as you need to. A non-goal in the prompt covers one task, and a rule scoped with a glob covers a convention. A hook is a script that runs at fixed points in the agent loop and returns allow or deny whatever the model decided, so put anything load-bearing in a hook. A hook that crashes or times out lets the action through by default, so set failClosed: true on a security-critical one.
Sources & last verified
- Cursor agent best practices
- Cursor Learn: working with agents
- Cursor Learn: context
- Cursor docs: prompting agents
- Cursor docs: Hooks
- Cursor docs: Rules
- Cursor docs: LLM safety and controls
- Cursor docs: Ignore file
- Cursor docs: Plugins
- Cursor docs: Organization Groups
Cursor ships frequently. Facts verified against primary sources on October 28, 2026.