AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Configure Snyk DeepCode AI in CI/CD to Block Insecure Code and Auto-Fix Pull Requests

Annett von Lucke · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Blocking insecure code in CI/CD is easy to mandate and notoriously hard to sustain. If your pipeline turns into an uncompromising traffic cop that halts builds over hundreds of ambiguous legacy warnings, developers will either disable the check or bypass it.

At 365Finds, we evaluate developer security tools based on whether they fix code or just complain about it. Snyk DeepCode AI succeeds where traditional static application security testing (SAST) fails because it pairs a deterministic security gate with an agentic remediation engine. Instead of merely throwing a red build in a developer's face, it highlights the data-flow path directly in the pull request and drafts a production-ready fix that can be committed in seconds.

To make this workflow work without alienating your engineering teams, you must connect two distinct mechanisms: the SCM PR Check layer (which handles inline feedback, branch protection gates, and automated AI fixes) and the CI/CD Pipeline CLI gate (which enforces build-level compliance).


The Architecture: PR Check vs. CLI Pipeline

A frequent mistake we observe at 365Finds is relying solely on a CLI task (snyk code test) inside a CI runner like GitHub Actions or GitLab CI. While a CLI runner can fail a build, it cannot easily post interactive code diffs or listen for developer commands.

CapabilitySCM PR Checks (Snyk Integration)CI/CD Pipeline (Snyk CLI / Actions)
Primary RoleDeveloper feedback, merge blocking, auto-remediationHard build gating, artifact logging, compliance reports
Trigger PointSCM webhook on PR opened or updatedPipeline execution on commit or merge event
AI Auto-Fix (@snyk /fix)Fully supported in PR comments and diffsNot supported in terminal logs
Threshold EnforcementBlocks PR merge via Branch ProtectionFails build runner with exit code 1
Scan ScopeDelta analysis (new issues introduced in PR)Full repository scan or delta scan

For optimal enforcement, configure SCM PR Checks as your primary developer-facing review gate and keep the CI/CD pipeline task as a secondary verification step.


Step 1: Enable Snyk Code and DeepCode AI Fix in Snyk

Before configuring pipeline triggers, activate the SAST engine and AI auto-remediation capabilities across your organization.

  1. Log in to the Snyk Web UI and switch to your target Organization.
  2. Navigate to Settings > Snyk Code.
  3. Toggle Enable Snyk Code to active.
  4. Navigate to Settings > Snyk Agent Fix (formerly labeled DeepCode AI Fix).
  5. Enable Snyk Agent Fix. This allows Snyk to invoke its hybrid AI engine—combining symbolic AST analysis with fine-tuned large language models—to generate context-aware diffs for detected vulnerabilities.

Snyk's AI engine is trained on curated security data and does not use customer source code to train public models.


Step 2: Configure SCM PR Checks and Severity Gates

Native SCM integration is what enables automated PR suggestions and status checks inside GitHub, GitLab, or Bitbucket.

  1. Go to Settings > Integrations and select your Source Control Management (SCM) provider (for example, the GitHub App).
  2. Open your repository's project settings or set global organization defaults under Pull Request Status Checks.
  3. Locate Code Analysis (Snyk Code) and switch it to Enabled.
  4. Define your Failure Threshold:
    • Select High and Critical only.
    • 365Finds strongly advises against setting the threshold to Medium or Low during the initial rollout. Blocking merges on medium-severity warnings will flood developers with trivial noise and erode confidence in automated gates.
  5. Select Only fail PR checks for newly introduced issues. This ensures that pre-existing technical debt does not prevent critical feature branches from merging.
  6. Enable Pull Request Experience options:
    • Inline comments: Surfaces vulnerable data flows directly on the offending lines of code.
    • PR issue summaries: Leaves a aggregated breakdown of security status.

Step 3: Enforce Branch Protection Rules

Configuring Snyk to mark a PR check as "Failed" does not automatically prevent a merge unless your Git host enforces it. You must bind Snyk's status check to your branch protection policy.

On GitHub:

  1. Navigate to your repository's Settings > Branches.
  2. Under Branch protection rules, select your default branch (e.g., main or release).
  3. Check Require status checks to pass before merging.
  4. Search for the Snyk status check (e.g., snyk / code / <project-name>) and check it as a Required gate.
  5. Check Require branches to be up to date before merging.

Once saved, any PR introducing high-severity Snyk Code issues will have its "Merge" button locked until the vulnerability is resolved.


Step 4: Add Build-Level Gating in Your CI/CD Pipeline

While SCM PR checks manage merge rules, adding Snyk Code directly to your pipeline runner ensures that scripts, dry-run pipelines, and scheduled builds also validate code integrity.

GitHub Actions Implementation (.github/workflows/snyk-code.yml)

name: Snyk Code Security Gate

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  security-gate:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Run Snyk Code SAST
        uses: snyk/actions/code@master
        continue-on-error: false
        env:
          SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
        with:
          args: --severity-threshold=high

Generic CLI Pipeline (GitLab CI, Jenkins, Bitbucket)

If running raw CLI commands in shell runners:

# Install Snyk CLI
npm install -g snyk

# Authenticate using your environment secret
snyk auth $SNYK_TOKEN

# Scan source code and block on High or Critical issues
snyk code test --severity-threshold=high

When Snyk detects vulnerabilities meeting or exceeding the high threshold, snyk code test exits with code 1, causing the pipeline job to fail immediately.


Step 5: Resolve Blocked PRs with Automated AI Fixes

When a developer opens a PR containing a security flaw (such as an unescaped SQL query, Cross-Site Scripting source, or insecure deserialization), the configured system responds in three coordinated actions:

  1. Pipeline Gate: Snyk PR check and GitHub Actions job fail, locking the merge button.
  2. Context Explanation: DeepCode AI posts an inline review detailing the source-to-sink data flow, explaining exactly how user input reaches the vulnerable method.
  3. Automated Fix Generation: DeepCode AI suggests a verified code patch right beneath the vulnerable snippet.
Snyk Code detected: SQL Injection (CWE-89)
Source: req.body.username -> Sink: db.query(...)

Suggested Fix:
- const query = "SELECT * FROM users WHERE username = '" + req.body.username + "'";
+ const query = "SELECT * FROM users WHERE username = $1";
+ const params = [req.body.username];

Applying the Fix via PR Commands

Developers can interact directly with the agent inside the PR review thread:

Once the commit lands, Snyk automatically re-runs the PR check. If the vulnerability is neutralized and no new issues are introduced, the check passes, the green checkmark reappears, and the merge block is cleared.


Recommended Rollout Strategy

At 365Finds, we advise against turning on blocking gates everywhere on day one. A sustainable adoption pattern follows three phases:

  1. Week 1-2 (Audit Only): Enable Snyk Code PR checks with notifications enabled, but set continue-on-error: true in CI and keep branch protection checks optional. Let engineers observe the findings and test the AI fix suggestions.
  2. Week 3 (Block High/Critical Delta): Enable branch protection requiring Snyk Code to pass, but strictly for newly introduced high-severity flaws.
  3. Week 4 onwards (Continuous Maintenance): Turn on automated pull requests for dependency upgrades and use Snyk Agent Fix to incrementally patch legacy findings during maintenance sprints.

DeepCode AI resolves the fundamental dilemma of DevSecOps: security teams get a verifiable gate that stops vulnerabilities from crossing into production, while developers get actionable code patches instead of open-ended Jira tickets.

References