Contents
Running coding agents securely means deliberately limiting what they can do: through an isolated execution environment (sandbox), fine-grained permissions and human approval for critical actions. An agent that is allowed to execute commands has, in principle, the same capabilities as the person whose account it runs under.
Why coding agents need their own security concept
A code assistant that only makes suggestions is manageable from a security perspective. An agent, however, reads files, writes code, runs shell commands, installs packages and may access the network. If it runs directly on a developer's laptop, it potentially has access to SSH keys, cloud credentials, browser sessions and every local repository.
On top of that come risks that do not exist in this form in traditional development:
- Prompt injection: the agent reads content from issues, web pages, documentation or dependencies. If these contain hidden instructions, it may mistake them for its assignment.
- Mistakes: a misunderstood task can lead to destructive commands, such as deleting files or resetting a branch.
- Data exfiltration: with network access, a manipulated agent could send secrets or code to external addresses.
- Supply chain: agents install packages and suggest dependencies – in the worst case including non-existent or malicious ones.
The fundamental risks of AI-generated code are covered in our article on security risks of AI code. This article focuses on the agent's operating environment itself.
Sandboxing: isolate the execution environment
A sandbox limits what the agent can technically access – regardless of what it "wants". Common options:
| Option | Isolation | Suitable for |
|---|---|---|
| Built-in tool sandbox (file system and network restrictions at OS level) | Medium | Local work on developer machines |
| Dev container / Docker container | Medium to high | Teams with a standardised development environment |
| Virtual machine or cloud development environment | High | Autonomous runs, sensitive projects |
| Ephemeral CI runners | High | Agents in pipelines, automated pull requests |
Key principles regardless of the option:
- File system: write access only to the project directory, no mounting of the home directory.
- Network: blocked by default or limited to an allowlist (e.g. package registry, internal Git instance).
- Short-lived: discard environments after the run instead of reusing them indefinitely.
- No production access: neither database credentials nor deploy keys inside the sandbox.
Permissions: the principle of least privilege
Most coding agents offer configurable permission levels. Instead of allowing everything, define which actions are automatic, require confirmation or are forbidden. A proven model:
- Always allowed: reading project files, searching code, running tests and linters.
- With confirmation: editing files, installing new packages, creating Git commits.
- Manual only, by humans: pushing to protected branches, deleting outside the working directory, accessing secrets, deployments.
Store these rules centrally in the repository so they apply to all team members, and add explicit deny lists for particularly dangerous commands. Make sure allow rules are not too broad – permitting "all shell commands starting with npm" also includes scripts that can execute arbitrary code.
Approvals: involve humans at the right moments
Approvals only work if they are given consciously. Anyone who clicks "yes" a hundred times a day eventually stops checking. The goal is therefore to focus approvals on the truly critical moments:
- before changes to dependencies, CI configuration or security settings,
- before any action with effects outside the sandbox (push, deployment, external API calls),
- when merging a pull request – here through regular code review.
A pattern that works well: the agent operates largely freely inside the sandbox, but its output only leaves the sandbox as a pull request. Branch protection rules ensure that nobody – not even an agent – writes to the main branch without review.
Protecting secrets and credentials
Secrets never belong in an agent's context. Concrete measures:
- Exclude
.envfiles and key files from reading via configuration. - Use only dummy credentials or dedicated test accounts with minimal rights for tests.
- Enable secret scanning in pre-commit hooks and CI.
- Issue agent tokens with short lifetimes and tightly limited scopes.
You will find more in our article on agentic coding and data security. When agents are connected to further tools via interfaces such as the Model Context Protocol (MCP), the same principle applies: every connected server widens the attack surface and should come from a trusted source and have minimal permissions.
Checklist for secure operation
- The agent runs in a sandbox, container or isolated cloud environment.
- Network access is blocked by default or restricted via allowlist.
- Permission rules are versioned in the repository and binding for everyone.
- Secrets are neither readable nor reachable via environment variables.
- Protected branches prevent merges without human review.
- New dependencies are checked before installation.
- Connected tool servers are inventoried and minimally privileged.
- Agent activity is logged and traceable.
We also train the practical implementation of these points in workshops: we place AI developers from real-world practice as trainers, from €799 net. Read more in our article on the security workshop for working safely with coding agents.
Planning an app? Request a free fixed-price quote in 2 minutesConclusion
Security with coding agents does not come from trusting the model, but from architecture. A sandbox limits potential damage, tiered permissions prevent mistakes, and targeted approvals keep humans accountable where it matters. Teams that combine these three layers can use agents productively without putting production systems or credentials at risk.
Frequently Asked Questions
Is it dangerous to run a coding agent directly on my own machine?
It is possible, but riskier than necessary, because the agent basically has your user account's rights. At a minimum, use the tool's built-in sandbox or a dev container.
What is prompt injection in the context of coding agents?
Content the agent reads, such as an issue or a web page, contains hidden instructions. The agent may wrongly follow them, which is why sandboxing and restricted network access matter so much.
Should an agent be allowed to push to the main branch on its own?
No. Agent output should arrive as a pull request and go through human review before merging, enforced by branch protection rules.
How do I prevent an agent from reading secrets?
Exclude secret files via configuration, keep production credentials out of the environment and use secret scanning in hooks and CI.