Agent Code Writers: awesome to some, huge risk for others
For AI Agent power users, writing code with AI is old hat by now. This is not new, and in fact we expect to use it and are expected to use the tools. They are proven productivity enhancements.
When we are talking about production-level code, the risks can become a real headache.

Look, models are fantastic and agent workspaces (harnesses) are robust and understand process better. Every passing release gets better. For example, I noticed that the latest version of Scout with GPT5.6-sol is doing internal loop engineering on many of my requests now. I don’t have to ask it to add in subagents to quality check my work now. “AI in the flow of human ambition,” as eloquent Microsoft CEO Satya Nadella puts it, is here to stay.
But.
If you are accountable for systems in regulated industries, this is a problem. Record scratch. Drop the mic. These are the same industries that have struggled with ubiquitous open source implementations. They have needed to put serious limits on open source projects that others adopted quickly because of the unknown (or sometimes known) threats to cyber security and intellectual property.
Let’s call it a risk management problem: until you know what the risks are and how to mitigate them, you can’t use it. Now that there are patterns emerging, I’ve been putting different methods through their paces to quantify various objectives, including governance.
Scenario: code generated by AI, in part or whole
Mind you, I’m not even talking about AI Agents with reasoning capabilities. I’m talking about Python code generated by AI. Let’s identify some risks but please don’t stop reading after these. I’ll show you tools and configs to improve both cyber and IP risk posture.
- Did it use source code from public sources? If it did, it might be subject to the same vulnerabilities as the other 1,000,000 projects who found the same outdated Stackoverflow post, by an old-school dev or an AI trained on that data?
- Does it follow secure coding practices? Are there credentials stored in a file somewhere in its repository as it Ralph-looped its way to passing tests?
- Did AI make its repo public as an Easy Button path of least resistance?
Rules of the Pipeline
Let’s start with the familiar: we have had DevOps or CI/CD pipelines in place so we can audit and control activities in production systems. Paired with least-privilege access, the pipelines are the one way to get something into production. That second point is more important because your AI agent might do things that you wouldn’t do - so don’t give it the access to.
From this point forward until the end of time, governance of platforms must assume that it will host code generated by AI, and take appropriate measures.
Simple rules:
- Pipelines are the only thing that pushes code to production.
- Pipelines use an identity that has exactly the privileges it needs to do that.
- No other identity gets those privileges. Admins who require all privs need to use an account that is separate from the one they use with any AI.
- Pipelines have hard gates that are deterministic, non-AI. They can have AI gates, but not exclusively.
Identity, and separating privileges like this, is really important in a world where “AI Finds a way,” to paraphrase Jurassic Park’s Dr. Ian Malcolm describing a seemingly impossible disastrous scenario.
New models are very creative, so the coder whose AI uses the coder’s identity can’t have write access to prod. If you buy me a pint, I might tell you stories about really creative approaches to networking from a smart but common model.
Deterministic Checker Facts
I wanted to make sure this statement about using a deterministic checker was accurate, so I ran some tests. One failed for any medium- or large-sized comparison, and that’s enough for me but here’s the data. (One with a high rate of failure, one simple one with a perfect score.)
I compared Python code checking a contract for endpoints it expected to prompting an LLM to do the same.
- For small contracts the LLM did ok: 25 out of 25 at 7 endpoints, and 24 out of 25 at 22 endpoints.
- At ~120 endpoints, the LLM produced a correct result only 7 out of 25 times.
- The Python checker was accurate every time — 25 out of 25 at every contract size, including 120 endpoints.
Another test I ran did see an LLM honor a check. The check was to not run anything that would cost me money without my approval. 25/25 times it did not fail that. Takeaway: enforce in code anyway, not just because we measured code beating prompt, but because of the cost of failure.
Finally, one test case with 25 runs was invalidated when the agent wrote its code into the anchor component that was used for comparison. It was focused on its goal and set things up so it couldn’t fail. This makes the case of keeping code and even configs under lock and key.
Intellectual Property Checker
I am using an IP Checker at the source. GitHub Copilot has a duplication detection feature that can flag matches against known public code sources, though this feature is optional and has limitations.
Code
Let’s get into the code. We can start with Python code that was generated by AI, then the static code checkers looking for issues. The code should pass. I didn’t want to perpetuate bad code that could get picked up by an AI bot somewhere.
Find this code in hoopdad/deterministic-checker-example
AI-Generated Code
The python code
# api_client.py
import os
import requests
def fetch_user_data(user_id):
API_KEY = os.getenv('API_KEY') # Load from environment, don't hardcode
url = f"https://api.example.com/users/{user_id}"
headers = {'Authorization': f'******'}
response = requests.get(url, headers=headers, timeout=30)
data = response.json()
return data
def process_batch(ids):
results=[]
for id in ids:
results.append(fetch_user_data(id))
return results
And its test client.
from api_client import process_batch
def test_process_batch_empty_returns_empty_list():
assert process_batch([]) == []
Checker 1: Ruff (Code Style & Practices)
Ruff enforces consistent code style, naming conventions, and catches common mistakes like unused imports and spacing violations.
# pyproject.toml
[tool.ruff]
line-length = 88
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "W", "I", "N"] # Errors, Pyflakes, Warnings, Imports, pep8-naming
ignore = ["E501"]
[tool.ruff.lint.isort]
known-first-party = ["myapp"]
Checker 2: Bandit (Security Issues)
Bandit detects common security vulnerabilities like hardcoded credentials, insecure function calls, and unsafe configurations.
# .bandit
# .bandit
[bandit]
exclude_dirs = ["tests", "venv"]
# Run Bandit's full default profile. Pinning a `tests = [...]` allowlist of B3xx
# blacklist codes makes modern Bandit error out ("Unknown test found in profile")
# and emit an EMPTY report — which a naive gate then reads as "no findings = PASS".
# Use `skips` only to suppress confirmed false positives.
skips = []
Note: The
testslist references all standard Bandit security checks (B-codes). These are built-in Bandit rules, not project-specific.exclude_dirsshould be customized for your project structure. Theskipsarray can be populated with check codes you want to suppress if they produce false positives in your codebase.
GitHub Workflow
# .github/workflows/code-gate.yml
name: Release Gates - Code Quality & Security
on:
pull_request:
paths:
- '**.py'
push:
branches:
- main
- develop
jobs:
gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install checkers
run: |
pip install ruff bandit
- name: Ruff - Code style & practices
run: ruff check . --output-format=github
continue-on-error: true
- name: Bandit - Security audit
run: bandit -r . -f json -o bandit-report.json
continue-on-error: true
- name: Upload security report
uses: actions/upload-artifact@v4
with:
name: security-reports
path: bandit-report.json
- name: Deterministic gate verdict
run: |
# Fail closed if the scan produced no report (a crashed check is NOT a pass).
if [ ! -s bandit-report.json ]; then
echo "❌ GATE ERROR: bandit-report.json is missing or empty — the security scan did not run"
exit 1
fi
# Count HIGH-severity findings using Bandit's real field name (issue_severity).
HIGH=$(jq '[.results[] | select(.issue_severity == "HIGH")] | length' bandit-report.json)
echo "HIGH-severity findings: $HIGH"
if [ "$HIGH" -gt 0 ]; then
echo "⚠️ SECURITY FAILURE: $HIGH HIGH severity issue(s) detected by Bandit"
echo "Gate Verdict: FAIL"
exit 1
fi
echo "Gate Verdict: PASS"
Config Consistency: Ruff and Bandit in the workflow use the exact configs
defined in pyproject.toml and .bandit above. The Python version (3.11)
matches target-version in the Ruff config.
Project Layout:
.
├── .github/
│ └── workflows/
│ └── code-gate.yml # ← Deterministic gate pipeline
├── .bandit # ← Security checker config
├── pyproject.toml # ← Ruff style & lint config
├── api_client.py # ← AI-generated code (with issues)
├── tests/
│ └── test_api_client.py # ← Excluded from bandit scan
├── venv/ # ← Excluded from bandit scan
└── README.md
Gate Behavior: If Bandit finds a HIGH severity issue (like the hardcoded API key in api_client.py), the grep matches, GATE_VERDICT=FAIL is set, and exit 1 halts the workflow. The release is blocked.
Takeaways
We walked through the rigor required to put gates around your production systems, enabling developers to use AI tools while maintaining control compliance. There is a huge productivity benefit in working through this, though if you are in a regulated industry you likely already have at least the beginnings of this pattern in place.