AI and DevOps

Is it safe to let AI run commands on your server?

It can be, with limits. The five real risks of giving an AI agent server access (destructive commands, leaked secrets, prompt injection, broad credentials, unreviewed changes), from OWASP and the vendors' docs, and the controls for each.

TL;DR

  • It is safe enough when the agent has no more access than the task needs and nothing that changes the server runs without you seeing exactly what will run, and not safe when it has a root shell on production with its prompts turned off.
  • The five real risks: destructive or wrong commands, secrets reaching the model or logs, prompt injection from content the agent reads, credentials broader than the task, and changes nobody reviewed.
  • The controls: read-only access first, changes as code reviewed before they apply, approvals bound to exactly what was reviewed, least-privilege, short-lived credentials, ideally held by CI rather than the agent, sandboxes, typed tools instead of a raw shell, and an audit trail.
  • Command allow-lists and deny rules reduce prompts but are not a security boundary: they match the command's text, and the same program can be run another way.
On this page

Letting an AI agent run commands on your server is safe enough when the agent has no more access than the task needs and nothing that changes the server runs without you seeing exactly what will run. It is not safe when the agent holds a root shell or an all-powerful cloud token and its approval prompts are off, because then one wrong or manipulated step goes straight to production. The controls are well understood, and most of them are settings, not new tools.

The five risks of AI agent server access below are grounded in OWASP's Top 10 for LLM applications or the agent vendors' own documentation, checked on 11 November 2026. This article belongs to the guide to AI DevOps agents for small teams.

Is AI agent server access safe? The short answer

Ask three questions before you give an agent access to a server:

  1. What can it read? If the answer includes .env files, state files or your home directory, secrets can reach the model.
  2. What can it change, and with which credentials? If the answer is "anything root can", every mistake is possible.
  3. Who sees a change before it happens, and does their approval cover exactly that change? If the answer is "nobody" or "I click yes on each command as it scrolls past", review is weak.

An agent that reads logs through a read-only tool, writes changes as pull requests and has CI apply them is a different risk from an agent that SSHs in as root, though both are "AI running commands on your server".

The five risks

1. Destructive or wrong commands

In ops, a wrong command is not a wrong answer: it is a deleted volume, a dropped table or a firewall rule that locks you out. OWASP names the underlying weakness Excessive Agency (LLM06:2025) and traces it to three causes: excessive functionality (tools that can do more than the task needs), excessive permissions (credentials that reach more than the task needs) and excessive autonomy (high-impact actions without a human check). Its example is apt: an extension meant to run one shell command that fails to stop other commands from running.

Anthropic's list of actions that Claude Code's auto mode blocks by default includes production deploys and migrations, mass deletion on cloud storage, force pushes and terraform destroy, and its documentation warns that auto mode "reduces permission prompts but does not guarantee safety".

2. Secrets reaching the model or the logs

Everything the agent reads becomes part of its context, and parts of its context can end up in transcripts, logs or its answers. A .env file, the output of env or printenv, a docker inspect of a container with environment variables, or a Terraform (opens in a new tab) state file can all hold secrets. HashiCorp warns that a saved plan file stores sensitive values "in cleartext" even when the terminal hides them. OWASP lists this as Sensitive Information Disclosure (LLM02:2025).

A secret does not need an attack to reach an agent: a person pasting a token into the chat to "help it", or the agent running a diagnostic command that prints the environment, is enough.

3. Prompt injection from what the agent reads

