Key Takeaways
- Source code is a business asset and a map of your systems, so a leak exposes both your product and your attack surface.
- AI tools added new exits for code: chat windows, assistant context, agent permissions, prompt logs and vendor retention.
- NIST's SSDF practice PS.1 asks you to store all forms of code under least privilege, and its AI profile extends that to model weights and pipelines.
- OWASP ranks software supply chain failures third in its 2025 Top 10, and developers' own machines are now prime targets.
- Code generated by AI can name packages that do not exist, which gives attackers a ready-made trap to register.
- The safest prompt is one where secrets, customer data and proprietary identifiers were removed before it left your network.
Most engineering leaders already accept that a stolen laptop or a public repository mistake can leak code. What changed is the volume of quiet, everyday exits. A developer pastes a stack trace into a chatbot. An agent gets write access to fix one bug and keeps it. A build log with a token ends up in a ticket that a third-party AI tool indexes. This is the developer side of shadow AI, and it rarely shows up in any dashboard.
This guide walks through where code escapes today, then shows how to build a protection program on top of frameworks your auditors already recognize, without slowing down the teams who ship.
Why Source Code Needs a New Protection Model
Code protection used to be a perimeter problem. You controlled who could clone the repository, scanned for secrets before release and trusted that code stayed on company machines.
Today code moves between people and machines all day. Our earlier piece of content on AI coding assistants and proprietary code covers how assistants process the files you open. The wider shift is that every one of those tools becomes a place where code is copied, cached, logged or retained.
There is also a second kind of value at stake. Source code reveals how authentication works, which endpoints exist, which libraries you depend on and sometimes which customers you serve. That is why we treat software code protection as a data protection problem as much as an intellectual property one. NIST makes the same point: protecting code that is not meant to be public helps prevent theft and makes vulnerabilities harder for attackers to find.
Where Code Leaves Your Control in the AI Era
Chat windows and assistant context
The most common exit is also the most ordinary. Someone copies a function, a config file or an error trace into a general chatbot to get unstuck. If that account is personal, the company has no contract, no logs and no say over retention, a pattern we unpacked in why unapproved AI tools raise data security risk. Even approved assistants can pull more context than intended, including neighboring files and environment variables.
Agents with repository and pipeline access
Agents change the question from what a user pasted to what a tool is allowed to do. An agent that can read the repository, open pull requests and run commands holds a standing credential. OWASP's Top 10 for Agentic Applications, released in December 2025, lists identity and privilege abuse, agentic supply chain weaknesses and unexpected code execution among the top risks. If an agent can be steered by prompt injection hidden in an issue or a README, it can be talked into copying code somewhere it should not go, one of the core LLM security risks that carries over to agents.
Scope those agents the same way would scope a contractor. Give them a single repository, short tokens and no production secrets. AI agent security and business data covers the access patterns in more depth, and our governance practices for enterprise AI agents cover approvals and ownership.
Pipelines, logs and secrets
Build systems are where code, credentials and automation meet. A pipeline usually has permission to read every repository it builds and to publish what it produces, which makes it a natural place to apply zero trust architecture so no job is trusted by default. OWASP's 2025 guidance on supply chain failures asks teams to harden the code repository by keeping secrets out of it, protecting branches and keeping backups, and to run the build server with separation of duties, environment-scoped secrets and tamper-evident logs.
Logs deserve their own attention. Debug output and CI transcripts often contain tokens and internal hostnames, and they get pasted into tickets and AI tools far more casually than source files. Treat them as code for protection purposes, because each one is a quiet data leakage path.
Dependencies and hallucinated packages
Your code is only as trustworthy as what it imports. OWASP's community survey for the 2025 Top 10 put software supply chain failures first for exactly half of respondents, and OWASP describes the 2025 Shai-Hulud worm as the first successful self-propagating npm worm. It harvested secrets from developer machines and used stolen npm tokens to push malicious versions of packages, reaching more than 500 package before npm disrupted it. We looked at similar incidents in AI supply chain risks and recent scares.
AI adds a twist. Researchers from the University of Texas at San Antonio, the University of Oklahoma and Virginia Tech generated 576,000 code samples with 16 models and found that 19.7% of the 2.23 million package references pointed to packages that did not exist. Commercial models did better than open models, at 5.2% against 21.7%, but the bigger finding was repetition: 43% of hallucinated names came back in all ten repeat queries. An attacker can register a repeated fake name and wait. We covered the small-builder version of this in our identity theft tips for vibe coding.
Model artifacts and training data
If your team fine-tunes models or builds AI features, the definition of code gets wider. NIST SP 800-218A, the SSDF profile for generative AI published in July 2024, says secure code storage should include AI models, model weights, pipelines and other model elements. It also adds a task to protect training and fine-tuning data. A fine-tuning set built from internal repositories is still your source code, just in a different format, which is one of the AI training data risks enterprises ignore.




