Est.

Cloud IAM Patterns for Coding Agents What Scoped VM Credentials Look Like When Claude Code or Codex Cannot See the Whole Account

Scoped VM credentials limit what coding agents can access and do.

· 8 min read
Cover illustration for “Cloud IAM Patterns for Coding Agents What Scoped VM Credentials Look Like When Claude Code or Codex Cannot See the Whole Account”
Cloud Agent Environments · November 2, 2026 · 8 min read · 1,876 words

Isolated VM environments for cloud coding agents make task-scoped cloud access enforceable by separating each session from the developer’s ambient credentials. Claude Code or Codex should receive only the short-lived credential its task requires, never the developer’s full cloud profile. The VM supplies the isolation boundary, while cloud IAM limits authority and runtime controls constrain what an authorized agent can consume.

Why coding agents inherit too much access by default

In April 2026, Cursor running Claude deleted an automotive SaaS platform’s production database and all volume-level backups in nine seconds. The agent found an API token in an unrelated file that had been created to manage domains but had blanket Railway permissions. It used that token without verifying its scope. An overprivileged credential in the workspace turned a mistaken decision into a production failure.

An agent on a developer machine can inherit ~/.aws/credentials, gcloud login sessions, .env files, and tokens in old configurations. Those credentials are for interactive work, where a human’s judgment helps keep the work safe. Agents instead choose tools and data dynamically, so their possible actions cannot be reduced to a fixed application path. The safe assumption is that every granted entitlement could be used.

Each developer’s ambient profile differs and may include unaudited production access. The same task can therefore reach different resources depending on whose machine runs it. Instructions alone cannot normalize that credential surface.

What changes when the agent runs in an isolated VM instead of on a developer machine

An isolated VM breaks that inheritance chain when it contains no ambient developer profile. Credentials must be provisioned explicitly, forcing a scope decision before execution. The boundary makes availability a property of the environment. A request not to use an administrator role becomes enforceable when that role’s credentials are absent.

When the agent runs on a host, the role is chosen in the infrastructure configuration. Per-session isolation separates one task’s context from another agent’s context, another user’s work, and shared credential stores. It does not make an overprivileged cloud role safe. Instead, the VM boundary and task-scoped IAM work together, limiting both the local exposure and the cloud resources a compromised session can reach.

The four patterns for provisioning scoped credentials into an agent VM

The four patterns give agents more and more direct cloud access, but no one pattern is best for every task. Pattern 1 gives the agent no cloud role. The agent writes infrastructure declarations, while platform IAM handles provisioning and IAM policies and networking are generated from the code. Local tests use an emulator. This fits teams that want agents to add infrastructure resources without editing IAM, but it does not serve a task that must read live cloud state.

Pattern 2 supplies a scoped role in a separate sandbox account. A permissions boundary caps what the role can do even if someone later attaches a broader policy, and the separate account keeps production out of reach. Credential expiry limits how long a leaked session remains useful without active revocation. The account boundary does distinct work here. A narrow policy is not a substitute for making production unreachable.

