Cursor hooks security for teams

Cursor hooks let your own script check an agent action before it runs: a shell command, an MCP call, a file read or a file write. To make them a security control, install them at the enterprise level, set failClosed: true on the checks that matter, answer deny or ask for risky actions, and keep a record of every decision outside the developer's laptop.

Last updated: · Checked against cursor.com/docs/hooks on 15 November 2026

Works with Claude Code · Cursor · Codex

Contents

How to secure Cursor for a team

Securing Cursor for a team comes down to five settings:

  1. Put the guard hooks above the project. Enterprise or user-level hooks.json, not the repo's, so the agent cannot edit its own guard.
  2. Fail closed where it matters. failClosed: true on hooks that guard shell commands, MCP calls and file writes, with an explicit timeout.
  3. Check what the agent reads as well as what it runs. Files, web pages and MCP results can carry prompt injection; flag the session and hold risky follow-up actions.
  4. Keep secrets out of reach. Deny reads of .env, key files and credential folders, and block commands that print them.
  5. Record every decision. Who ran which agent, what it tried, what was allowed, blocked or held, in a log you can export.

The sections below explain each one.

Which Cursor hooks can stop an action

Cursor runs hooks at fixed points in the agent loop. The ones that can stop something before it happens:

  • beforeShellExecution: allow, deny or ask on a terminal command.
  • beforeMCPExecution: allow, deny or ask on an MCP tool call.
  • beforeReadFile: allow or deny a file read.
  • preToolUse: allow or deny a tool call such as Write or Delete; it can also return updated_input. "ask" is accepted by the schema but not enforced here.
  • beforeSubmitPrompt: runs on each prompt and can stop it before it is sent.

The reply is JSON with permission, plus user_message (shown to the developer) and agent_message (sent to the model). When several hooks answer, deny wins over ask and ask wins over allow. Exit code 2 blocks, like a deny. Source: cursor.com/docs/hooks.

Fail open is the default. Decide where that is acceptable

If a hook crashes, times out or exits with an unexpected code, Cursor lets the action run by default. failClosed: true on a hook makes those failures block instead (a permission hook that returns invalid JSON blocks even without it). Our recommendation from building a Cursor connector:

  • Shell, MCP and file writes: failClosed: true. A missing check on rm -rf or a push is worse than a short wait.
  • File reads: fail open is often fine, unless the path matches secrets.
  • Set an explicit timeout (in seconds) so a slow network does not stall the agent forever.

In SecGuardRail, if our policy service cannot read its database it answers 503, and Cursor applies the failClosed setting you chose for that hook.

Where hooks.json lives, and why that matters for security

Cursor merges hooks from four levels, highest first: Enterprise, Team, Project, User.

  • Enterprise: a system-wide hooks.json that a standard user cannot edit (paths below).
  • Team: set in the Cursor dashboard (Enterprise plans) and synced to all team members every thirty minutes.
  • Project: .cursor/hooks.json in the repo.
  • User: ~/.cursor/hooks.json.
Windows:  C:\ProgramData\Cursor\hooks.json
macOS:    /Library/Application Support/Cursor/hooks.json
Linux:    /etc/cursor/hooks.json

A security hook in the user or project file can be edited or deleted by the developer, or by the agent itself. Put guardrail hooks at the Enterprise or Team level. Note that cloud agents load project hooks but not user hooks.

Hooks that arrive with the workspace

Project hooks are code that ships with the repo. Pillar Security reported that Cursor Desktop 2.4.37 could run Claude hook commands from a .claude/settings.local.json written into the workspace, without the approval users expect (Pillar Security; CVE-2026-48124, Cursor advisory GHSA-pc9j-3qc2-95wv). Cursor fixed it in 3.0.0.

Treat any hook config in a cloned repo like a dependency: review it, and deny agent writes to .cursor/hooks.json, .claude/settings*.json and other hook config. SecGuardRail ships these denies in an always-on Tamper Protection pack and raises a Critical alert on each attempt; our installer keeps an existing company hooks.json instead of overwriting it.

Example: one policy check for every risky Cursor action

{
  "version": 1,
  "hooks": {
    "beforeShellExecution": [{ "command": "./guardrail-hook.sh", "failClosed": true, "timeout": 10 }],
    "beforeMCPExecution":   [{ "command": "./guardrail-hook.sh", "failClosed": true, "timeout": 10 }],
    "beforeReadFile":       [{ "command": "./guardrail-hook.sh", "timeout": 5 }],
    "preToolUse":           [{ "command": "./guardrail-hook.sh", "failClosed": true, "timeout": 10 }]
  }
}

