Writing Secure Code with Cursor: Scan, Fix, and Verify with StackHawk

A young man with short hair smiles widely. The image is in black and white and framed by a light blue hexagon, representing a focus on Shift-Left Security in CI/CD practices. Matt Tanner   |   Jun 26, 2026

Share on LinkedIn
Share on X
Share on Facebook
Share on Reddit
Send us an email
Two white logos on a dark background: the left features a stylized bird with wings spread over a geometric shape, while the right displays a three-dimensional polygon. A line with a dot, symbolizing Cursor Security, connects them.

Cursor lets you steer its agent with rules. The .mdc files in your project turn “follow our conventions” into behavior the agent pulls in as it works, and security testing fits that model cleanly. That’s how StackHawk plugs into Cursor: as a set of rules that teach the agent to scan, fix, and verify the code it writes.

This guide is about putting those rules to work against your live, running app. By the end, Cursor’s agent will scan your local application, fix the vulnerabilities it finds, and prove the fixes with a clean rescan, all from inside the editor.

What Are StackHawk Agent Skills for Cursor?

An agent skill is a set of instructions that teaches a coding agent a job. From these, the agent learns to run security scans against your app, read the findings, fix the vulnerable code, and verify the fixes. StackHawk’s skills follow a five-step loop: Configure, Scan, Parse, Fix, Verify.

Two skills ride along in a single install. HawkScan owns the scanning half, from configuring and running scans through fixing findings and confirming them. StackHawk API answers questions by pulling posture summaries, findings reports, and scan history from the platform. On Cursor, they arrive as .mdc rules in your global config, so if you’ve written Cursor rules before, the format will feel familiar.

The rules themselves are structured markdown: installing them adds zero runtime dependencies, and nothing runs in the background. That’s the Agentic StackHawk idea, where the agent that wrote the code is also the one that tests it under real requests, so “done” means “done and secure”.

Prerequisites

Here are a few prerequisites to check off before the steps below:

  • Cursor installed, with any project open
  • A StackHawk account; the agent skills require the Secure, Scale, or Wingman plan
  • Java 17 or newer (a full JDK) if you’re on Linux; the macOS and Windows installers ship with Java included
  • Make sure your app is running locally with its source code checked out, listening on a port from 1024 to 65535

Set Up Cursor Security Scanning with StackHawk

Step 1: Get a StackHawk API Key

To get an API key, log in to the StackHawk console in the browser and click Settings in the left-side menu, then click API Keys in the menu that appears. On the API Keys screen, click the Create API Key button in the top right corner.

A dark-themed settings page shows API Keys selected from the left sidebar. The main panel displays no API keys and a blue-highlighted Create API Key button in the top right, with blue arrows and boxes guiding the user to enhance Cursor Security.

Give your API key a descriptive name like “Cursor Agent” and click Continue.

A dialog box titled New API Key asks What is this key for? with Cursor Agent typed in the input field, highlighting Cursor Security. Cancel and Continue buttons appear at the bottom right.

The API key has now been created. Leave this screen open or temporarily copy the key somewhere secure so it’s ready for the next step. If you exit before copying it, you’ll need to delete the key and create a new one.

A dark-themed settings page displays API keys under API Keys, featuring Cursor Security enhancements. Four keys are listed with names and partially hidden secret codes. A purple banner warns to save the secret key. A Create API Key button is at the top right.

Step 2: Install the hawk and hawkop CLIs

On macOS or Linux, Homebrew installs both, and the two init commands sign them in:

brew trust stackhawk/cli && brew tap stackhawk/cli && brew install hawk hawkop
hawk init
hawkop init

The brew trust step matters on current Homebrew releases, which refuse to install from a third-party tap until you trust it; without it the install stops with Refusing to load formula ... from untrusted tap.

hawk init prompts for the API key from Step 1, validates it, and stores it at $HOME/.hawk/hawk.properties.

A terminal window displays a prompt asking for a StackHawk API key, directs the user to a URL to create one, shows an API key, and confirms authentication was successful—all within the secure environment of Cursor Security.

hawkop init reads that stored key on its own, so the only thing it asks for is your default organization. On Windows, the MSI installers on StackHawk’s downloads page cover both CLIs (the hawk MSI includes Java), and the init commands run the same way in PowerShell.

Why two CLIs? hawk runs scans, while hawkop operates on the results, and the rules lean on both.

Step 3: Install the StackHawk rules in Cursor

Cursor installs differently from the plugin-based agents. Run the script from the Cursor skill docs to drop the StackHawk rules into your global Cursor config:

# Clone the agent-skills repo
git clone https://github.com/stackhawk/agent-skills.git /tmp/stackhawk-skills

# Install Cursor rules to your global config
bash /tmp/stackhawk-skills/scripts/install.sh --platform cursor --target ~

# Clean up
rm -rf /tmp/stackhawk-skills