OWASP puts prompt injection first (LLM01:2025) and separates direct injection (the user's own prompt) from indirect injection, where the model reads external content, such as a web page or a file, that contains instructions. For an ops agent, that external content is everywhere: a README in a dependency, an issue or pull request comment, a web page it fetches for documentation, even a log line that an attacker can influence through a request to your app.

Anthropic's security page lists Claude Code (opens in a new tab)'s safeguards against it (permission prompts, approval for network commands such as curl, most fetched web pages summarised by a separate model call instead of passed raw) and still advises: review suggested commands, avoid piping untrusted content to Claude (opens in a new tab), and use virtual machines for scripts and tool calls, "especially when interacting with external web services". GitHub filters hidden characters, such as HTML comments, out of issues and comments before its Copilot cloud agent sees them. None of these is a guarantee; OWASP says it is unclear whether there are fool-proof methods of preventing prompt injection at all.

4. Credentials broader than the task

An agent acts with whatever access its session has. If that is a root SSH key, a cloud token that can create and delete everything, or a classic GitHub (opens in a new tab) token that reaches all your repositories, then a mistake or an injected instruction has the same reach. Some access is broader than it looks. Docker's documentation says that "only trusted users should be allowed to control your Docker (opens in a new tab) daemon", because the daemon "requires root privileges unless you opt-in to Rootless mode" and a container can be started with the host's / directory mounted inside it. So whoever can control the Docker daemon on a server can, in effect, reach everything on it.

5. Changes nobody reviewed

A command typed on a server, by a person or an agent, leaves no review and often no record. It also drifts: the server no longer matches the code that is supposed to describe it, the next deploy may undo the fix, and nobody knows why the server works. With agents this happens faster, because they make many small changes in a short time.

The controls that contain them

Each risk and the controls that contain it
RiskControlsWhere it is documented
Destructive or wrong commandsRead-only first; changes as reviewed plans or pull requests; approval before high-impact actions; typed toolsOWASP LLM06; Terraform plan and apply; GitHub Copilot cloud agent
Secrets in the model or logsDeny reads of secret files; secrets in a secret store, not the chat; agent without production credentialsClaude Code permissions; OWASP LLM02
Prompt injectionTreat what the agent reads as untrusted; approval prompts; narrow permissions; sandbox with a network allow-listOWASP LLM01; Claude Code security and sandboxing
Broad credentialsLeast privilege; short-lived credentials; read-only tokens for investigatingAWS (opens in a new tab) IAM best practices; GitHub OIDC; Hetzner (opens in a new tab) API tokens
Unreviewed changesEverything as code; branch protection; an audit trailGit history; the platforms' audit logs

Read-only access first

Most of what an agent does in operations is look: logs, metrics, configuration, recent changes. Give it that first. Some providers let you make tokens that can only read: Hetzner Cloud API tokens, for example, are either Read (GET requests only) or Read & Write. Claude Code's plan mode lets it read and explore without editing your source files. A read-only agent can still give a wrong diagnosis, but you check the evidence before you act on it.

Plans reviewed before they apply

When something must change, have it written down before it runs. For infrastructure, that is a plan: terraform plan -out=tfplan saves exactly what would change, and terraform apply tfplan "performs the operations in the saved plan without prompting you for confirmation", so what runs is the plan you read. For the app, its workflows and its server setup, that is a pull request. HashiCorp's advice applies to agents too: "always re-check the final non-speculative plan before applying to make sure that it still matches your intent."

Approvals bound to exactly what was reviewed

An approval in a chat ("yes, go ahead") covers whatever the agent does next. A strong approval covers one specific change: a saved plan file, a plan identified by its hash, a pull request at a specific commit. If the change is edited after review, the approval should no longer apply. GitHub builds this into its agent: Copilot's cloud agent "cannot approve or merge a pull request", and the person who asked for the pull request cannot approve it either.

Least-privilege, short-lived credentials

AWS's IAM best practices say to "grant only the permissions required to perform a task" and to have workloads use temporary credentials rather than long-lived access keys. GitHub Actions (opens in a new tab) supports this through OpenID Connect: the workflow requests a short-lived token from the cloud provider that is "only valid for a single job", so no cloud credential is stored as a GitHub secret. For GitHub itself, GitHub recommends fine-grained personal access tokens, which can be limited to specific repositories and permissions, with an expiry date.

For agents, the strongest version is: the agent holds no production credential at all. It writes the change; CI applies it with credentials scoped to that job.

Sandboxes

A sandbox limits what a command can reach even when the command is wrong. Claude Code's sandbox uses the operating system (Seatbelt on macOS, bubblewrap on Linux and WSL2) to limit which files the agent's shell commands can write and which network hosts they can reach; its network proxy starts with an empty allow-list. It covers shell commands only, not file tools, MCP servers or hooks, and on native Windows commands run unsandboxed. For more isolation, Anthropic (opens in a new tab) suggests running the whole Claude Code process in a container, a virtual machine or its sandbox runtime, and using virtual machines for scripts and tool calls.

Allow-lists and deny rules, with their limits

Allow-lists ("these commands may run without asking") and deny rules ("these may never run") cut down on prompts and stop the forms of a command you expect. They are not a boundary. Anthropic's documentation is explicit that a Bash deny rule "isn't a security boundary around the program": Bash(curl *) stops curl https://example.com but not /usr/bin/curl https://example.com or sh -c 'curl https://example.com'. We saw the same while testing for Claude Code for DevOps, with Claude Code 2.1.316 run headless and the Bash tool allowed on the command line: the deny rule Bash(terraform apply *) blocked terraform apply -auto-approve, but terraform -chdir=infra apply -auto-approve did not match it and went through to the shell, because -chdir=infra sits between terraform and apply. A PreToolUse hook that reads the whole command blocked the -chdir form in the same setup. The hook also matches text, so the fix that holds is to keep the credentials that could apply a change out of the session. Use rules for convenience, and sandboxes, credentials and review for safety.

Typed tools instead of a raw shell

OWASP's mitigations for Excessive Agency include "avoid open-ended extensions" and prefer granular ones: a tool that writes one file instead of a shell that can do anything. In practice: give the agent a tool that reads the last 500 lines of one container's logs instead of SSH access; a tool that proposes a plan instead of a cloud CLI. A typed tool checks its inputs and can only do its one job, so an injected instruction has less to work with.

An audit trail

Keep a record of what the agent did: Git history for every change made as code, and the platforms' own logs for the rest (AWS says DevOps Agent's API calls are captured by CloudTrail; Azure SRE Agent logs every action to Application Insights). When something breaks a week later, the first question is what changed.

