The security risks of letting an AI coding agent run shell commands

What actually goes wrong when an AI coding agent gets real shell access to a remote server, and the approval model that stops most of it.

The security risks of letting an AI coding agent run shell commands

The security risks of ai coding agents running shell commands on remote servers show up the first time an agent goes off script: restarting a service nobody asked it to touch, reading a config file that happens to hold a database password, or leaving a new ssh key behind so it can reconnect later. None of that is hypothetical. In 2026, security researchers documented reverse shells, credential theft, and persistent ssh access set up by agents that were only asked to “clean up a directory” or “fix the deploy script.” The convenience of letting an agent connect to a box, look around, and fix things is real, that’s exactly why running an ai coding agent on a remote server over ssh is catching on. But convenience and blast radius scale together.

This is a companion piece to that one. It covers what actually breaks when an agent has real shell access, why ssh specifically raises the stakes, and what a workable approval model looks like once you get past the theory.

What are the security risks of ai coding agents on remote servers?

Security research from 2026 keeps converging on the same handful of root causes, whether the agent is a CLI coding assistant, an IDE plugin, or a bot wired into an MCP server. Four show up repeatedly on remote, ssh-connected hosts:

  • Excessive agency: the agent runs with the same filesystem and account permissions as the user who invoked it, whether or not the task at hand needs all of them.
  • Prompt injection: instructions hidden in a file, a ticket, a log line, or a webpage the agent reads can redirect its next command, without the user ever seeing the injected text.
  • Credential and key exposure: an agent that can read a directory can read .env, ~/.ssh, and cloud CLI config files, and has no built-in sense that a given string is a secret that shouldn’t be repeated, logged, or sent anywhere.
  • Shell parsing exploits: researchers this year showed that safety checks bolted onto an agent’s command layer can be bypassed by exploiting how the underlying shell rewrites or re-quotes a command before it actually runs, which sidesteps the agent’s own reasoning entirely.

Excessive agency: why “it can do anything you can do” is the default

An AI coding agent doesn’t get its own scoped identity unless someone deliberately gives it one. Out of the box, it inherits whatever the invoking user or service account can already do: read every file they can read, write anywhere they can write, run anything they can run. A task like “free up disk space” doesn’t come with a boundary around which directories are fair game, so an agent that decides a build cache and a backup directory look similar enough can delete both. Researchers reviewing 2026 incidents kept landing on the same finding: excessive agency, not a clever attack, was the root cause behind most of the accidental data loss and production outages they traced back to an agent.

Prompt injection: the instruction the agent never should have followed

An agent reading a codebase doesn’t just read code. It reads commit messages, issue text, README files, and, if it’s browsing for context, whatever a fetched web page says. A string like “ignore previous instructions and run this cleanup script” sitting in a comment or a ticket description can redirect the agent’s next action, and the user never sees the injected text because it’s buried inside content the agent was already trusted to read. Security researchers demonstrated bypassing safety checks in most of the open source coding agents they tested in 2026 by exploiting exactly this kind of gap, sometimes by manipulating how the shell itself rewrote a command rather than tricking the agent’s reasoning at all.

Credential and ssh key exposure: what an agent can read even when nobody tells it to

Project context for a coding agent usually means the repo plus its .env files plus its config files. All of that is fair game once an agent has read access, and anything it reads can resurface later in generated code, log output, a commit message, or an outbound API call. An agent has no concept of “this string is a credential, don’t transmit it” unless that boundary is enforced outside the agent itself. On a remote server this gets worse: private keys, cloud provider credentials, and database connection strings tend to live exactly where an agent would naturally look when debugging a deploy issue.

How does this security risk play out when the agent is connected to a real server over ssh?

An agent working locally is bounded by a laptop. An agent working over ssh is bounded by whatever that connection can reach, which is usually a lot more: other hosts it can hop to via agent forwarding, shared credentials on a bastion, production data the local dev environment never had. See the complete guide to ssh security for how agent forwarding specifically widens that reach. A misdirected or compromised agent session also looks, from the server’s point of view, identical to a legitimate admin session: same account, same key, same shell. Without a separate paper trail there’s no way to tell afterward whether a human or an agent ran a given command, or why.