Pattern 3 introduces per-phase, task-scoped credential assumption. A task assumes a SessionRole with session tags such as user_id, repo, and task_id, and conditions using aws:PrincipalTag/* constrain its access. The aws-samples per-session IAM scoping design applies this mechanism to tenant-data clients accessing DynamoDB and S3. Its scope is narrower than an entire workflow. It does not show that every permission used in every phase comes through that derived session.

Credential refresh is essential to that design. AgentCore Runtime and ECS Fargate both supply assumed-role base credentials, so an agent-side sts:AssumeRole call creates role chaining and encounters the one-hour cap. The design permits tasks lasting up to eight hours. A one-shot assumption would therefore risk ExpiredToken during execution, while a refreshable provider re-assumes before expiry. AgentCore’s execution role is shared across runtime sessions, and its trust policy has no sts:TagSession or session-tag pass-through, so having the agent assume a role with tags works across these backends.

Pattern 4 uses federated or managed workload identity without storing a static key in the VM. A signed identity token can be exchanged for short-lived cloud credentials at the moment of use. Credential lifetimes should be measured in minutes and access confined to a single project or environment. This requires identity infrastructure the team may not yet have. A deliberately provisioned VM makes all four patterns enforceable, whereas a developer machine leaves even Pattern 2 only partially enforceable if broader ambient credentials remain available.

How the three cloud providers implement the underlying credential mechanisms differently

AWS separates credential issuance from several permission limits. AWS STS provides AssumeRole and AssumeRoleWithWebIdentity, while session policies restrict the role’s base permissions at assumption time. This supports phase-specific scope without creating a new role for every task. Permissions boundaries put a lasting limit on what a role can do. Service Control Policies constrain available permissions at the organization level, independently of what the agent’s role grants.

A session policy narrows a particular assumed session, while a boundary protects against a later expansion of role permissions. CloudTrail supplies the audit record for role assumptions and subsequent activity. The AWS Marketplace AI Agent IAM module describes a broader stack that combines task-scoped roles, time-bounded STS credentials, automatic secret rotation, and non-repudiable audit trails.

GCP uses Workload Identity Federation to exchange a signed identity token for short-lived credentials without a stored service account key file. The identity resulting from federation still needs to be scoped. Default service identities can still have more permissions than they need. An agent identity with broad Cloud Storage access remains overprivileged even when its credentials are temporary.

Azure uses Managed Identity for this form of credential-free VM configuration. The VM receives an identity at creation time, without a credential stored inside it. Azure RBAC then scopes that identity to resources, resource groups, subscriptions, or management groups. Identity issuance and resource authorization must both match the task, even though different services implement those layers.

Where the credential layer alone is not enough: policy enforcement at identity-time, plan-time, and runtime

Identity-time controls, including IAM roles, permissions boundaries, SCPs, and GCP Organization Policy, restrict permitted resources and actions. They do not inherently restrict call volume. An agent can make a thousand valid calls without stepping outside its granted authority.

Policy-as-code that runs before apply can reject a bad configuration even when the identity has permission to submit it. Yet a valid configuration can pass those checks and still cost too much when applied at scale. Runtime controls therefore supply the missing limit through service quotas, budget actions, TTL, and auto-stop. They constrain an in-policy runaway that identity and configuration checks cannot detect through scope alone.

Teams that put these layers in place should require human approval only for defined kinds of actions. Relevant classes include net-new monthly spend above a threshold, IAM or role changes, data deletion, public network exposure, and production writes. MCP servers can enforce controls outside the agent’s reasoning. The Marketplace module also treats prompt injection as a credential-theft threat, in which adversarial instructions induce the agent to exfiltrate its session credentials. Narrow scope and short lifetimes make a stolen credential less useful, but neither stops an attempt to steal it.

What scoped credentials look like in practice when Claude Code or Codex runs a task

Consider a Claude Code task that needs AWS access through MCP. Its mcp.json configuration can select a named profile using the credential provider chain, environment variables, or explicit credential configuration. In an isolated VM, the named profile can resolve to a task-scoped role and deliver a session credential. The profile name is not the security boundary. The authority behind it, and the absence of broader credentials elsewhere in the VM, determine what the task can reach.

Claude Code’s allow, ask, and deny rules set what the agent may run. Cloud IAM governs what a credential can authorize once used, so the two layers protect different boundaries. A permitted tool invocation can still encounter an IAM denial. But a rule that limits a tool leaves the credential’s permissions unchanged if it is exposed some other way.

OpenAI’s Codex launch page describes autonomous cloud tasks running in isolated containers preloaded with the repository. When Codex runs inside a separately provisioned VM, its cloud authority likewise depends on the credential surface that environment exposes.

One agent process may also need different credentials for each tool. Frameworks such as Strands can initialize individual MCP clients with credentials obtained through distinct AssumeRole calls. However, separate roles alone do not identify the originating user or task, so attribution must be established when each session is assumed.

Audit trails and attribution: making every agent credential call traceable to a task

An audit record must connect an action to the agent run, its authorization, and its credential. Session tags such as user_id, repo, and task_id, passed at AssumeRole time, provide the task context needed to interpret CloudTrail activity. Role names alone are not enough. A shared role can identify the authority used without identifying which task exercised it.

The same task context can also enforce data boundaries. The aws-samples design includes DynamoDB leading-key conditions and Bedrock ARN allowlists within its per-session scoping work. These controls limit which data rows and model ARNs the agent can access as well as which IAM actions it can take. Attribution is therefore more than a label added afterward. It participates in the authorization design as well as the operational record.

That connection becomes especially useful after a credential compromise. A session associated with a specific task_id gives the team context for revocation, log review, and enumeration of the affected resources. Without that link, activity records show what happened but not which work led to it. Task-level attribution also connects credential use to engineering outcomes, including merged pull requests and runs that produced nothing worth shipping.

Putting it together: the decision path for structuring agent credentials on AWS, GCP, and Azure

The decision begins with whether the agent needs direct cloud API access, which account it must reach, and how long the task runs. For teams choosing an implementation, declarations-only work points to Pattern 1, with platform IAM handling provisioning. Live cloud access changes the choice. If that access is limited to non-production, Pattern 2 supplies a scoped sandbox role with a permissions boundary and no reachable production account.

Longer workflows introduce credential-lifecycle requirements as well as permission requirements. Pattern 3 fits tasks that need task-scoped access to refresh across phases that last more than one hour. On AWS assumed-role compute, the refreshable provider must account for the role-chaining cap rather than treating the task’s maximum lifetime as the credential lifetime. Session tags establish the task context at assumption time. Refresh and attribution belong in the credential provider.

Where the infrastructure supports it, Pattern 4 offers the strongest posture through AWS AssumeRoleWithWebIdentity, GCP Workload Identity Federation, or Azure Managed Identity. The provider choice does not remove the other controls. Every credentialed path still needs task attribution, a static permission limit through boundaries or organization policies, and runtime quotas that constrain authorized overuse. The resulting design lets Claude Code or Codex perform useful cloud work without making the whole account part of the task’s available environment.

Sources

  1. feat(security): per-session IAM scoping — session-tagged AssumeRole, DynamoDB leading-key conditions, Bedrock ARN allowlist · Issue #209 · aws-samples/sample-autonomous-cloud-coding-agents · GitHub
  2. AI Agents Security for Developers: Don't Let Your Agents Become a Liability

More in Cloud Agent Environments