githubEdit

Directives

Directives allow security and engineering teams to govern how AI coding assistants operate across your organization, ensuring adherence to security policy, code standards, and approved workflows.

They have varying names across different coding assistants. For example, rules, instructions, commands, memories, skills, knowledge, workflows, hooks, and so on.

Snyk categorizes anything that guides an agent to produce code a certain way under the term "Directives" and offers code examples that you can use as they are, or customized to meet your needs.

Snyk categorizes directives into the following types:

circle-info

Different coding assistants may require a different header or formatting for directives. Check the coding assistant's official documentation for formatting instructions.

Guardrail directives

Guardrail directives are automatically injected into agent interactions. They govern agent behavior by providing persistent context, setting security policies, and enforcing compliance rules.

Coding assistants have different mechanisms for how these types of directives are applied, but they are either appended to prompts or injected into the workflow when relevant.

circle-info

Non-determinism is a factor with LLM interactions and there can be scenarios where coding assistants do not append directives to prompts.

There are many guardrail directives that your company may choose to implement, some of which may relate to security.

Secure at inception directives

Snyk Secure at inception directives are code examples that can be used to ensure that AI-generated code is tested for security issues at the time of code generation.

The following directives can be customized to fit your organization needs.

chevron-rightSecure at inception: SASThashtag

The following code snippet establishes the SAST constraint for new code and guides the agent through the mandated validation and remediation process:

- Always run snyk_code_scan tool for new first party code that is generated in a Snyk-supported language.

- If any security issues are found based on newly introduced or modified code or dependencies, attempt to fix the issues using the results context from Snyk.
- Rescan the code after fixing the issues to ensure that the issues were fixed and that there are no newly introduced issues.
- Repeat this process until no new issues are found.
chevron-rightSecure at inception: All Snyk productshashtag

The following code snippet extends the Secure at inception testing to include checks for Snyk Code, Snyk Open Source, Snyk Container, and Snyk IaC:

chevron-rightSecure at inception: Package health check [Experimental]hashtag

The snyk_package_health_check directive evaluates open-source packages for security vulnerabilities, maintenance health, community engagement, and popularity. This reduces supply chain risk in agentic development workflows where AI agents autonomously select and install dependencies.

circle-info

The snyk_package_health_check is available only for npm, pypi, nuget, maven, and golang.

Snyk Studio provides two ready-to-use sample scripts that integrate snyk_package_health_check into your development workflow: a skill for proactive package selection and a hook for enforcing security gates on package installations.

Skill: Secure dependency health check

This skill evaluates and compares open-source packages for AI agents.

When a developer requests a recommendation or an agent imports a dependency, the skill runs snyk_package_health_check on each candidate. The tool returns a structured comparison including:

  • Overall health rating

  • Vulnerability counts by severity

  • Maintenance and community ratings

  • Popularity metrics

The agent uses these signals to recommend packages with clear reasoning or flag packages to avoid because of security issues or inactive maintenance.

Install this skill to evaluate packages before recommending or adding them.

You can:

  • Compare multiple candidates for the same functionality.

  • Check if an existing dependency is safe.

  • Find a secure alternative to a vulnerable package.

To use this skill, refer to the sample script in the Snyk Studio recipes repositoryarrow-up-right.

Hook: Enforce security scan on new packages

circle-info

The snyk_package_health_check hook works only with Cursor.

The Enforce Security Scan hook implements a security gate for the Cursor IDE. Install this hook to enforce a policy that prevents installing new dependencies without a security check.

When an AI agent modifies a package manifest, for example, package.json, the hook blocks install commands, like npm install, until the snyk_package_health_check runs. After the agent invokes the health check, the install commands proceed. If a session ends with unscanned manifest changes, the hook displays a warning.

The hook operates in the background and requires no developer intervention. This suits teams that want consistent guardrails across all agent coding sessions.

To use this hook, refer to the sample script in the Snyk Studio recipes repositoryarrow-up-right.

How to use the sample scripts

Sample scripts are available in the studio-recipes repositoryarrow-up-right.

To use them:

  1. Clone or download the repository.

  2. Copy the skill or hook directory into your project's .cursor/ configuration.

  3. Ensure the Snyk MCP serverarrow-up-right is configured, and you have an authenticated Snyk account.

Command directives

Command directives are manually invoked by human developers or agents. They codify and standardize complex, multi-step engineering and security playbooks.

Remediation directives

Remediation directives, a category of command directive, trigger a full, end-to-end security remediation playbook that results in a secure pull request.

There are many command directives that companies may choose to implement, some of which may relate to security. Snyk remediation directives are code examples that can be used to accelerate the remediation of pre-existing security issues.

The following directive can be customized to fit your organization's specific needs.

chevron-rightEnd-to-end vulnerability resolutionhashtag

This directive content guides the agent to:

  • Execute one or more security tests.

  • Filter the results if any parameters are provided.

  • Rescan to validate the security fix resolved the issues and did not introduce new ones.

Once executed, a pull request can be generated to review, approve, and merge into the codebase.

This directive is invoked by calling the directive in an agent chat interaction, for example, /snyk-fix. This is invoked without any arguments, which results in any detected findings being remediated, or it is invoked with specific Snyk product filters or other indications of which resulting findings should be fixed:

Last updated

Was this helpful?