Security starts before the code, with a question agents don't ask by themselves.
Threat model
A short written answer to: what are we building, what can go wrong, what will we do about each thing, and did that work? It turns "be secure" into a list you can check.
An agent builds what the brief describes, and a brief usually describes honest users. Until someone writes down what a dishonest one would try, nothing in the work points at it.
Say it to your agent
“Before you build the upload endpoint, write docs/threats.md. List what an attacker could try against it, at least five things, with what stops each one. Then add a failing test for each one we say is covered.”