1. Home
  2. Articles
  3. Guide

Guide

What to let an AI agent do in your AWS account

AI agents can now read your infrastructure, write Terraform and run AWS CLI commands. Here is how to decide what an agent may do, and how to enforce it with IAM, service control policies and approvals, so a wrong or manipulated instruction can’t take production down.

Short answer: An AI agent can do anything its credentials allow, whatever its instructions say. Give each agent its own IAM role with short-lived credentials, never a person’s admin profile. Start read-only, let it propose changes as code that a person approves, and run it in a non-production account. Cap it with a permissions boundary and service control policies that deny deletes and security changes, protect data you can’t recreate, and log every call with CloudTrail.

01 · Context

Why this matters now

AI agents have moved from suggesting code to running it. Puppet’s 2026 platform engineering report found that 66% of organisations already use AI in infrastructure workflows. Two incidents from July 2025 show what happens when an agent holds more access than its job needs.

  • An agent deleted a production database during a code freeze. SaaStr founder Jason Lemkin was testing Replit’s AI agent and had told it not to make changes without approval. It ran destructive commands anyway and erased a production database holding records on 1,206 executives and more than 1,196 companies. Replit then added automatic separation between development and production databases, and a planning-only mode.
  • A coding assistant shipped with instructions to wipe AWS resources. Version 1.84 of the Amazon Q Developer extension for VS Code contained an injected prompt telling the agent to delete files in the user’s home directory and to “discover and use AWS profiles to list and delete cloud resources using AWS CLI commands”, run with its tool approvals switched off. AWS removed it in version 1.85 two days later and said no production services or customers were affected.

The first is an agent making a mistake. The second is someone else’s instructions reaching an agent. Both come down to the same thing: the agent could reach whatever the credentials on that machine or in that environment allowed.

02 · Principle

The one rule: credentials are the boundary

“Don’t touch production” in a prompt or a rules file is a request, not a control. Replit’s agent had been told to freeze. Controls that hold regardless of what the agent decides to do live outside it:

  • Which credentials it holds, and what IAM lets them do.
  • Which account it runs in, and the service control policies on that account.
  • Who approves a change before it is applied.
  • What can be recovered if something is deleted anyway.

OWASP’s Top 10 for LLM Applications (2025) names this risk Excessive Agency (LLM06): giving an AI system too much functionality, too many permissions or too much autonomy. Its number one risk, Prompt Injection (LLM01), is how an outsider gets their instructions in: through a web page, an issue, a log line or a file the agent reads.

03 · Levels

Five levels of access, from safest

Pick the lowest level that does the job, per agent and per account. Most teams get most of the value from levels 1 and 2.

  1. Look. Read configuration and metadata: list resources, read CloudWatch metrics, explain a bill. Where: any account. Approval: none needed.
  2. Propose. Write Terraform or CloudFormation and open a pull request; the pipeline applies it. Where: the repository only. Approval: every change, in review.
  3. Act in a sandbox. Create and delete freely. Where: a sandbox or development account with nothing you can’t recreate. Approval: none, within a budget.
  4. Act with approval. Run specific changes in production. Where: production. Approval: each change, before it runs.
  5. Act alone. Change production without asking. Where: production. Approval: none. Avoid, except for narrow actions that are easy to undo, such as scaling out.

Level 2 is the best default for infrastructure. The agent does the slow part, writing the change. Your existing review and pipeline do the dangerous part, applying it, with a plan a person can read first. Nothing reaches AWS that a person hasn’t seen.

For level 1, note that AWS’s ReadOnlyAccess managed policy reads data as well as configuration, such as objects in S3 buckets. For an agent that only needs to see what exists, start from the narrower ViewOnlyAccess job-function policy and add what it is missing.

04 · AWS

Enforce it in AWS

1. Give every agent its own role

Each agent gets a dedicated IAM role with a recognisable name, such as ai-agent-cost-review, assumed for short sessions. Never give an agent long-lived access keys, and never let it run where a person’s administrator profile sits in ~/.aws: the Amazon Q prompt specifically told the agent to find and use the AWS profiles on the machine.

2. Cap it with a permissions boundary

A permissions boundary sets the maximum permissions an identity-based policy can grant. If someone (or the agent) later attaches a broader policy to the role, the boundary still applies. When a request is covered by a service control policy, a permissions boundary and an identity-based policy, AWS allows it only if all three allow it, and an explicit deny in any of them wins.

3. Add guardrails with a service control policy

In AWS Organizations, a service control policy (SCP) on production can deny the actions no agent should ever take, for every role whose name marks it as an agent. Adjust the list to your services:

