Code agents can read files, run commands and reach the network, so their security risks go beyond insecure generated code. Teams should learn six guardrails: least-privilege permissions, sandboxed environments for autonomous runs, strict secret hygiene, awareness of prompt injection from files and web content, verification of every new dependency and careful vetting of MCP servers, all backed by human review of agent changes.
On this page
Security discussions about AI coding often focus on whether generated code contains vulnerabilities. That matters, but it is only half the picture. A code agent is an actor with access: it reads your repository, executes shell commands, installs packages and may call external services. The question is not only whether its code is safe, but whether its actions are. This article describes the guardrails we teach development teams before they hand real work to agents.
Guardrails for what the agent may do
1. Least privilege for agent permissions
Agentic tools let you control what the agent may do without asking: editing files, running commands, accessing the network. The safe default on a developer's machine is to allow routine, low-risk actions such as running tests, linters and read-only git commands, and to require approval for everything else. Avoid blanket permissions on machines that hold credentials, SSH keys or access to production systems. Modes that skip all approvals exist for good reasons, but they belong in disposable, isolated environments only. Teams should agree on a shared permission profile and commit it to the repository, so safety does not depend on individual settings.
2. Sandboxes for autonomous work
Background agents, cloud tasks and long autonomous runs should operate in containers or virtual machines with no access to production credentials and restricted network egress. Give them only the secrets they genuinely need, ideally test credentials with limited scope. If an agent is compromised by malicious input or simply makes a destructive mistake, the damage stays inside the sandbox. This is also the right place to experiment with higher autonomy levels.
Guardrails for what the agent reads
3. Secrets never belong in context
Agents read whatever is in the working directory, including environment files and configuration. Keep secrets out of the repository, use a secret manager or environment injection and add secret scanning to pre-commit hooks and CI. Do not paste API keys, tokens or customer data into prompts. Context files like CLAUDE.md or AGENTS.md are committed and shared, so they must never contain credentials either. When agents need to work with realistic data, use synthetic or anonymised datasets. Tools such as Textwash Pro anonymise text locally with machine learning before it reaches any AI system, which is useful for logs, support tickets or documents used as test material.
4. Prompt injection is a real attack path
An agent treats the text it reads as potential instructions. Malicious content in a README of a dependency, an issue comment, a web page the agent fetches or a file in a pull request from an outside contributor can try to make the agent exfiltrate data or run harmful commands. Defences are layered: restrict which external content the agent may fetch, keep approvals on for commands that touch the network or credentials, review agent actions on untrusted input with extra care and never run fully autonomous agents on content from unknown sources. In training, teams practise with a planted malicious instruction in a test file and see how their setup reacts.
Guardrails for what the agent brings in
5. Verify every new dependency
Language models sometimes suggest packages that do not exist or have slightly different names from popular libraries. Attackers register such names in public registries, a practice often called slopsquatting. Agents may also choose outdated or abandoned libraries. A simple rule helps: no new dependency without human approval. Check that the package exists, is actively maintained and is the one you intended, pin versions, use lockfiles and run dependency scanning in CI.
6. Treat MCP servers like third-party code
The Model Context Protocol lets agents connect to databases, issue trackers, cloud consoles and more. Each MCP server extends what the agent can read and do. Use only servers from trusted sources, review what permissions and data access they request, prefer read-only access where possible and maintain an approved list for the team. A database server with write access to production is a very different risk from a read-only documentation server. Our guide on MCP servers for developers explains how these connections work.
Review remains the last line of defence
None of these guardrails replace human review. Agent-written code should pass the same review and automated checks as human code, with extra attention to authentication, authorisation, input validation, data access rules and error handling. Common issues we find in agent output include overly permissive database policies, missing server-side validation and debug endpoints left in place. For applications built on Supabase, our article on Supabase row level security covers a frequent weak spot. A complete, structured list of controls is available in our security checklist for AI coding agents.
A practical way to make review stick is to add a short security section to the pull request template for agent-assisted changes: did the change add dependencies, touch authentication or data access, or introduce new external calls? Three yes or no questions take seconds to answer and direct reviewer attention where it matters most.
Teaching guardrails, not just rules
Policies on paper rarely change behaviour. Developers adopt guardrails when they see in a safe setting what can go wrong, for example an injected instruction in a test file or a hallucinated package name, and when the secure path is configured for them by default. That is why we include a hands-on security module in every agentic coding workshop at neooutput, for Claude Code, OpenAI Codex and Cursor, remote or on-site, in English or German. jocapps is ISO 9001 certified and states ISO 27001, and we apply the same guardrails when we build and launch digital products ourselves.
Frequently asked questions
Is it safe to let a code agent run commands without approval?
Only for clearly low-risk commands such as tests and linters, or inside an isolated sandbox without access to production credentials. On regular developer machines, keep approvals on for everything else.
What is prompt injection in the context of coding agents?
It is malicious text in files, web pages, issues or dependencies that tries to make the agent follow the attacker's instructions instead of yours, for example to leak secrets or run harmful commands.
Should agent-generated code get a different review process?
It should go through the same review and automated checks as any code, plus a brief checklist for dependencies, authentication, data access and new external calls, where agents most often introduce risk.