The script sends the event to a policy engine and prints its answer, for example:

{
  "permission": "deny",
  "user_message": "Push to main needs approval (policy: Protect main)",
  "agent_message": "Blocked by team policy."
}

Approvals: hold a risky action for a person

ask on shell and MCP shows the developer a prompt, which is good for a single user. For a team, the reviewer is often someone else. SecGuardRail holds the call and sends a Slack alert whose Review request link opens the approval in the dashboard; the developer sees the request number and when to retry; the request and the decision both go into the audit log. Cursor's user_message carries the full reason to the developer, and agent_message carries the level of detail you choose for the model.

Prompt injection in Cursor: watch what the agent reads

A README, issue or MCP result can carry text aimed at the agent. In our tests a Cursor agent read a README with injected instructions; the read was allowed and the session was marked tainted, and the agent's next step, a curl to an outside host, was held for approval with the reason "Read /repo/README.md". Detection alone misses plain-language instructions planted in data (our rule-based detector: 0 false positives on 795 benign samples, 35% recall overall), so holding the risky follow-up actions matters more than catching every injected line. Limit: beforeSubmitPrompt has no field to add context, so a prompt warning is recorded and alerted but not shown to the model.

Secrets and audit

Check shell commands and MCP input for credentials before they run (45 provider formats plus named values scored by entropy), block credentials sent to a host other than localhost, and redact secrets before anything is stored or sent to Slack. Record every Cursor decision with the device, action, policy and approver, hash-chained so an edited or deleted record breaks the chain, and export it off the laptop. One policy set covers Cursor and Claude Code: a rule for Bash or Read also decides Cursor's shell commands and file reads.

Honest limits

  • Cursor has no general "stop session" reply, so the hooks can deny individual calls and prompts, not whole sessions.
  • The hook does not send the repository name, so repo-scoped rules need the Policy Check API.

Cursor hooks security checklist

  1. Guardrail hooks at Enterprise or Team level, not user or project.
  2. failClosed: true on shell, MCP and write hooks; explicit timeout.
  3. deny for destructive commands and secret reads; ask or hold for push, deploy and permission changes.
  4. Deny agent writes to .cursor/hooks.json and other hook config.
  5. Review hook config in cloned repos before opening them in agent mode.
  6. Taint and hold after reading untrusted content (web, README, MCP).
  7. Secret checks on commands and MCP input; redact before logging.
  8. Audit log of every decision, exported off the laptop.

FAQ

How do I secure Cursor for a team?

Put guard hooks in enterprise or user-level hooks.json, set failClosed on shell, MCP and write hooks, deny secret paths, hold risky actions for a person, and keep an exportable audit log of every decision.

Do Cursor hooks fail open?

Yes, by default. Set failClosed: true per hook to block when the hook crashes or times out.

Can a developer turn the hooks off?

User and project hooks, yes. Enterprise and Team hooks are managed centrally, which is why guardrails belong there. A local administrator can still remove files; a silence alert (a device that stops sending events) tells you.

Can I approve Cursor actions from Slack?

Not with Cursor alone. A policy service behind the hook can hold the action and send a Slack alert whose Review request link opens the approval in the dashboard.

Does the same policy work for Claude Code and Codex?

With SecGuardRail, yes: one set of policies, approvals and one audit log across Claude Code, Cursor and Codex. See Claude Code security for teams.

Set it up

Become a design partner

Design partners: Team plan free for 30 days, then 50% off for life, limited to 10 teams. We set it up with you on a 20-minute call.

Agents you use

0/1000

We store this to contact you. See Privacy.

Plans

  • Free

    $0

    • 1 developer, 1 workspace
    • 3 agent API keys
    • 10,000 agent events a month
  • Starter

    $50/mo

    • Up to 3 developers
    • Everything in Free
    • Approvals with timeout
  • Team

    $99/mo

    • Up to 10 developers
    • +$9 per extra developer
    • Everything in Starter
  • Business

    From $499/mo

    • Everything in Team
    • Agent discovery
    • Retention and legal hold
See full pricing

Compare hooks, sandboxes and gateways across Cursor, Claude Code and Codex. Connect Cursor in the docs, read Claude Code security for teams. Related guides: Codex CLI security for teams and MCP security for coding agents. See pricing, or join as a design partner.

Sources

Guardrails for Claude Code, Cursor and Codex

Request access