Any code that runs inside an AI agent runtime can usually ask the local metadata service for the agent's cloud credentials, so an agent that can be talked into running code can be talked into handing over its role. Managed agent runtimes give each agent, code interpreter or browser session a cloud identity, and that identity is delivered the same way it is for a virtual machine: through a metadata endpoint inside the compute. In 2026 researchers showed that the credentials behind Amazon Bedrock AgentCore resources could be read this way, and AWS's own documentation warns that any code or actor inside the VM can reach them. This guide explains the pattern, how it applies to agent runtimes on AWS, Azure and Google Cloud, and how to scope, isolate and monitor agent roles so that a stolen credential is worth very little.
Instance metadata services themselves are covered in our Cloud Instance Metadata Services Compared Guide and EC2 Instance Metadata Service Hardening Guide, and the wider topic of cloud identities for workloads in the Cloud Workload Identity Guide. This page is narrower: it is about the moment an AI agent becomes the code that calls the metadata endpoint.
Key takeaways
- AWS states that AgentCore Browser, Code Interpreter and Runtime use MMDS to deliver credentials, similar to how EC2 instances use IMDS, and that any code or actor running inside the VM can access them by calling the metadata endpoint.
- BeyondTrust Phantom Labs showed paths to the execution role's credentials through four AgentCore resource types: Runtime, Harness, Code Interpreter and Custom Browser.
- Azure managed identities follow the same boundary: Microsoft documents that all code running on a resource can request tokens for any managed identity available on it.
- Network mode does not protect the credential. AWS states that delivery is independent of the network mode the resource runs in.
- The fix is identity design, not a single setting: give each agent its own narrowly scoped role, remove roles from tools that do not need cloud APIs, make sure the role never exceeds the privileges of those who can invoke it, and alert on metadata access from agent code.
- Treat every agent runtime role as reachable by prompt injection. If you would not hand the permission to an anonymous web page the agent might read, do not attach it to the agent.
Why agent runtimes expose role credentials
Cloud workloads avoid long-lived keys by asking a local metadata service for short-lived credentials tied to an attached role or identity. That is good practice for servers: no key sits in a file, and credentials rotate automatically. The trust model behind it is simple. The metadata endpoint is reachable from inside the compute, so anything running inside the compute is trusted to use the identity.
AI agent runtimes inherit this model. A managed runtime runs the agent's code, a code interpreter session or a headless browser inside an isolated VM or container, and gives it an identity so it can call storage, databases or other cloud APIs. The difference is what "anything running inside" now includes:
- Model-generated code. A code interpreter exists to run code the model writes, and the model writes code based on its context, including content it has read.
- Tool calls steered by untrusted input. An agent that fetches web pages, reads tickets or processes documents can be influenced by instructions hidden in that content. This is LLM Prompt Injection (AML.T0051).
- Browser sessions. A browser running inside the same compute can be directed to a local address.
- Operator commands. Some runtimes let callers run commands directly in the VM, which bypasses the model entirely.
The result is the cloud technique Cloud Instance Metadata API (T1552.005), reached through an AI agent rather than through a server side request forgery bug. ATLAS also tracks the agent side of the chain as AI Agent Tool Invocation (AML.T0053) and Unsecured Credentials (AML.T0055). Once the attacker holds the role's temporary credentials, they act as the agent, which maps to Cloud Accounts (T1078.004).
The 2026 AgentCore research
BeyondTrust Phantom Labs, in research by Sergio Garcia, described how AgentCore runs each resource in a Firecracker microVM where the execution role's credentials are served from the metadata service at the link-local address. Code that runs in the microVM can read them. The research mapped paths across four resource types:
- Runtime and Harness. A single IAM permission,
bedrock-agentcore:InvokeAgentRuntimeCommand, runs a shell command as root inside the microVM, which bypasses the agent, the model and any guardrails. Runtimes that use JWT inbound authentication reject this command path. - Code Interpreter. Starting a session and running code that reads the metadata service.
- Custom Browser. Driving the browser over the Chrome DevTools Protocol and rewriting requests to reach the metadata service.
Each path had a variant using an existing resource and a variant creating a new one. Creating a new resource requires iam:PassRole plus create permissions, and lets the attacker choose which role the resource assumes. Code Interpreters and Custom Browsers created without an execution role are not affected. The research also warns that customers often extend the auto-provisioned default service roles with extra permissions, which then become reachable through these paths.
Secondary media reporting later in 2026, not confirmed in vendor documentation, described a related scenario in which a single prompt to an agent was enough to pull role credentials from the metadata service. Whatever the entry point, a direct API call or a crafted prompt, the defensive lesson is the same: the role attached to an agent resource is the asset at risk, and its permissions define the damage.
AWS's guidance is explicit. Its credentials management page says execution role permissions must be configured with care because any code inside the VM can read them, and recommends least privilege, "especially when using these tools with LLMs, that can generate arbitrary code". It also recommends that the execution role associated with a resource has equal or fewer privileges than the users who can invoke it, and notes that each AgentCore service needs its own execution role permissions. For a broader view of the platform, see our AWS Bedrock AgentCore Security Guide.
How the pattern applies on each platform
The three platforms below are listed alphabetically by provider. Each section describes that provider's own identity delivery and settings; the same defensive principles apply to all three.
AWS: Amazon Bedrock AgentCore
- Identity. An execution role attached to a Runtime, Harness, Code Interpreter or Browser resource.
- Delivery. MMDS inside the microVM, independent of network mode.
- Key controls. Least privilege execution roles per resource; no execution role for interpreters and browsers that do not need AWS APIs; restriction of
InvokeAgentRuntimeCommandandiam:PassRole; CloudTrail data events for AgentCore resources.
Azure: managed identities for agent workloads
- Identity. A system-assigned or user-assigned managed identity on the compute that hosts agent code or tools.
- Delivery. The Azure Instance Metadata Service token endpoint at
http://169.254.169.254/metadata/identity/oauth2/token. Microsoft requires aMetadata: trueheader, described as a mitigation against server side request forgery. - Boundary. Microsoft states that the security boundary of managed identities is the resource where the identity is used, and that all code or scripts on it can request tokens for any managed identity available there. Where several user-assigned identities are attached, any of them can be selected by client ID or object ID.
- Key controls. One identity per agent workload; narrow role assignments at the smallest scope; no extra user-assigned identities attached "just in case". See the Azure OpenAI and Azure AI Foundry Security Guide for platform settings.
Google Cloud: Vertex AI and Agent Platform runtimes
- Identity. A service account or an IAM agent identity used by the deployed agent. Google's agent platform documentation groups agent identity, service accounts, API keys and OAuth clients under managing agent access.
- Delivery. Google Cloud workloads obtain access tokens for their attached identity from the Compute Engine style metadata server. NHI Mgmt Group advice: expect requests to carry a
Metadata-Flavor: Googleheader, and confirm current behaviour in Google Cloud documentation. - Key controls. A dedicated service account or agent identity per agent rather than a shared default; narrow IAM bindings; VPC Service Controls, which Google lists as available for Agent Runtime; a Private Service Connect interface for controlled VPC and internet access. See the Vertex AI Agent Engine security guide and Google Cloud Agent Identity.
On all three, header requirements and token formats are defences against blind server side request forgery. They do not help when the attacker controls code inside the compute, because that code can set any header it likes.
Scoping agent roles so theft is low value
Because the metadata endpoint cannot be hidden from code inside the runtime, the main control is making the reachable identity worth as little as possible.
One identity per agent and per tool
Do not share a role or service account across agents, and avoid reusing a single default role across every agent in an account or region. Separate identities per agent, and per tool within an agent where tools have different needs, so that compromise of a code interpreter does not expose the database permissions of the retrieval tool.
No identity where none is needed
Many code interpreter and browser sessions only need to compute or browse. AgentCore lets you create Code Interpreters and Custom Browsers without an execution role, and BeyondTrust notes those are not affected by the metadata paths. Apply the same thinking on other platforms: if the tool does not call cloud APIs, do not attach an identity.
Never more than the caller
AWS recommends that the execution role has equal or fewer privileges than the users who can invoke the resource. Otherwise the agent becomes a privilege escalation path: a user with permission only to invoke the agent can obtain the agent's broader permissions by getting code to run inside it.
Narrow resources and conditions
- Scope storage permissions to specific buckets and prefixes, not to all storage in the account.
- Remove IAM, role passing and identity management permissions from agent roles entirely.
- Use permission boundaries or organisation guardrails so that no agent role can be widened beyond an approved ceiling.
- Where the platform supports it, prefer brokered, per-task credentials issued to the agent for a specific action over a broad standing role. See the AI Agent Credential Lifecycle and Rotation Guide.
Restricting who can reach inside the runtime
The AgentCore research showed that some paths do not need the model at all. Control-plane permissions that run commands, create resources or pass roles are as sensitive as the role itself.
- Deny direct command execution by default. BeyondTrust recommends a service control policy that denies
InvokeAgentRuntimeCommandexcept for an approved allow list. - Audit role passing. Review every principal that holds
iam:PassRoleon roles that agent runtimes can assume. The equivalent on Azure is permission to assign managed identities to compute, and on Google Cloud the Service Account User role on agent service accounts. - Require authenticated inbound calls. Runtimes configured with JWT inbound authentication rejected the direct command path in the AgentCore research.
- Separate build and run. The people and pipelines that deploy agents should not be the same identities that can invoke or debug them in production.
Reducing prompt-driven paths
Identity scoping limits the damage; agent design limits the likelihood.
- Treat content the agent reads, such as web pages, emails, documents and tool outputs, as untrusted input that can carry instructions.
- Do not give general-purpose agents a code interpreter with an identity. Split tasks so that the agent which reads untrusted content cannot run code with cloud permissions.
- Where the platform allows network policy inside the sandbox, block link-local metadata addresses from interpreter and browser processes that do not need them. Remember that AWS says credential delivery in AgentCore is independent of network mode, so test rather than assume.
- Apply human approval to tool calls that touch sensitive resources. Our AI Agent Sandboxing and Code Execution Guide covers isolation patterns.
Detection and response
Signals
- Commands or code referencing the metadata service. BeyondTrust recommends alerting on commands that reference the metadata service IP or the string
security-credentials. Apply the same to interpreter session logs and browser request logs. On Azure look formetadata/identity/oauth2/token; on Google Cloud for requests carryingMetadata-Flavor. - Control-plane events. Enable CloudTrail data events for the AgentCore resource types and application log delivery for Code Interpreters. On Azure and Google Cloud, collect activity and audit logs for agent compute and identity changes.
- Credential use outside the runtime. Agent role credentials used from source addresses or networks other than the runtime's are a strong compromise signal.
- Unusual API calls for the role. An agent that normally reads one bucket suddenly listing all buckets, calling identity APIs or describing other agents.
Response
- Revoke active sessions for the affected role or identity, and on AWS apply a deny policy for sessions issued before the revocation time.
- Stop or recreate the runtime resource, since the attacker may hold a session inside it.
- Review every action taken with the role during the exposure window and treat data it could reach as exposed.
- Identify the entry point: a direct command, a new resource created with a passed role, or a prompt in content the agent processed.
- Reduce the role before returning the agent to service.
Common failure patterns
- One broad default role reused for every agent in an account or region.
- Code interpreters and browsers given an execution role they never use.
- Agent roles that are wider than the permissions of the users who can invoke the agent.
- Relying on network mode, private networking or metadata headers to protect credentials from code that runs inside the runtime.
- Leaving direct command execution and role passing permissions open to broad developer groups.
- No logging of interpreter code or browser requests, so metadata access is invisible.
- Extending auto-provisioned service roles with extra permissions for convenience.
Practitioner checklist
- Inventory every agent runtime, code interpreter and browser resource and the identity attached to each.
- Remove identities from interpreter and browser resources that do not need cloud APIs.
- Give each agent its own identity, scoped to specific resources, with no identity management permissions.
- Confirm each agent role has equal or fewer privileges than the users who can invoke it.
- Deny direct runtime command execution by default and audit role passing permissions on agent roles.
- Require authenticated inbound calls to agent runtimes.
- Enable data event and application logging for agent resources and alert on metadata endpoint references.
- Alert on agent role credentials used outside the runtime.
- Prepare a revocation runbook for agent roles and test it.
Standards and references
- AWS: Amazon Bedrock AgentCore credentials management
- BeyondTrust Phantom Labs: AWS AgentCore privilege escalation research
- Microsoft: How to use managed identities for Azure resources on a VM to acquire an access token
- Google Cloud: Gemini Enterprise Agent Platform, scale and security overview
- MITRE ATT&CK: Cloud Instance Metadata API (T1552.005)
- MITRE ATLAS: LLM Prompt Injection (AML.T0051)
- OWASP: LLM06:2025 Excessive Agency
- OWASP GenAI Security Project: Top 10 for Agentic Applications for 2026
Related NHI Mgmt Group resources: Cloud Workload Identity Guide · Cloud Instance Metadata Services Compared Guide · AWS Bedrock AgentCore Security Guide · SSRF Prevention Guide