On Windows, use the PowerShell equivalent:

git clone https://github.com/stackhawk/agent-skills.git $env:TEMP\stackhawk-skills
& "$env:TEMP\stackhawk-skills\scripts\install.ps1" -Platform cursor
Remove-Item -Recurse -Force "$env:TEMP\stackhawk-skills"

Global rules in ~/.cursor/rules/ load automatically in every project you open, so you install once and scan everywhere.

Terminal window displaying installation logs for a script, detailing installed files and skills like DAST scanning, API reporting, CI/CD pipeline, data seed, configuration steps, and scan reminder setup for enhanced Cursor Security.

Step 4: Verify the rules are active

Open any project in Cursor and ask the AI:

What StackHawk rules do you have?

The response should describe the HawkScan scanning skill and the API reporting skill. If it does, you’re wired up.

A dark-themed interface displays a table of StackHawk rules, organized by section: an Always-on rule, detailed HawkScan scanning rules with rule names and purposes, a CI/CD rule for GitHub Actions integration, and enhanced Cursor Security measures.

Step 5: Ask Cursor to scan your app

With your app up, give Cursor’s agent the prompt from the docs, changing the port if yours differs:

Scan my app running on localhost:8080 for security vulnerabilities

From here, Cursor takes over. It checks that the app is running and prompts you to start it if it isn’t, then generates a stackhawk.yml, validates it, and runs the scan. The generated config needs just three fields: app.applicationId, app.env, and app.host.

Know where that applicationId comes from before you see it. It’s not derived from your code; it points to a record for your app on the StackHawk platform, and app creation is part of the multi-step workflow the rules carry out.

A dark-themed code editor displays a YAML configuration file on the left and Stackahawk rules, project config details, and Cursor Security settings on the right, including environment variables, scripts, and security scanning setup instructions.

When the scan finishes, the results print in Cursor’s terminal and also land on the StackHawk platform: a summary of counts by severity, followed by each vulnerability with its risk, confidence, and affected paths and methods.

A dark-themed Cursor Security scan report for a web app displays tables of vulnerabilities by severity, a section on reflected and stored XSS findings, and notes missing security headers. A terminal window is partly visible below.

If parts of your app sit behind a login, describe the auth pattern in plain language, and the agent folds it into the scan config; the authenticated scanning guide covers what HawkScan supports.

Step 6: Let Cursor fix the findings and verify

Findings in hand, send the follow-up:

Fix all of these security findings

The agent reads each vulnerability in its code context and fixes it the way you would: parameterized queries where SQL was concatenated, output encoding where XSS surfaced, and security headers where protections were missing. Then it rescans, and the job isn’t finished until the issues stop reproducing.

A screenshot of code in a dark-themed editor shows a diff view. Added lines display an attacker script (“<script>console.log(Stored XSS ready!)</script>”). Below, Node.js server setup code with security headers, styles, and Cursor Security is visible.

That verification rescan is the difference between code that looks fixed and a running app that no longer has the vulnerability.

A dark-themed dashboard displays completed security tasks in server.js, including Cursor Security enhancements, improved XSS protection, updated security headers, CORS, CSRF measures, and file access updates with technical details for each change.

Reviewing and Triaging Findings in the StackHawk Platform

One of the best parts of using StackHawk skills with a coding agent is that the skill can automatically review and triage findings. The agent decides whether something should be fixed and adds a note, all without intervention.

If you’d rather review scans and triage manually, that’s available in the StackHawk console.

A cybersecurity dashboard powered by Cursor Security shows scan results for react-js-app, listing 8 high and 30 medium risks. A table details security issues, their criticality, counts, and assignment status. Optimization tips are displayed on the right.

In the console, unprocessed findings are marked New, and the Finding Details page gives each one three triage paths: Assigned, Risk Accepted, or False Positive. Whichever you pick, the platform asks for a comment, which is how a triage decision survives team turnover.

A dashboard displaying details about the CSP: Wildcard Directive and Cursor Security issues. It shows remediation steps to specify allowed sources, an example policy, and a table with HTTP methods, status, URLs, and options to add comments.

When a finding looks questionable, the Validate action generates a ready-to-run curl command that reproduces the attack with the correct verb, headers, and data. Fire it at your local app and trace exactly what the scanner saw.

You can skip the browser, too. Ask Cursor about your security posture or recent findings, and the StackHawk API skill pulls the answer from the platform. StackHawk’s docs list the hawkop CLI as a prerequisite for the API skill, which you installed in Step 2.

Wrap-Up

Agents need help shipping secure code. Install the rules once, and Cursor security scanning becomes part of how features are finished, rather than a separate review you schedule later. Start a free StackHawk trial and put the loop to work on your own app. The Agentic StackHawk Setup Guide covers the same end-to-end flow whenever you want a docs-native reference.

More Hawksome Posts