A checklist before you give an agent server access

  • The agent's session has no production secrets: no .env, no state files, no tokens pasted into the chat.
  • Its file access excludes secret files (in Claude Code, Read deny rules such as Read(./.env)).
  • Its credentials are the narrowest that work: read-only for investigating, scoped and short-lived for changes, and ideally held by CI rather than the agent.
  • It does not connect as root, and it is not in the docker group on production unless that is the point.
  • Changes reach production as pull requests or saved plans that a person reviews.
  • Your approval covers one specific change, not "carry on".
  • High-impact commands (destroy, prune, drop, force push) need an explicit approval or are blocked.
  • Its permission checks are never turned off on a machine that holds production credentials. Anthropic says to use Claude Code's bypassPermissions mode "only in isolated environments like containers, VMs, or dev containers without internet access".
  • Its shell runs in a sandbox, container or VM when it works with untrusted content.
  • Branch protection stops anything, including the agent, from merging unreviewed code to the branch that deploys.
  • You can see afterwards what it did.

Securing the server itself is a separate job, and an agent does not replace it: how to harden an Ubuntu server and securing SSH cover it. If secrets may already have reached your repository, scanning a git repository for leaked secrets shows how to find them.

How OpsCrew handles it

OpsCrew is built so that its agents never need the risky kind of access. Its documentation describes the controls:

  • Plans approved by their hash. Every change is a plan you see first, with its cost and its SHA-256 hash, and your approval is bound to that hash; a changed plan needs a new approval. Removing a server or an app asks you to type its name (how the AI works).
  • No secret in the model, a plan or a log. The AI steps send parts of your code, never a key or a password, and no secret goes into a plan, a log, a report or a pull request (security).
  • Typed tools, not a shell. On a server, opscrew logs runs fixed, read-only Docker commands built only from names it has checked, "and can't run anything else on the server"; each read goes to OpsCrew's audit log (logs and status). In Claude Code, the plugin's changing tools wait for your approval in a dialog Claude cannot answer, and your app's secrets never pass through the chat (the plugin).
  • Narrow, rotatable credentials. The guide lists the exact permissions each token needs, and opscrew rotate replaces a credential everywhere OpsCrew put it, as a plan you approve, without ever showing the old or new value (rotating credentials).

