---
title: "Use Semgrep for static security scans · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/testing-and-code-quality/semgrep
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Use Semgrep for static security scans

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

For AI agents: [llms.txt](https://agentwranglers.se/llms.txt) is a short guide that sends you to the rules your problem needs, and [rules.json](https://agentwranglers.se/playbook/stack/rules.json) holds every rule of this playbook as JSON.

- Level: Recommended
- Chapter: [Testing and code quality](https://agentwranglers.se/playbook/stack/testing-and-code-quality)
- Rule: Scan source code for security mistakes with Semgrep Community Edition in CI, with the rule sets named in the repository.
- Cost: Open source. The Semgrep Community Edition engine is LGPL-2.1. The rules Semgrep maintains are free for internal business use only.
- How: Semgrep's first PyPI release came in May 2020, and 1.0.0 shipped on 1 December 2022. That is under five years of stable releases, so record it as an exception. Version 1.182.0 shipped on 20 October 2026, and PyPI counted about 5.3 million downloads that week. It reads more than 30 languages, and its rules look like the code they match. The rules Semgrep maintains use the Semgrep Rules License, which bars their use in competing products or hosted services. Run it as [Scan every change for known mistakes](https://agentwranglers.se/playbook/adversarial-testing/rules-of-engagement/scan-every-change) says. Choose something else when that rules licence blocks your use. Opengrep is an LGPL-2.1 fork whose repository opened in December 2024, and 1.31.0 shipped on 15 October 2026.
- Check: Every pull request runs `semgrep scan --error` with named rule sets. A test file with SQL built from a formatted string makes the job fail.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### YAML example

```yaml
# .github/workflows/semgrep.yml
on: pull_request
jobs:
  semgrep:
    runs-on: ubuntu-latest
    container: semgrep/semgrep:1.182.0
    steps:
      - uses: actions/checkout@v5
      - run: semgrep scan --config p/owasp-top-ten --config rules/ --error
```

### YAML example 2

```yaml
# rules/sql.yml
rules:
  - id: sql-from-formatted-string
    languages: [python]
    severity: ERROR
    message: Pass values as query parameters instead of formatting them into SQL.
    pattern: $CURSOR.execute(f"...")
```

## Sources

- [Semgrep licensing](https://docs.semgrep.dev/licensing)

## Related rules

- [Scan every change for known mistakes](https://agentwranglers.se/playbook/adversarial-testing/rules-of-engagement/scan-every-change) in Security testing

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/stack/testing-and-code-quality/semgrep">Agent Wranglers software choices playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Avoid Karma, Protractor and TSLint](https://agentwranglers.se/playbook/stack/testing-and-code-quality/retired-test-tools)
- Next: [Use TruffleHog to find leaked secrets](https://agentwranglers.se/playbook/stack/testing-and-code-quality/secret-scanner)
- [Testing and code quality](https://agentwranglers.se/playbook/stack/testing-and-code-quality)
