agentic-semgrep-rules
Semgrep rules for AI agent code in Python, TypeScript and JavaScript.
What it is
Semgrep rules for AI agent code: static analysis for LLM applications in Python, TypeScript and JavaScript that finds model output flowing into exec, shells, SQL, URLs, file paths and HTML (eval of model output, SSRF through tool URLs), user input written into system prompts, tools that let the model run anything, MCP server security checks (HTTP transports without authentication, servers bound to every interface), leaked provider keys, and unsafe model or config loading. For teams that ship LLM agents, MCP servers and tool-using assistants and want these mistakes caught in a pull request rather than found in an incident.
36 rules (23 Python, 13 TypeScript/JavaScript), every one with a tested fixture, CWE and OWASP LLM Top 10 (2025) mapping, and a message that says what is wrong and how to fix it.
pip install semgrep
semgrep --config https://raw.githubusercontent.com/basitalisandhu/agentic-semgrep-rules/main/agentic-semgrep-rules.yaml .
Output on an agent that runs model-written code (excerpt; the file is tests/python/code-execution/llm-output-to-exec-eval.py):
agent.py
❯❯❱ python.code-execution.llm-output-to-exec-eval
❰❰ Blocking ❱❱
Text returned by a language model flows into a call that executes it as Python. A prompt injection
in any document, web page or tool result the model has read becomes arbitrary code execution in this
process. Do not execute model output. [...]
15┆ exec(code)
⋮┆----------------------------------------
17┆ return eval(code.strip())
⋮┆----------------------------------------
23┆ exec(resp.output_text)
On two large public agent codebases (the official MCP reference servers and the OpenAI Agents SDK, 807 files) the pack reports 10 findings, all of them real for the rule's definition; see docs/smoke-test.md.
Install
pip install semgrep
# the single-file bundle, straight from GitHub (Semgrep accepts a URL only for a single file)
semgrep --config https://raw.githubusercontent.com/basitalisandhu/agentic-semgrep-rules/main/agentic-semgrep-rules.yaml .
# or the rules directory from a clone
git clone https://github.com/basitalisandhu/agentic-semgrep-rules
semgrep --config agentic-semgrep-rules/rules .
From the README; see the full README for every option.
Links
Releases
Posts about it
- Four open repositories for securing AI agents, and what each is for
A map of the open tools for AI agent security: an incident dataset, Semgrep rules for agent code, a threat-model CLI and Claude Code skill packs, with where each one stops.
More in Security tooling
- agent-off-switch: Find every AI agent identity in Microsoft 365, AWS and GitHub, see what it can reach, and switch it off. Offline on saved exports.
- skill-scan-gate: CI gate for Claude Code skills and plugins, with SARIF output. GitHub Action and CLI.
- agent-threat-model: Threat modeling for AI agents: describe the system in YAML, get a STRIDE and OWASP Agentic threat model.
- agent-config-audit: Audit AI agent configuration files for security risks.
- security-actions: GitHub Actions for AI agent and supply chain security checks.
- cc-hooks: Typed Python SDK and offline test runner for Claude Code hooks.
- cc-plugin-lock: Lock file for Claude Code plugins: pins plugins and skills to content hashes and verifies them before load.
- claude-perm-sim: Claude Code permission rule simulator: shows which rule decides a tool call and where a rule set is permissive.
- llms-txt-gen: Generate llms.txt for any docs site or repository.
- scp-guardrails: Build AWS service control policies from a short spec and lint them for lockouts and statements that deny nothing.
- spotlighting: Spotlighting for prompt injection defence in Python: mark untrusted text before it reaches a model.
- llm-agent-control-plane: Deterministic policy enforcement for LLM agents.
Topics: agent-security, agentic-ai, ai-agents, ai-security, code-scanning, devsecops, github-actions, hacktoberfest, llm-security, mcp, owasp, prompt-injection, sast, security-automation, security-tools, semgrep, semgrep-rules, ssrf, static-analysis