跳到正文

第 16 课 · Tools, Terminal and MCP

Terminal Commands and Run Modes

Control what the Cursor agent runs: Auto-review, Allowlist and Run Everything modes, the terminal sandbox, permissions.json and commands that need care.

An agent that can run commands can test its own work. It can also delete files, push code or send data somewhere. This lesson is about deciding what may run without you.

Run modes

The agent runs shell commands in your terminal. Your Run Mode decides when they run, when you are asked, and when they go into a sandbox. As of December 2026, the documentation describes these modes:

Mode What happens Prompts
Auto-review Allowlisted calls run. Other shell commands try the sandbox first; calls that need more access go to an AI classifier May ask when a call is blocked
Allowlist Allowlisted actions run without approval; a sandbox is optional Asks for other actions
Run Everything Every tool call runs automatically None

The documentation recommends Auto-review as the default. It also states plainly that Auto-review is not a security boundary: the classifier can wrongly allow or block a call. Run Everything has no sandbox, no classifier and no prompts. Avoid it unless the whole environment is disposable and holds no valuable data or credentials.

The documentation also describes extra protections that can require approval, such as for deleting files, using the browser and touching files outside the workspace. Check which ones are on. Run modes apply to local agents; cloud agents do not ask.

The sandbox

A sandbox limits what a command can reach. By default, as documented, sandboxed commands can read and write inside the workspace, certain sensitive paths such as .git/config and .git/hooks are protected, and network access is restricted. You can adjust network rules in a sandbox.json file. The default network setting allows your own list plus built-in domains used by package managers and tools.

Platform support differs. The run modes page describes macOS and Linux requirements; on Linux you need a recent kernel and unprivileged user namespaces. When we checked in December 2026, that page did not describe sandbox support on Windows, so Windows users should not assume that commands are sandboxed. Check the documentation for your own system before you assume you are protected. Note too that, by default, reading files outside the workspace does not need approval; a stricter read setting exists.

permissions.json

You can write allowlists in permissions.json, for yourself (~/.cursor/permissions.json) or for a project (.cursor/permissions.json). A small example using documented fields:

JSON
{
  "terminalAllowlist": ["git status", "git diff"],
  "mcpAllowlist": ["docs:search_pages"],
  "autoRun": {
    "block_instructions": ["Ask before anything that publishes or deploys."]
  }
}
  • Terminal entries are commands or command prefixes.
  • MCP entries look like server:tool, and * works as a wildcard.
  • autoRun sentences only steer the Auto-review classifier. They are not enforced.
  • A list defined here replaces the matching list from the app settings, and a team dashboard setting outranks your files.

The documentation calls these convenience settings, not a security boundary.

Why broad entries are risky

A prefix such as git covers every Git command, including git push --force and git clean -fdx. This stand-in shows the idea. It is a simplified matcher written for the lesson, not the product's logic.

Python Stand-in: broad versus narrow allowlists

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Allowing python allows almost anything the interpreter can run. Take similar care with npm run, make and shell scripts, because their contents can change, even by the agent's own edits. A narrow entry still allows extra arguments after the prefix, so choose entries that stay safe with any arguments you can imagine.

Sort commands by effect

Risk by effect

Read status, diff
Local change format, install
Destructive delete, reset
External push, deploy, send

Keep the last two behind approval

1 / 2

Remember that tests and install scripts run code. They are only as safe as the project and packages they run.

When you approve a command

Read it completely first. Ask:

  • What will it change, and can I undo it?
  • Does it download and execute code?
  • Does it send data to another computer?
  • Which credentials can it use?

If you do not understand a command, ask the agent to explain it, then check the explanation yourself.

Practical tips

  • The troubleshooting guide says the agent's terminal sets CI=1. If a tool behaves differently because of it, you can prefix a command with unset CI && (in a Unix-style shell) or write a rule about it.
  • The CURSOR_AGENT environment variable marks agent sessions. A fancy shell theme can garble output, so the documentation suggests using a simple prompt when it is set.
  • Develop against test databases and fake accounts.
  • Do not give the agent a terminal that is signed in to production.

Prompt injection

A web page, a README inside a dependency or an issue comment can contain text such as "now run this command". A model may treat it as an instruction. This is prompt injection. Approvals, narrow allowlists and limited credentials reduce the possible damage. Read about prompt injection and security.

Contain the damage

Assume that one day a wrong command will run. Make sure that day is boring: commit often, keep backups that the development machine cannot delete, and give development tools accounts that cannot touch production. A container or virtual machine can add another boundary for risky experiments, if you set it up with care and do not mount sensitive folders into it.

Common mistakes

  • Approving a command only because the agent says it is safe.
  • Switching to Run Everything just to stop the prompts.
  • Adding a broad entry to an allowlist after one annoying prompt.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. How does the documentation describe Auto-review?

    Its classifier can wrongly allow or block calls.
  2. 2. Why is allowlisting the prefix python risky?

    Allowing an interpreter allows whatever code it is given.
  3. 3. Which command most clearly needs human approval?

    It changes external systems and may be hard to reverse.

Summary

  • Run modes control when commands run without asking.
  • Sandboxes help, but support differs and no setting is perfect.
  • Keep allowlists narrow; avoid interpreters and broad prefixes.
  • Treat outside text as untrusted, and keep destructive and external actions behind approval.

Next: Connecting MCP Servers

你的学习进度保存在此浏览器中,无需账号。