Cursor
Integrate sus with Cursor hooks to automatically scan packages installed by AI agents
Cursor's hooks system lets you intercept and control agent actions. By using the beforeShellExecution hook, you can automatically route all package installations through sus for security scanning.
Why Use Hooks?
When AI agents install packages autonomously, they don't verify package integrity or check for known vulnerabilities. This makes them vulnerable to:
- Typosquatting - installing
lodashsinstead oflodash - Supply chain attacks - compromised packages like
event-stream - Malicious install scripts - packages that execute code during installation
With sus hooks, every npm install, yarn add, pnpm add, or bun add command is intercepted and routed through sus first.
Prerequisites
- sus CLI installed
- Cursor IDE
Setup
Choose one of the two options below. The script-based approach is recommended for production use.
Option A: Script-Based Hook (Recommended)
This approach uses a bash script for fast, deterministic behavior.
1. Create the hooks configuration
Create .cursor/hooks.json in your project root:
{
"version": 1,
"hooks": {
"beforeShellExecution": [
{
"command": ".cursor/hooks/sus-gateway.sh",
"matcher": "npm|yarn|pnpm|bun"
}
]
}
}2. Create the hook script
Create .cursor/hooks/sus-gateway.sh:
#!/bin/bash
input=$(cat)
cmd=$(echo "$input" | jq -r '.command')
# Match install commands with packages
if [[ "$cmd" =~ ^(npm\ (i|install|add)|yarn\ add|pnpm\ (add|i)|bun\ (add|i))\ (.+)$ ]]; then
pkg="${BASH_REMATCH[4]}"
jq -n --arg p "$pkg" '{continue:true, permission:"deny", agent_message:"Use `sus add \($p)` instead."}'
elif [[ "$cmd" =~ ^(npm\ (uninstall|rm)|yarn\ remove|pnpm\ (rm|remove)|bun\ (rm|remove))\ (.+)$ ]]; then
pkg="${BASH_REMATCH[4]}"
jq -n --arg p "$pkg" '{continue:true, permission:"deny", agent_message:"Use `sus remove \($p)` instead."}'
else
echo '{"continue":true,"permission":"allow"}'
fi3. Make it executable and restart Cursor
chmod +x .cursor/hooks/sus-gateway.shThen restart Cursor to load the hook.
Option B: Prompt-Based Hook (Zero Code)
This approach uses Cursor's built-in LLM evaluationβno script needed. Trade-off: adds slight latency per command.
Create .cursor/hooks.json in your project root:
{
"version": 1,
"hooks": {
"beforeShellExecution": [
{
"type": "prompt",
"prompt": "If this command installs a package (npm install <pkg>, yarn add <pkg>, pnpm add <pkg>, bun add <pkg>), deny and tell the agent to use 'sus add <package>' instead. Allow bare 'npm install' or non-install commands.",
"matcher": "npm|yarn|pnpm|bun"
}
]
}
}Restart Cursor to load the hook. No script file needed.
How It Works
When the Cursor agent tries to run a package install command:
- Agent attempts
npm install express - Hook intercepts and denies the command
- Hook tells the agent to use
sus add expressinstead - sus scans the package for vulnerabilities
- If safe, sus installs using your detected package manager
Command Mapping
The hook intercepts these commands and routes them through sus:
| Original Command | sus Equivalent |
|---|---|
npm install pkg | sus add pkg |
npm i pkg | sus add pkg |
yarn add pkg | sus add pkg |
pnpm add pkg | sus add pkg |
bun add pkg | sus add pkg |
npm uninstall pkg | sus remove pkg |
yarn remove pkg | sus remove pkg |
Commands without specific packages (like npm install to install from package.json) are allowed through.
Testing the Integration
Ask Cursor to install a package:
Install the express packageYou should see the hook intercept the command and instruct the agent to use sus instead:
π checking express@4.21.0...
β
not sus
ββ publisher: expressjs (verified)
ββ downloads: 32M/week
ββ cves: 0
ββ install scripts: none
π¦ installed
π updated AGENTS.md docs indexGlobal Configuration
To apply sus hooks to all your projects, create the configuration in your home directory:
mkdir -p ~/.cursor/hooksCreate ~/.cursor/hooks.json:
{
"version": 1,
"hooks": {
"beforeShellExecution": [
{
"command": "./hooks/sus-gateway.sh",
"matcher": "npm|yarn|pnpm|bun"
}
]
}
}Then copy the hook script to ~/.cursor/hooks/sus-gateway.sh.
Troubleshooting
Hook not triggering
- Verify the hook file exists at
.cursor/hooks.json - Check that the script is executable:
chmod +x .cursor/hooks/sus-gateway.sh - Restart Cursor after making changes
- Check Cursor Settings > Hooks tab for debug info
Script errors
Test the script manually:
echo '{"command": "npm install express", "cwd": "/tmp"}' | .cursor/hooks/sus-gateway.shExpected output:
{"continue":true,"permission":"deny","agent_message":"Use `sus add express` instead."}jq not found
The script requires jq for JSON parsing. Install it:
# macOS
brew install jq
# Ubuntu/Debian
sudo apt-get install jq
# Windows (with chocolatey)
choco install jqNext Steps
- Learn about threat detection
- Learn about AGENTS.md
- See other integration guides
On this page