SAST catches some AI-generated code flaws but misses many of the ones that matter. SAST for AI generated code works for known patterns such as SQL injection, unsafe deserialisation and hardcoded secrets. It falls short on hallucinated packages, over-scoped agent permissions, unsafe framework defaults and logic flaws, because those risks live in configuration and intent rather than in a recognisable code pattern.
What SAST does well on AI-generated code
Static application security testing (SAST) reads source code without running it and flags patterns that match known vulnerability classes. AI-generated code is still code, so SAST works on it the same way it works on human code.
Coding agents reproduce common insecure patterns from their training data. SAST catches many of them:
- SQL built by string concatenation instead of parameterised queries.
- Shell commands built from user input.
- Hardcoded API keys and passwords.
- Unsafe deserialisation and use of
eval. - Missing output encoding that leads to cross-site scripting.
- Weak cryptography, such as MD5 for password hashing.
Keep SAST in your pipeline. It is cheap, fast and catches a real share of what coding agents get wrong.
Where SAST for AI generated code falls short
SAST looks for known bad patterns inside the code. The riskiest flaws in AI-generated changes often contain no bad pattern at all. Seven gaps show up again and again.
Hallucinated and typosquatted packages
Coding agents sometimes import packages that do not exist, or that have names close to real ones. An attacker can register that name and publish malware. SAST scans your code, sees a normal import statement and moves on. Catching this needs a check against the package registry and a dependency review, not a pattern match.
Over-scoped permissions and IAM changes
A coding agent asked to "fix the upload error" may widen an IAM policy to s3:* or add an OAuth scope. The code is syntactically clean. SAST tools that scan application code often skip infrastructure files, and those that scan them rarely judge whether a scope is wider than the task needs.
Agent tool definitions
When the product is itself an agent, a new tool definition is a new capability. Adding a delete_records tool to an agent that reads customer emails creates a path for prompt injection to delete data. SAST has no rule for "this agent can now do something dangerous," because the danger comes from combining the tool with untrusted input elsewhere.
Unsafe framework and SDK defaults
Agent frameworks and MCP tools ship defaults that work against the builder. Motiontic's ARI-42 risk index found that agent tools rarely meet security requirements by default, and that some run agent-generated code on the host or pass provider keys to agent commands. SAST sees a call to a framework function and has no knowledge of what that framework does by default.
Missing controls
SAST flags code that is present. It struggles with controls that are absent: no sandbox around agent code execution, no egress allowlist, no human-in-the-loop approval before a payment. Absence produces no pattern to match.
Business logic flaws
An AI-generated endpoint can check that a user is logged in and forget to check that the user owns the record. SAST rarely catches broken authorisation like this, because the code looks normal and the flaw lives in what the code fails to compare.
Prompts as code
System prompts, AGENTS.md files and tool descriptions now steer behaviour as much as code does. A change that tells an agent to "skip confirmation for internal users" is a security change. SAST treats it as a string.
Why AI-generated code makes these gaps worse
AI-generated diffs tend to be longer, touch more files and arrive faster than human-written ones. Reviewers skim them. A pull request that adds a feature, a dependency and an IAM change in one go gives each change less human attention.
SAST was designed as a second line behind code review. When review thins out, the gaps SAST leaves become the gaps in your whole process. The OWASP Top 10 for LLM Applications treats supply chain risk and excessive agency as separate risk categories, and SAST covers neither well.
Getting more out of the SAST you already run
Before adding tools, tune the SAST you have for AI-generated changes. Three adjustments pay off quickly.
First, scan every file type coding agents touch: infrastructure as code, CI workflows, Dockerfiles and config, not only application source. Agents edit these as side effects of feature work.
Second, add custom rules for your own risky functions. If your codebase has a run_shell helper or a raw query builder, write a rule that flags every new call site so a human looks at it.
Third, run SAST on the pull request, not nightly. Findings attached to the diff get fixed by the author, often by the same coding agent that wrote the code. Findings in a weekly report get ignored.
What to add alongside SAST
Close the remaining gaps with checks that read context, not only patterns. A practical stack for teams shipping AI-generated code and agents:
- SAST for known code-level vulnerability classes.
- Secret scanning across code, config, prompts and environment files.
- Dependency review that verifies packages exist, checks for typosquats and matches versions against CVEs.
- Infrastructure and permission review for IAM, OAuth scopes and service accounts.
- Agent configuration review: tools, scopes, agent sandbox settings, egress and approvals.
- Tests for authorisation logic on every new endpoint.
Items 1 to 3 have mature tools. Items 4 and 5 need a reviewer that understands what an agent can do and why a change widens its blast radius.
The Motiontic Security Layer (MSL) covers that second group on every pull request in the team's own CI. The team's coding agent collects quoted evidence through the Motiontic MCP, a checker verifies each quote matches the commit, and MSL judges it against ARI-42, 85 rated tools and a weekly CVE feed. Each risk arrives as a PR comment with its fix, alongside a dashboard and a buyer-ready PDF report.
How to evaluate a scanner for AI-generated code
Test any scanner against changes that coding agents produce in your repository. A short evaluation set:
- A pull request that imports a package that does not exist on the registry.
- A pull request that widens an IAM policy to a wildcard.
- A pull request that adds a write tool to an agent that reads external content.
- A pull request that removes an approval step before a send or payment.
- A pull request with an endpoint missing an ownership check.
Count how many each tool flags, and whether it gives a fix you can apply. A scanner that catches only the classic patterns will look fine on a demo repository and miss most of this list.
FAQ
Is SAST enough for AI-generated code?
No. SAST catches known code patterns but misses hallucinated packages, permission changes, agent tool risks, unsafe defaults and missing controls. Pair it with dependency review and agent-aware checks.
Do AI coding assistants write less secure code than humans?
They reproduce common insecure patterns and sometimes invent dependencies, and their long diffs get less careful review. The safer assumption is that AI-generated code needs at least the same checks as human code, plus checks for agent-specific risks.
Can SAST detect prompt injection?
Not reliably. Prompt injection arrives at run time through content the agent reads, so static scans of code cannot see the attack. They can only help confirm that controls like sandboxing and output validation exist.
Where should these checks run?
On every pull request, before merge. That catches issues while the fix is small, and the run history doubles as evidence for enterprise security reviews.
Want to see what your current scanners miss? Book a 20-minute call with Motiontic.



