AI-Assisted Engineering

Securing AI Coding Agents: Shell Access, Secrets, Git and Production Credentials

Coding agents run shell commands, read files, use Git and sometimes reach cloud consoles, often on developers' own machines with their credentials. That makes them one of the most privileged pieces of software in an engineering organisation. This is a practical security model for coding agents, from laptops to cloud sandboxes.

By EthicalHat Research · · 4 min read
Infographic: Security layers for AI coding agents

A coding agent is, from a security point of view, a program that executes commands chosen by a language model, based on instructions that may come partly from untrusted text, with access to your source code and whatever credentials happen to be available. Put that way, it is clear why coding agents need a deliberate security model.

In 2025 we saw what can go wrong: prompt injection through repository content and issues, malicious prompts slipped into agent tooling itself, malware that recruited AI CLIs on developer machines to hunt for secrets, and well-publicised cases of agents deleting data they should never have been able to touch. This article sets out the controls that address those risks.

The threat model

Ambient authority. On a developer laptop, an agent running in the developer's terminal can read SSH keys, cloud credential files, browser cookies, .env files and shell history, and can reach internal networks through the VPN.

Untrusted instructions. Agents read READMEs, issues, code comments, dependency source and web pages. Any of these can contain instructions aimed at the agent.

Destructive commands. rm -rf, git push --force, terraform destroy, DROP TABLE, or a well-meaning "clean up" of files it misunderstood.

Exfiltration. Sending code or secrets to an external endpoint, directly or by embedding them in a URL, a package publish or a commit.

Supply chain. Malicious or compromised agent extensions, MCP servers and packages the agent installs.

Control 1: sandbox the agent

The single most effective control is to run the agent somewhere that does not have everything.

  • Use a dev container, VM or cloud development environment for agent work, with only the repository mounted.
  • Provide no ambient credentials: no SSH agent forwarding, no ~/.aws, no cloud CLI logins, no browser profile.
  • Mount the repository read-write but keep the rest of the file system out of reach.
  • Make environments ephemeral: destroy and recreate them rather than letting state accumulate.
yaml
# Illustrative dev container settings for agent sessions
services:
  agent-workspace:
    image: registry.example.com/devcontainers/python-3.12:pinned
    volumes:
      - ./:/workspace:rw          # only the project
    environment:
      - HOME=/home/agent          # clean home: no dotfiles, no credentials
    read_only: true               # root filesystem read-only
    tmpfs: [/tmp, /home/agent]
    cap_drop: [ALL]
    networks: [egress-restricted]

Control 2: restrict network egress

Allow the agent to reach only what it needs: the model provider, package registries (ideally through your proxy) and your Git host. Block everything else. This turns many exfiltration attempts into failed connections that show up in logs.

Control 3: secrets hygiene

  • Keep secrets out of the repository and out of files the agent can read. Use a secrets manager and load secrets at runtime in environments the agent does not control.
  • Never put production credentials in .env files in working copies.
  • Clear or disable shell history in agent environments.
  • Use short-lived, scoped credentials for anything the agent genuinely needs, such as a read-only token for a test database.
  • Run secret scanning on everything the agent commits.

Control 4: command policy and approvals

Most agent tools support permission modes and allow- or deny-lists for commands. Use them:

  • Allow without asking: read-only commands, builds, tests, linters and formatters.
  • Ask before: installing packages, network calls, anything touching Git remotes, anything outside the workspace.
  • Deny: destructive commands, privilege escalation (sudo), direct database access to shared environments, infrastructure changes.

Configure these centrally for managed developer machines so each developer does not have to get them right alone.

Control 5: Git controls

  • Agents commit to their own branches and open pull requests; they never push to protected branches.
  • No force-push and no history rewriting on shared branches, enforced server-side.
  • Agent commits are attributable (their own identity) and ideally signed, so provenance is verifiable.
  • Changes to CI configuration, build scripts and deployment files require code-owner review.

Control 6: production is off-limits by default

Coding agents should not have production credentials. If an agent-assisted workflow must touch production, for example running a data migration, it should go through the same deployment pipeline and approvals as any change, executed by the pipeline, not by the agent's shell.

Control 7: govern agent tooling

  • Maintain an approved list of agent tools, extensions and MCP servers, with pinned versions.
  • Review updates to agent tooling as supply-chain changes.
  • Monitor developer endpoints for unusual behaviour from agent processes: unexpected file access, network destinations or child processes.
flowchart TB
  Dev[Developer] --> A[Coding agent<br/>in sandbox]
  A -->|allowed| B[Build / test / lint]
  A -->|ask| C[Install packages,<br/>network, git push]
  A -->|deny| D[Destructive commands,<br/>sudo, prod access]
  A --> G[Own branch → PR]
  G --> CI[CI checks + human review]
  CI --> Main[Protected main]
  E[(Secrets manager)] -.not reachable.-> A

A checklist for engineering leaders

  • Agents run in sandboxed environments without ambient credentials
  • Network egress restricted to allow-listed destinations
  • No production credentials reachable from agent environments
  • Command permission policies configured centrally
  • Agents push only to their own branches; protected branches enforced server-side
  • Agent commits attributable and signed
  • Secret scanning on all commits; secrets never in working copies
  • Approved list of agent tools and MCP servers, versions pinned
  • Agent activity logged and monitored

The bottom line

Coding agents deliver real productivity, and they concentrate risk: model-chosen commands, untrusted instructions and privileged access in one place. Sandbox them, starve them of ambient credentials, restrict their network and Git permissions, and keep production behind your normal pipeline. Then they can work at full speed without putting your source code, secrets or systems at risk.

Our application security testing and information security audit services include reviews of AI coding agent deployments, from developer endpoints to CI.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.