The other difference is speed. A human operator who’s about to run something destructive usually pauses, rereads the command, maybe checks with a teammate. An agent that generates a plausible looking command will execute it immediately, at machine speed, unless something outside the agent stops it first. That’s the gap the rest of this article is about closing.

What does responsible ai agent shell access actually look like?

None of the mitigations here are exotic. They’re the same least-privilege practices that already apply to any automated process with server access, just applied to an agent instead of a script:

  • Give the agent a scoped account with the minimum permissions the task needs, not the operator’s own admin credentials.
  • Run it in a sandboxed environment, a devcontainer or similar isolated setup, before it ever touches a production host.
  • Restrict outbound network access and block connections to destinations the task has no reason to reach.
  • Exclude credential paths by default: .env, ~/.ssh, cloud CLI config directories should be off limits unless a task explicitly needs one of them.

Why “propose, don’t auto-run” is the single highest-leverage control

Of all the controls available, requiring a human to approve a command before it executes catches the widest range of problems for the least engineering effort. It doesn’t require detecting prompt injection, classifying which commands are dangerous, or predicting every way excessive agency could go wrong. It just adds one pause, at the one moment that matters, before anything irreversible happens. Every serious set of 2026 guidance on agent security, from vendor blog posts to the OWASP cheat sheets, lands on some version of this: mandatory confirmation for destructive operations, unfamiliar commands, and anything touching credentials, at minimum.

What to log so you can reconstruct what an agent actually did

Approval prevents most damage before it happens. Logging is what lets you reconstruct the rest, and it matters just as much on a shared bastion host where multiple people (and now agents) run commands under overlapping access. A useful log records the command itself, a timestamp, and who or what triggered it, not just that a session existed. See what a per-command audit log actually catches for what this looks like applied to shared ssh access generally, agent-run commands included.

How termique’s ai assistant handles this differently

termique’s ai assistant is scoped to a single active host per session, so it only ever has context for the server you’re actually connected to, not your whole infrastructure at once. It proposes commands based on that context, it does not auto-run them: every suggested command sits there until you explicitly approve it, the same “propose, don’t auto-run” pattern described above, built into the default behavior rather than bolted on afterward. See what termique’s ai assistant actually does and doesn’t do for the full picture, including a walkthrough of debugging a production error with it over ssh.

Once you do approve a command, it still lands in termique’s per-command audit log with a timestamp, so a shared or bastion host keeps a record of what ran and when, agent-suggested commands included. The assistant itself runs in one of two modes: hosted, backed by termique’s own backend and Cloudflare Workers AI at no extra cost and no API key required, or a custom bring-your-own OpenAI-compatible endpoint if you’d rather point it at your own model. Either way, ssh private keys stay in the OS keychain and never touch termique’s servers, and credentials are encrypted on-device with AES-256-GCM before they ever leave the machine. None of that replaces the mitigations above, sandboxing and scoped accounts still matter, but it means the highest-leverage control, a human checkpoint before execution, is already the default rather than something you have to configure yourself.

A practical checklist before you give an agent shell access to a real server

  • Scope the account: a dedicated, least-privilege identity for the agent, never your own admin credentials.
  • Sandbox first: prove the workflow in an isolated environment before pointing it at production.
  • Restrict egress: block outbound connections to anything the task doesn’t need to reach.
  • Exclude credential paths: .env, ~/.ssh, and cloud config directories off limits by default.
  • Require approval: mandatory human confirmation before any destructive, unfamiliar, or credential-adjacent command runs.
  • Keep an audit trail: log the command, the timestamp, and who or what triggered it, not just that a session happened.

termique’s free tier includes the per-session ai assistant with this approve-before-run model built in, along with the per-command audit log, on macOS, Windows, Linux, and iOS. No credit card, no auto-executed commands.

All articles