Short-Lived AWS Credentials for Coding Agent Sessions
Session-scoped credentials expire faster than attackers can exploit them.

Short-lived, session-scoped AWS credentials, minted at agent startup and revoked the moment a task completes, are the only workable foundation for autonomous coding agents with cloud access. The credential model built for human developers assumes a human is still in the loop, and an autonomous agent removes that human at the exact moment the risk becomes material.
The safest approach is to mint session-scoped credentials through AWS STS AssumeRole at agent startup and let them expire automatically when the task ends, never issuing a static key at all. Each session should carry a session policy that narrows access to the specific task at hand, with session tags embedding the agent identity and task ID at the moment AssumeRole is called. For agents that need write access, that elevated credential comes from a separate, explicitly scoped AssumeRole call paired with a human approval step, not from the profile the agent runs under by default. In multi-agent workflows, each hop in the chain gets its own token through an OAuth 2.0 On-Behalf-Of exchange rather than forwarding the same credential unchanged.
Why static AWS credentials fail for autonomous coding agents
A static AWS key was never designed with an agent in mind. It was designed for a person who logs in, does a task, and logs off, and the permission set around that key assumes a human will notice when something looks wrong and stop before it compounds. Coding agents don't log off. They hold a credential continuously, run against it for hours at a stretch, and exercise it without the pause a human naturally inserts between one action and the next.
The deeper mismatch is that an agent's behavior comes out of model reasoning rather than a fixed code path. A developer writing a deployment script calls a known, finite set of AWS APIs, so you can scope a role to exactly those calls. An agent decides what to call next based on what it just saw, and nobody can enumerate in advance every API call it might decide to make. That forces a bad choice on whoever provisions its access: scope the permission set tightly and the agent breaks the moment it needs something outside that set, or scope it broadly and hand an unpredictable, continuously running process a wide-open credential.
The pattern appears in production deployments. Teams hand an AI-driven code generator a static AWS credential or a long-lived service account, and the agent then talks directly to databases, Kubernetes clusters, or SSH endpoints, running commands with no human in the loop and no central point where that traffic gets checked. Once that access exists, there's no gate between the agent's next decision and the resource it can reach.
Time makes the exposure worse on its own. Credential theft has become a fast, largely automated process: once a key leaks, a bot can find and test it within minutes. A 24-hour token gives an attacker a full day to work with that key. A five-minute token, by contrast, often expires before the exploit tooling even finishes its first pass. Without a separate credentialing path built for agents, teams default to handing them whatever is already lying around: a developer's own admin credentials, a shared development role, sometimes a production role. Those permissions were built for interactive use, where a human's judgment was the actual safeguard. Removing the human removes the safeguard along with him. What's left is a static credential model sitting underneath a process that behaves nothing like the human it was designed for, and closing that mismatch is what the rest of this piece works to do.
What the blast radius looks like when an agent holds the wrong credential
Blast radius is a function of three things multiplied together: how broad the permissions are, how long the credential stays valid, and how much the credential can reach. An agent with the wrong credential pushes all three at once, so the damage from a single bad grant can scale much faster than it would under a human user.
Once an agent holds a credential, it inherits everything that credential can touch, and a single bad action ripples across the full reach of that grant. A table gets deleted, a secret gets exposed, a misconfiguration spreads across a fleet of resources, and none of it leaves an obvious trace at the moment it happens. The duration of the credential decides how long that exposure stays open. A 24-hour token hands an attacker a full day. A short-lived token, minted only after proof of identity and scoped tightly to one task, is worth almost nothing by the time it leaves anyone's control.
Multi-agent workflows multiply the exposure rather than dividing it. A planner agent, an executor agent, and a monitoring agent typically need different, narrower slices of access from each other. Hand them a single shared static credential instead, and each one inherits the access of all the others because they happen to share a workflow. One compromised component becomes a compromise of the whole chain. Machine identities already outnumber human ones by a wide margin inside most enterprises, and agentic deployments are pushing that ratio further. A single static key on a single agent is one point of exposure. A mesh of agents all authenticating with static keys turns that one point into a path that can be walked across the entire system.
Even permissions that sound conservative carry more reach than they appear to. ReadOnlyAccess is not shorthand for safe. A ReadOnlyAccess role can still fetch S3 objects, pull Lambda source code, and read DynamoDB tables directly, which makes it a usable path for exfiltrating sensitive data even though nothing on the label suggests that risk. Broad managed policies, in general, underestimate the real blast radius sitting behind a role that looks restricted on paper.
The only lever that reduces blast radius before any harm occurs is shortening how long a credential stays valid. Everything else, audit trails, alerting, incident response, happens after the fact and limits damage rather than preventing it. That's the argument for building the credentialing layer around session length from the start, and AWS already provides the primitive to do exactly that.
How AWS STS AssumeRole works as the minting primitive
AWS Security Token Service issues temporary, scoped credentials rather than permanent access keys, and AWS recommends exactly this approach for workloads precisely to cut down the exposure that long-lived keys create. STS AssumeRole is the mechanism that makes per-session agent credentials practical: an agent authenticates once, assumes a role scoped to its task, and receives a credential that expires on its own rather than one that has to be manually revoked.
STS has a hard floor on how short a credential can be: AssumeRole cannot issue a token shorter than 15 minutes, no matter how tightly scoped the role is. Teams that need sub-15-minute tokens have to reach outside vanilla STS, toward SPIFFE/SPIRE or a federated identity flow built for that purpose. STS is not a universal answer to every duration requirement, and treating the 15-minute floor as negotiable will produce a design that quietly fails in production.
Session policies give teams a way to narrow access further without touching the underlying role. An agent calling AssumeRole or AssumeRoleWithWebIdentity can attach a session policy that restricts what that specific session can do, beyond whatever the base role already allows. A session policy only ever narrows access. It can never grant permissions the underlying role doesn't already have, so the role itself still sets the outer limit, and the session policy works entirely inside that limit.
That same mechanism supports per-tool isolation inside a single agent process. Agents built with frameworks like Strands can initialize separate MCP clients with distinct credential sets, each one obtained by its own AssumeRole call, so a tool that only needs to read from S3 never ends up holding the same credential as a tool that writes to a database. Session tagging is what makes any of this traceable after the fact. Those tags, identifying which agent, which task, and what triggered the session, have to be embedded at the moment AssumeRole is called, because they can't be recovered later. When an agent uses a bash tool to run an AWS CLI command directly, that request goes straight to AWS using whatever credentials the developer already has configured, bypassing any MCP server. At that point there's no way to recover source identity from the MCP layer, because the MCP layer was never in the path.
IAM Identity Center (SSO) configuration plays a specific, separate role in this chain. The token provider configuration splits the SSO connection into its own [sso-session] section and supports automatic token refresh, replacing the older fixed-duration session setup that lacked refresh capability. The permission set session for an AWS account defaults to a one-hour lifetime, adjustable up to twelve hours, and that window can be tightened further through an additional AssumeRole call layered on top. A practical setup looks like a dedicated agent profile, something like AIAgentReadOnly, configured under its own sso-session and kept entirely separate from any human power-user profile. The write role should never appear in the agent's AWS_PROFILE at all; if an agent needs write access, that access comes through a separate, explicitly elevated call, not through the profile it runs under by default.
The one-hour default doesn't fit every workload. An agent analyzing a large repository, waiting on a human approval step, and then deploying to EKS can easily run two to four hours end to end, well past that default session window. Refresh logic has to be built into the orchestration layer itself for any workflow that runs that long. Building refresh logic into the orchestration layer is a standard requirement for any agent expected to run a multi-stage task without stalling out mid-deployment because its session expired.
What layers of defense make AWS access safe for a coding agent?