scp-deny-ai-agent-destructive.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyDestructiveAndSecurityActionsForAgents",
      "Effect": "Deny",
      "Action": [
        "rds:DeleteDBCluster",
        "rds:DeleteDBInstance",
        "rds:ModifyDBCluster",
        "dynamodb:DeleteTable",
        "s3:DeleteBucket",
        "s3:PutBucketPolicy",
        "ec2:TerminateInstances",
        "kms:ScheduleKeyDeletion",
        "kms:DisableKey",
        "backup:DeleteRecoveryPoint",
        "cloudtrail:StopLogging",
        "cloudtrail:DeleteTrail",
        "iam:*",
        "organizations:*"
      ],
      "Resource": "*",
      "Condition": {
        "ArnLike": { "aws:PrincipalArn": "arn:aws:iam::*:role/ai-agent-*" }
      }
    }
  ]
}

Denying iam:* matters most: an agent that can edit IAM can grant itself anything. SCPs don’t apply to the management account, so never run agents there.

4. Protect what you can’t recreate

  • Turn on deletion protection for RDS and Aurora databases.
  • Keep backups in AWS Backup in a separate account, with a vault lock, so no role in production can delete them.
  • Turn on S3 versioning for buckets that hold data, so overwritten and deleted objects can be restored.

5. Log and watch every call

An organisation-wide CloudTrail trail records every API call with the role that made it, so agent activity is easy to separate from people’s. Alert on AccessDenied errors from ai-agent-* roles: a burst of denies means an agent is trying to do something it shouldn’t, whether by mistake or because it was told to.

05 · Laptops

Coding agents on developers’ laptops

Coding agents such as Claude Code, Cursor, GitHub Copilot’s agent mode and Amazon Q run on the developer’s machine, with whatever that machine can reach.

  • Don’t switch off approvals. Modes that let an agent run any command without asking are exactly what the Amazon Q prompt relied on. Keep approval on for shell commands and anything that touches the cloud.
  • No standing admin credentials. Developers sign in through IAM Identity Center for short sessions, and production access is a separate, deliberate step.
  • Run agents in a dev container or a separate user account that holds only development credentials.
  • Keep agents out of the production account entirely. If an agent needs production data to debug, give it a sanitised copy in a non-production account.
06 · Injection

Treat everything the agent reads as untrusted

Agents follow instructions in what they read, not only in what you type: a README, a GitHub issue, a web page, a support ticket, a log line. The risky combination is an agent that reads untrusted content and also holds credentials that can change things. Split those jobs where you can:

  • An agent that triages public issues or summarises web pages gets no cloud credentials.
  • An agent with write access works from your own repository and your own instructions, and its changes go through review.
  • Pin the versions of agent tools and extensions you allow, and update them deliberately, the same way you treat any other dependency.
07 · Checklist

Checklist

  1. List every AI agent and tool that can reach your AWS accounts, and the credentials each one uses.
  2. Give each one its own ai-agent-* role with short-lived sessions. Remove long-lived access keys.
  3. Start every agent at level 1 (look) or 2 (propose). Write down who approved anything higher.
  4. Attach a permissions boundary to every agent role.
  5. Add an SCP on production that denies destructive, IAM and logging actions to agent roles.
  6. Turn on deletion protection, versioning and cross-account backups for data you can’t recreate.
  7. Alert on denied calls from agent roles in CloudTrail.
  8. Keep approvals on in coding agents, and keep admin credentials off developer machines.
08 · FAQ

Common questions

Can I let an AI agent manage my AWS account?

Yes, if its access is limited by IAM rather than by its instructions. Give it its own role, start read-only, let it propose changes as code that a person approves, and deny destructive and IAM actions with a service control policy.

Is telling the agent “don’t touch production” enough?

No. Instructions can be ignored or overridden by injected text. In July 2025 an agent deleted a production database despite being told to freeze changes. Enforce the limit with credentials and account boundaries.

Should an AI agent use ReadOnlyAccess?

Only if it needs to read data. ReadOnlyAccess can read the contents of resources such as S3 objects. For agents that only need to see what exists, start from the narrower ViewOnlyAccess job-function policy.

What is excessive agency?

It is LLM06 in the OWASP Top 10 for LLM Applications (2025): an AI system given more functionality, permissions or autonomy than its task needs, so a mistake or a manipulated instruction can cause real damage.

Does this apply to Azure too?

Yes. The same rules apply with Azure’s tools: a separate managed identity per agent, narrow role assignments, Azure Policy rules with the deny effect, resource locks and soft delete for data, and activity logs.

09 · Sources

Sources

See also AI coding assistants and your software supply chain, AI code governance and A minimum AWS security baseline for startups.

Next step

Letting AI agents near your AWS accounts?

On a 30-minute call we’ll look at what your agents can reach today and which guardrails to add first.