Application security, AI benefits/risks

Trimming the fat: How to stop AI agents from creating bloated, insecure code

Futuristic 3D rendering of an AI agent robot orchestrating workflow automation.

Using AI agents to write software code can deliver tremendous productivity gains, letting developers build, modify and deploy applications at never-before-seen speeds.

But there's a catch, because those gains may be offset by a less visible problem: AI-generated software often packs in unneeded libraries, dependencies and functions.

This can greatly expand an application's attack surface, especially when code is pulled from public open-source repositories. It can also end up costing developers and analysts more time in the long run as they must review reams of extra code to find bugs and strip out unnecessary parts.

"The speed of software creation has outpaced the speed of security," writes Saty Sundarram, RapidFort Vice President of Product Delivery & Operations, in a recent blog post. "The result is a surge in AI-influenced vulnerabilities."

To achieve the maximum productivity benefit from coding agents, development teams will need to change how they source, build, harden and maintain their applications.

Why AI coding agents stuff applications with extra code

AI coding agents are great at quickly building software from existing components. Yet agents can introduce new dependencies and vulnerabilities as developers modify a project's requirements.

"Each time a developer changes a prompt, the assistant can add new libraries to satisfy the request," writes RapidFort Chief Marketing Officer Mike Wood. "It rarely goes back to remove the ones the previous version needed."

According to Wood, inherited or imported components such as default operating-system packages, language runtimes and transitive dependencies may make up 90% or more of container contents. The resulting bloat can be extraordinary.

He describes how one customer, readying an application for deployment at a financial institution, found a Bluetooth driver package containing 125 vulnerabilities. Yet the application didn't use Bluetooth at all.

Once the Bluetooth driver and other unused components were removed, the container image shrank from 1.8 gigabytes to just 262 megabytes.

"As AI assistants write more of your code, packages like that Bluetooth driver pile up faster, and each one adds to your container attack surface," writes Wood.

The risks of adding extraneous code

Every unnecessary software component can become another avenue of attack. AI coding agents may pull in outdated open-source packages, vulnerable dependencies or compromised third-party components without agents or human developers understanding their provenance — if their provenance is even available.

Even unused libraries can become dangerous if attackers gain access to a container. Unnecessary shells, package managers and networking utilities can facilitate further malicious activity.

"Every package in an image is code that a person or a model can search for flaws," writes Wood. "A package the application never loads still counts, because an attacker who gains a foothold in the container can call it."

Meanwhile, frontier AI models capable of discovering previously unknown vulnerabilities and chaining together low-level weaknesses to create a critical attack path make the practice of retaining unnecessary code increasingly risky.

Extra vulnerabilities in unused code will show up in routine static or dynamic security testing, forcing security personnel to waste time investigating, prioritizing and coordinating their remediation and further undermining the productivity gains that coding agents had promised to deliver.

How to make sure coding agents create efficient, low-risk code

Organizations can mitigate this problem by adding automated security controls throughout the software development lifecycle.

RapidFort calls this approach "flow defending," and it encompasses three essential practices:

  • Use curated code repositories. Restrict coding agents to pull code from curated software repositories and container images. RapidFort Senior Solutions Engineer Matthew Oliver-Mayho says that in one customer trial, RapidFort's curated versions of eight RedHat Universal Base Image 9 (UBI9) container bases had 93.3% fewer known vulnerabilities than the regular versions, and none of the regular versions' high-severity vulnerabilities.
  • Identify and remove unnecessary code. Complement conventional software bills of materials (SBOMs) with runtime bills of materials (RBOMs), which identify components actually loaded or executed. Profile applications through comprehensive quality-assurance testing, then automate the removal of unnecessary packages during subsequent builds.
  • Maintain continuous runtime protection. Monitor production workloads for newly disclosed vulnerabilities, changing execution paths and unexpected components. Continuously update optimization profiles and hardening processes accordingly as AI-generated modifications enter production.

Productivity will ramp up as vulnerabilities in extraneous components are removed for good, reducing remediation workloads without forcing developers to rewrite code.

"Each component you remove is a link that chain can no longer use," writes Wood. "Removal also ends recurring work, because a CVE in a package you've deleted can't reappear in next quarter's report."

The ultimate measure of AI-powered development isn't how quickly agents can generate code, but how quickly organizations can deliver secure, functional software.

By combining curated software components, runtime-aware optimization and continuous vulnerability remediation, organizations can minimize software bloat, shrink their attack surfaces and preserve the productivity gains of agentic coding.

"As AI accelerates development workflows, the risk of unintentionally introducing vulnerable components also increases," writes Sundarram in a different blog post. "In today’s fast-moving software landscape, securing your software supply chain is no longer optional — it’s foundational."

Paul Wagenseil

Paul Wagenseil is a custom content strategist for CyberRisk Alliance, leading creation of content developed from CRA research and aligned to the most critical topics of interest for the cybersecurity community. He previously held editor roles focused on the security market at Tom’s Guide, Laptop Magazine, TechNewsDaily.com and SecurityNewsDaily.com.

Get daily email updates

SC Media's daily must-read of the most current and pressing daily news

By clicking the Subscribe button below, you agree to SC Media Terms of Use and Privacy Policy.

You can skip this ad in 5 seconds