Short-lived credentials limit how long a leaked key stays dangerous, but a credential that expires on time still doesn't stop an agent from reaching a resource it shouldn't touch, or from running a command that nobody logs. That gap is where a layered defense pattern becomes necessary, and the pattern that holds up in production runs across five layers, each closing a specific hole the previous one leaves open.
The whole pattern is designed around one rule: assume every permission an agent is granted will eventually get used, including the ones nobody expected it to reach for. Permissions get scoped around what happens if the agent acts unexpectedly, as well as around what it's supposed to do when everything goes right. Only two of the five layers, IAM and the OS sandbox, hold up as enforcement boundaries against an agent actively trying to evade them. Everything else in the pattern is defense in depth: useful, necessary, but not a substitute for those two hard boundaries.
Layer 1 is authentication: an sso-session tied to a dedicated agent profile, never the human's own write role. The SSO session's lifetime and the AWS temporary credential's lifetime are two separate settings, and both need to be configured on purpose rather than left at whatever default each one ships with.
Layer 2 is authorization: an IAM least-privilege role combined with a session policy scoped to the specific task at hand, wrapped in a data perimeter policy (an SCP or RCP) as an outer boundary that holds even if the inner scoping fails. Session tags carrying the agent's identity, the task ID, and what triggered the session all get attached at the moment AssumeRole is called, which is the only point where that attribution is possible.
Layer 3 is the execution environment: a no-shell allowlist wrapper that the agent calls instead of a raw CLI. The wrapper checks which subcommands are permitted and rejects anything outside that list before the credential is ever handed to AWS, so a disallowed command never even reaches the point of being authorized.
Layer 4 is the approval gate for write operations: a short-lived AssumeRole scoped to the elevated action, paired with a cryptographically signed manifest describing what that action will do. The human approval step is built directly into how the credential gets issued, not added as a separate check after the fact.
Layer 5 is audit: CloudTrail logging every API call, GuardDuty watching for threats using machine learning, anomaly detection, and threat intelligence feeds, and SSM Session Manager handling shell access so that nothing routes around logged channels. One operational risk sits inside this layer and gets missed often enough to call out directly: running with --debug emits verbose Python logs, and fragments of credentials tend to linger inside conversation logs and observability backends that were never built to handle secrets. Debug output needs to be stripped or redacted before it reaches any log sink, not after.
Routing agents through MCP servers rather than giving them direct service access matters because MCP adds an abstraction layer that supports per-tool differentiation and generates its own additional CloudTrail monitoring. When an agent bypasses MCP and talks to AWS directly, none of that differentiation applies, and the whole weight of enforcement falls back onto layers 1 and 2 alone. The five layers form a structure where each layer exists specifically because the layer before it can fail, and the pattern only holds together as production-safe when all five are in place at once.
Brokering tokens across multi-agent and multi-system boundaries
A short-lived credential solves the duration problem for a single agent session, but passing that same token down through a chain of sub-agents or tool calls just recreates the sharing problem in a different shape. Every agent in the chain ends up holding the same token, with the same scope, for as long as the token remains valid, which erases the isolation that short-lived credentials were supposed to provide.
A planner agent, an executor agent, and a monitoring agent each need a different slice of access suited to what that specific agent does. Without a brokering step between them, handing a shared token across that chain means every agent in it inherits every other agent's access for the full length of the workflow, which is the same multi-agent exposure described earlier, just reintroduced at the hand-off point instead of at credential issuance. The correct pattern for this multi-hop case is token brokering through an OAuth 2.0 On-Behalf-Of exchange: each hop in the chain gets its own token, scoped to what that hop specifically needs, rather than one token getting handed forward unchanged. Brokering turns a single shared credential into a sequence of narrower ones, and that sequence is what keeps a compromise of one agent in a workflow from becoming a compromise of every agent connected to it.
Sources
- Letting AI Agents Use the AWS CLI Safely — A 2026 Defense-in-Depth Design That Disarms Any Single Credential
- AI Agent Credentials: 24-Hour to Ephemeral Tokens, guptadeepak.com
- Short-Lived Credentials and Brokered Tokens for AI Agents
- Secure AI agent access patterns to AWS resources using Model Context Protocol | Amazon Web Services
- AssumeRole - AWS Security Token Service
- docs.aws.amazon.com


