How to audit what AI coding agents and MCP servers did in your AWS account with CloudTrail
AI coding agents and MCP servers now run AWS CLI and SDK calls for developers. They usually run with the developer's own credentials, often an administrator role from single sign-on. In CloudTrail, the agent's calls look like the person's calls. After an incident, nobody can say what the agent read, what it changed, or what it tried and was denied.
Do it yourself with CloudTrail event history
Every AWS account has CloudTrail event history: the last 90 days of management events, per region, at no extra cost and with no trail to set up.
- Pull the write calls for one person in one region:
aws cloudtrail lookup-events --region us-east-1 \ --lookup-attributes AttributeKey=Username,AttributeValue=jane@example.com \ --start-time 2026-11-20T00:00:00Z --query 'Events[].CloudTrailEvent' --output json \ | jq -r '.[] | fromjson | select(.readOnly==false) | [.eventTime, .eventSource, .eventName, .userAgent, .errorCode // "-"] | @tsv' - Look at the user agent. Each event records the
userAgentof the client. The AWS CLI and SDKs identify themselves there, and some agent tools and frameworks add their own name. - Look at the identity.
userIdentity.arnincludes the role session name for assumed roles. If agents use their own role or session name, you can filter on it directly. - Check the errors. Events with
errorCodeset toAccessDeniedor similar show what the agent tried and could not do, which is often the most useful part.
Make the next audit easier
- Give agents their own IAM role instead of a person's admin role, with a short maximum session duration and only the permissions they need.
- Start agent sessions with a recognisable session name, for example
aws sts assume-role --role-session-name agent-jane ..., or set a source identity, so every call can be traced to the agent and the person behind it. - Set an application ID for the SDK user agent in the agent's environment (the
AWS_SDK_UA_APP_IDvariable) so its calls are labelled in CloudTrail.
Gotchas
- Event history is per region. Calls to global services such as IAM are recorded in us-east-1, so check that region too.
lookup-eventsaccepts one lookup attribute per call and is rate limited, so scanning a busy account by hand is slow.- Event history holds management events only. Data events such as S3 object reads are not included unless you configure a trail for them.
- Events appear a few minutes after the call, not instantly.
- A user agent is a hint, not proof. It can be changed by the client.
How AI Agent Activity Audit for AWS automates it
You connect an AWS account with a read-only IAM role that can read CloudTrail event history and IAM role metadata. Every 10 minutes we read new events and pick out agent calls by user agent signature, role session name, roles you mark as agent roles, or your own patterns, and every detection says why it matched. Calls are grouped into agent sessions with a timeline of reads, writes, errors and AccessDenied. You get instant Slack or email alerts for high-risk calls such as IAM changes and deletes, a daily digest of agent writes, risk findings such as agents on admin roles, and a least-privilege policy built from the calls your agents really made. We store only calls that match an agent rule.