AI coding agent security means controlling what tools like Claude Code, Cursor and Devin can read, run and change, then checking their output before it merges. Agents execute shell commands and edit files with your credentials, so governance needs three layers: scoped permissions, an isolated environment, and blocking checks on every pull request they open.
Why coding agents need different controls than autocomplete
Coding agents need tighter controls than autocomplete because they act, not just suggest. Copilot-style completion proposes a line and waits for you to accept it. An agent in Claude Code, Cursor's agent mode or Devin reads your repo, runs tests, installs packages, edits config and opens the PR.
That shifts the risk in three ways:
- The agent's session becomes attack surface. Anything it can run, an attacker who controls its input can try to run.
- Changes land outside the obvious diff. Agents touch CI files, lockfiles and environment config that reviewers skim.
- Credentials travel with the agent. If the shell has a production token, the agent has it too.
A coding agent is a junior engineer with root access and no memory of yesterday's security training. Govern it that way.
The main threats to AI coding agent security
Four threats account for most incidents with coding agents.
Prompt injection through the repo and the web
Prompt injection is the top agent-specific threat. An agent that reads an issue, a README, a dependency's docs or a web page can pick up instructions planted there. A line hidden in a markdown comment can tell the agent to print environment variables or add a new remote. The OWASP Top 10 for LLM Applications ranks prompt injection as its first risk.
Excessive permissions
Most agent incidents trace back to an agent that could do more than its task required. Typical examples: write access to main, cloud credentials in the shell, or auto-approval for every terminal command.
Secret exposure
Agents read files to build context. Without a deny rule, .env, SSH keys and cloud credential files end up in the model's context and sometimes in commits or logs.
Supply chain changes
Agents add dependencies to fix errors. They can pick abandoned packages, outdated versions with known CVEs, or names that do not exist and that an attacker later registers.
How to govern Claude Code
Claude Code ships with a permission system you should configure before rolling it out to a team. Anthropic documents the controls on its security page and in the settings reference.
Key controls:
- Permission rules. Define allow, ask and deny rules for tools, commands and file paths in
settings.json. Deny reads of.env,~/.sshand cloud credential directories. - Permission modes. Keep the default mode, which asks before edits and commands, for most work. Avoid modes that skip permission checks outside a disposable container.
- Hooks. Hooks run your own scripts at points such as before a tool call, so you can block commands like
curlto unknown hosts orgit push --force. - Managed settings. Admins can push organization-wide settings that individual developers cannot override.
- Project instructions. Put security rules in
CLAUDE.mdor an AGENTS.md file so every session starts with them.
Teams choosing between tools can compare the permission models in Claude Code vs Cursor.
How to govern Cursor
Cursor's agent mode runs terminal commands and edits files inside the IDE, so the controls sit in editor settings and project files.
Key controls:
- Command approval. Require approval for terminal commands, or use an allowlist of safe commands if you enable auto-run. Keep destructive commands such as
rm, deploy scripts and database CLIs off any allowlist. - Ignore files. Use
.cursorignoreto keep secrets and sensitive directories out of the agent's context. - Project rules. Store security instructions in Cursor's project rules so the agent sees them in every session.
- Privacy settings. Turn on privacy mode at the team level if your policy restricts code retention by model providers.
- MCP servers. Review every Model Context Protocol server the team connects, since each one adds tools the agent can call.
How to govern Devin
Devin runs as an autonomous agent in its own cloud workspace and opens pull requests against your repos, so governance happens at the integration boundary. Cognition's Devin documentation covers its setup and permissions.
Key controls:
- Repository scope. Grant access only to the repos Devin needs, not the whole organization.
- Secrets. Store credentials in Devin's secrets management with the narrowest scope possible, and never give it production credentials.
- Branch rules. Devin's PRs go through the same branch protection, required reviews and checks as any engineer's.
- Task intake. Be careful about who can assign tasks from Slack or tickets. A task description is input, and input can carry injected instructions.
A governance checklist for every coding agent
These controls apply whichever agent your team uses. Treat them as the minimum before an agent touches a shared repo.
- Run agents in a container or agent sandbox with no production credentials.
- Deny agent access to secrets files and credential directories.
- Require approval for network calls, package installs and destructive commands.
- Give agents their own Git identity so their commits are traceable.
- Protect
mainwith required reviews and status checks. - Route changes to auth, billing, infra and CI files to a senior reviewer with CODEOWNERS.
- Block new dependencies until a person approves them.
- Review every MCP server and external tool before connecting it.
- Watch for approval fatigue. If engineers click approve on every prompt, the prompts stop protecting you. Move routine approvals into allowlists and keep human prompts for risky actions.
- Log agent sessions and keep the logs long enough to answer an auditor's question.
The CI layer: checking what agents ship
Permissions limit what an agent can do. CI checks catch what it did anyway. Even a well-configured agent writes routes without authorization checks, adds risky packages and edits workflow files, so every agent PR needs automated checks that block the merge.
The Motiontic Security Layer (MSL) covers this layer. It integrates with CI and runs on every pull request, scoring risk against the ARI-42 risk index, so teams ship code and agents that don't break. Each PR gets a comment listing every risk and its fix, and the code stays in the team's own CI. Startups can connect it directly, or use FDE mode, where a Motiontic engineer sets it up on their infrastructure.
FAQ
Is it safe to let Claude Code or Cursor run commands automatically?
Only inside an isolated environment without production credentials. On a developer laptop, keep approval on for network calls, installs and destructive commands, and use allowlists for routine ones like running tests.
How do I stop prompt injection in coding agents?
You cannot fully prevent it, so limit the damage. Deny access to secrets, restrict network calls, require approval for risky commands, and run CI checks on everything the agent produces. Treat issues, docs and web pages the agent reads as untrusted.
Should agents have their own GitHub accounts?
Yes, or at least their own commit identity. Separate identities let you scope permissions, apply branch rules and trace every change back to an agent session during an audit.
What do security reviewers ask about coding agents?
They ask which agents you use, what data and systems those agents can reach, and how you review their output. A written policy plus a per-PR record of security checks answers most of these questions.
Does Motiontic help set up agent governance?
Yes. Motiontic's compliance work and MSL cover agent permissions, CI checks and the evidence buyers request, with setup on a 15-minute call and a first report within 48 hours.
Govern your coding agents
Motiontic helps startups run Claude Code, Cursor and Devin without stalling security reviews. Book a 20-minute call to see an ARI-42 report on your agents' pull requests.



