Building with agents, lesson 7.1
Scanning code and dependencies for leaks and holes
An agent writes code fast, and it makes the same three mistakes people do: a secret left in, a hole in the code, a borrowed package with a hole in it. This lesson sets up a scan for each, where every change has to pass it.
Every example below changes to fit what you pick. The businesses are made up for teaching.
The picture, one step at a time
Each box is one stage. The picture lights up as you scroll.
Three scans, where they run and what you do with the results
1Secrets
Keys, passwords and tokens written into the code or left in its history.
2Your own code
A tool reads your code without running it and flags patterns known to cause holes.
3The packages you borrow
A tool lists every package you depend on and checks each version against public lists of known holes.
4Where the scans run
Before a commit, and again on every pull request, so an agent's change is checked like anyone's.
5Reading what comes back
Each finding is real, real but out of reach, or a false alarm. A person decides which.
A secret scan reads every file, and the history.
Step 1 of 6
Secrets first
A secret is a key, password or token that lets someone into a system. Agents leak them in boring ways: a test that needs a key, a debug log, a config file. A secret scanner looks for their shapes in every file and in the history. Turn on the kind that blocks a push, not only the kind that reports one.
GitHub's docs describe its push protection this way: it "blocks pushes that contain secrets before they reach your repository" (read November 2026).
An agent pushed a live key yesterday. You spot it today. What do you do first?
Step 2 of 6
Your own code
The second scan reads the code you wrote, without running it. It is called SAST, short for static application security testing. It flags patterns that cause holes: typed text pasted into a database query, a file name taken straight from a request, a password check written by hand. For the shop's order site, it runs on every change, the agent's and yours.
Step 3 of 6
The packages you borrow
Most of your app is other people's code. The third scan, SCA (software composition analysis), lists every package you depend on, and every package they depend on, and checks each version against public lists of known holes. The fix is usually a version bump.
Step 4 of 6
Packages that do not exist
Agents add packages too, and models sometimes name packages that do not exist. Anyone can register that name and fill it with bad code. So set a rule: an agent may suggest a new package, and a person checks it is real, who publishes it and how widely it is used before it goes in.
A 2024 study of 576,000 generated code samples found that, on average, at least 5.2% of the packages suggested by commercial models and 21.7% by open-source models did not exist (Spracklen et al., arXiv 2406.10279).
An agent's change adds a package you have never heard of, and the tests pass. What now?
Step 5 of 6
Run them where the agent's work lands
A scan nobody runs protects nothing. Put the secret scan before every commit, and all three on every pull request, so an agent's change goes through the same gate as a person's. Then make a failed scan block the merge. A warning that can be ignored will be.
Step 6 of 6
Read what comes back
Scanners are noisy. Each finding is one of three: real and reachable, real but the bad code is never called, or a false alarm. Mark each one, and write down why you closed it, so the next scan does not ask again. Lesson 7.3 hands this sorting to an agent.
Which scan catches it?
Here are four problems in your code. Secret scan: a key or password in a file. Code scan: a hole in code you wrote. Dependency scan: a hole in code you borrowed.
1An agent adds a test that only passes with the live payment key, so it pastes the key into the test file.
2The order search page builds its database query by pasting in whatever the customer typed.
3The image resizing package you installed two years ago has a published hole in the version you use.
4An agent adds a payments helper package that nobody on your team has heard of.
0 of 4 right so far, 4 to go.
A security scan checklist
This is what you keep: the three scans, where they run, and what to do on the day a key gets out.
A security scan checklist
- Turn on secret scanning that blocks a push, and point it at the history too.
- If a key gets out, cancel it and issue a new one before anything else.
- Run a code scan (SAST) on every pull request, an agent's or a person's.
- Run a dependency scan (SCA) on the whole tree, not just the packages you chose.
- A new package from an agent waits until a person checks it is real and who publishes it.
- Make a failed scan block the merge, and write down why each finding was closed.
An agent's code goes through the same scans as yours, before it merges, every time.
Next: Lesson 7.2: Prompt injection and how agents get tricked. What to change in your code and your set-up so words an agent reads cannot steer what it does.