For when an agent is worth using at all, go back to the guide to AI DevOps agents for small teams, or see how the agents differ in AI DevOps agents compared.

Key facts

FactValueSource
OWASP's name for an agent with too much powerLLM06:2025 Excessive Agency, caused by excessive functionality, permissions or autonomyOWASP, LLM06:2025 Excessive Agency (opens in a new tab)Verified on
What a Claude Code Bash deny rule matchesThe command text Claude writes; not the same program run by its full path or inside sh -cClaude Code, Configure permissions (opens in a new tab)Verified on
Hetzner Cloud API token permissionsRead (GET requests only) or Read & WriteHetzner Docs, Generating an API token (opens in a new tab)Verified on
Saved Terraform plan filesHold sensitive values in cleartext; HashiCorp says to treat them as potentially sensitiveterraform plan command (opens in a new tab)Verified on

Frequently asked questions

Is it safe to let an AI agent SSH into my server?

It can be, with limits: connect as a user that is not root, approve each command, keep secrets out of the session, and prefer a sandbox or tools that run fixed, read-only commands. Changes are safer as code in a pull request that CI applies than as commands the agent types on the server.

What is an AI DevOps agent access policy?

A written-down answer to what the agent may read, what it may change, with which credentials, and who approves what. In practice it lives in configuration: the agent's permission rules, the scope of its tokens, branch protection on the repository and the approval step before infrastructure changes.

Sources

  1. OWASP Top 10 for LLM Applications 2025 (opens in a new tab), OWASP Gen AI Security Project, accessed on
  2. LLM01:2025 Prompt Injection (opens in a new tab), OWASP Gen AI Security Project, accessed on
  3. LLM06:2025 Excessive Agency (opens in a new tab), OWASP Gen AI Security Project, accessed on
  4. Claude Code, Security (opens in a new tab), Anthropic, accessed on
  5. Claude Code, Configure permissions (opens in a new tab), Anthropic, accessed on
  6. Claude Code, Permission modes (opens in a new tab), Anthropic, accessed on
  7. Claude Code, Sandboxing (opens in a new tab), Anthropic, accessed on
  8. Security best practices in IAM (opens in a new tab), Amazon Web Services, accessed on
  9. OpenID Connect in GitHub Actions (opens in a new tab), GitHub, accessed on
  10. Managing your personal access tokens (opens in a new tab), GitHub, accessed on
  11. Generating an API token (opens in a new tab), Hetzner, accessed on
  12. Docker Engine security (opens in a new tab), Docker, accessed on
  13. terraform plan command (opens in a new tab), HashiCorp, accessed on
  14. terraform apply command (opens in a new tab), HashiCorp, accessed on
  15. Risks and mitigations for GitHub Copilot cloud agent (opens in a new tab), GitHub, accessed on
  16. AWS DevOps Agent security (opens in a new tab), Amazon Web Services, accessed on
  17. Audit agent actions in Azure SRE Agent (opens in a new tab), Microsoft, accessed on
Edit this article
  • Security

    Is your vibe-coded app ready for production? A checklist

    An ordered checklist for taking an app built with Lovable, Bolt, Replit, v0, Cursor or Claude Code to production: secrets, database access, configuration, dependencies, the server, backups and monitoring.

    11 min read

  • Deploying

    Claude Code built your app. Here is how to put it online

    Can Claude Code deploy apps? It writes the code, the Dockerfile and the workflow, and can run deploy commands you approve, but it is not a host. The path from its code to a live URL on your own server.

    7 min read

  • Deploying

    Cloudflare Tunnel for a self-hosted app: setup, Docker and SSH

    What a Cloudflare Tunnel is, quick tunnels and named tunnels, a tested Docker Compose setup with a tunnel token, SSH through Cloudflare Access, and the limits that come with sending every request through Cloudflare.

    11 min read

Put OpsCrew to work on your app.

Run npx opscrew init in your app's repository. It checks your tools and tokens first, for free.