Securing AI-Generated Code: Practical Controls for Faster Software Teams
AI coding tools are making it easier for more people inside an organization to ship software. That speed changes the security challenge: code may reach production before anyone has checked how it handles customer data, dependencies, or access. My read is that organizations need controls built into the way people already write and review code, with named humans responsible for what ships.
A Reddit post from an IT manager illustrates the gap. A recent graduate had built a web application that handled customer data and private contracts. It ran under a domain he controlled, stored data on Supabase’s free plan, and deployed from his private GitHub repository to Cloudflare’s serverless infrastructure. When asked about security precautions, he pointed to the repository’s privacy. The manager raised the issue with the CEO, who dismissed it.
The concern extends beyond informal app building. Engineering teams use AI coding agents to speed up development, while business leaders are asking employees outside engineering to build their own tools. In both cases, working code can create a false sense of confidence. A private repository, for example, does not establish that an application is safe to run with sensitive data.
Working code can still be insecure
Research gives a measure of the difference between making a feature work and implementing it safely. SusVibes, a benchmark built from 186 real-world feature requests in open-source projects, found that agents given feature descriptions without security guidance produced working code as often as 57% of the time. Only 11.8% of their solutions were secure.
Danqing Wang of Carnegie Mellon University’s Language Technologies Institute, who wrote the paper describing the benchmark, said the failures weren’t simply careless mistakes. Finding them requires reasoning about what an attacker might do, not just what a feature is supposed to do.
That distinction matters because modern AI tools can generate code that looks plausible and runs as intended. Katie Paxton-Fear, a staff security advocate at Semgrep, says developers may be less critical of AI output now that the tools have improved at writing functional code. But an assistant’s ability to produce a feature doesn’t mean it has accounted for the application’s threat model, trust boundaries, or attacker-controlled inputs.
AI can also help find flaws in existing code, but it can introduce flaws when generating new code. As a result, AI-written code needs to earn its way into a codebase through the same security process as other contributions.
Put checks where developers work
Security teams can make that review practical by running static analysis, secrets detection, and dependency checks on every pull request, and bringing those checks into developers’ editors where possible. Datadog engineering vice president Bianca Lankford recommends treating AI-generated code as untrusted input until it passes review. Organizations can also approve specific AI tools, limit what those tools can access, and help reviewers recognize patterns such as weak input validation, outdated libraries, and overly broad defaults.
Automation should handle repeatable checks, while people remain accountable for decisions that require context. At Mimecast, CISO Leslie Nielson says each AI-assisted change that ships has a named owner recorded in its pull request. His approach reserves specialist review for code involving access, authentication, or sensitive data, even when automated scans find no problems.
Lankford says specialist review should follow the potential impact of a change, regardless of whether a person or an AI wrote it. Authentication, cryptography, payments, personal information, and infrastructure all warrant closer attention. Code owner rules can route those changes automatically. Diff size, newly added dependencies, permission changes, and greater network exposure can also help identify where review effort is needed.
The aim is to focus human attention on the changes where judgment matters most. Nielson warns that reviewers buried in low-risk work can end up approving changes without truly reviewing them. Automated checks reduce that burden, but they don’t replace specialist assessment of sensitive systems.
Review also depends on having enough context to understand a change. Security expert and tech activist Alex Ștefănescu argues that generated code can’t provide the understanding needed to maintain it. Documentation, a solid test suite, and written records of significant architecture decisions can help teams debug complex problems and respond to security incidents. He recommends that people create and maintain this material for other people to use.
Dependencies, models, and data can widen exposure
AI-generated code may include third-party libraries or phantom dependencies: packages that are used but aren’t declared in a project’s manifest. If a package isn’t recorded, scans may miss it. Software composition analysis and software supply chain security tools can help organizations identify libraries in use and assess associated vulnerabilities and other potential concerns.
Package suggestions pose a related risk. Alex Ștefănescu warns that coding assistants can suggest package names that don’t correspond to established libraries. Attackers may register those names on services such as npm or PyPI and publish packages that appear to provide the expected functionality. If a developer imports one into an application, the package can cause harm.
Teams also need controls for machine learning models and datasets downloaded from platforms such as Hugging Face. Ștefănescu cautions that a model could contain a backdoor that activates after integration and ultimately exposes company data. Suggested safeguards include scanning for malicious code or backdoors, allowing models only from verified publishers, and testing them in isolated environments. Organizations can document these rules and include them in AI coding agents’ instruction files where appropriate.
Developers can also accidentally place sensitive information in codebases while using AI-powered tools. Clear rules about what data and code may be shared with approved assistants help make this risk visible and manageable.
Bring nontraditional developers into the process
AI-assisted software work is spreading beyond engineering. Darren Meyer, a staff research engineer at Endor Labs, says data analysts, marketing teams, and researchers are building tools that use AI libraries and models, even though they may have limited experience with application security. That mix of shadow engineering and lower security awareness can leave teams without the guidance they need.
Security leaders can reduce that gap by engaging these groups early and offering training tailored to the tools they build. Clear communication matters: people need to know which tools are approved, what information they can share, and where to get help when a project handles sensitive data or adds a dependency.
Make the safe route easy to follow
With limited time and budget, a plain-language policy is a useful starting point. It should identify approved tools, set boundaries for code and data sharing, explain which changes require specialist review, and name a contact for questions. Employees want to get work done; policies that leave them waiting for weeks can encourage them to work around the process.
Blanket bans can push AI use out of view, reducing security teams’ ability to see what tools people are using and what information they’re sharing. Nielson recommends offering amnesty so employees feel safe disclosing unapproved tools and past mistakes. That visibility can help teams understand the scope of a problem and respond with better information.
Controls can apply at several stages: during design, in agent instruction files such as CLAUDE.md, while an agent generates code, at pull request review, and during AI-assisted penetration testing. Wang’s point is that agents don’t reliably infer the threat model, trust boundaries, or attacker capabilities from a feature request. Teams need to supply that context and check the result themselves.
Security capacity also needs to keep pace with software output. Meyer says AI adoption is widening the gap between development speed and security budgets. Tools matter, but so do application and product security staff who can work with developers, including people who don’t traditionally build software. The practical test for an AI coding program is whether it pairs speed with clear ownership, visible dependencies, and expert attention wherever sensitive data or access is involved.