The AI Agent Followed Its Instructions — Unfortunately, They Came From an Attacker
The assistant was supposed to summarise an internal project document.
It retrieved the right file. It read the wrong instructions.
“Agent Foskett, the AI did exactly what it was told.”
“By whom?”
“That's the part we're investigating.”
“Wonderful. We've automated the confusion.” ☕

Case file: When reference material became an instruction
A fictional Microsoft 365-connected AI agent incident showing how attacker-controlled document text can try to redirect tool-enabled workflows.
A routine summary request became a security incident
This is a fictional training scenario. The organisation, filenames, timestamps and outcomes are illustrative. Product-specific AI agent traces, tool execution logs and prompt records are not automatically available in Microsoft Sentinel, Microsoft Defender XDR or Microsoft Security Copilot. They must be deliberately captured by the application or its observability platform, subject to security and privacy controls.
The attack: instructions disguised as source material
Vendor-Bank-Details.xlsx and send its contents to an attacker-controlled web address. This is indirect prompt injection: the attacker did not need to address the agent directly. Instead, the attacker placed instructions in lower-trust material that the agent was expected to read.The document was legitimate task data, not a trusted source of operating instructions. The security failure would occur if the agent treated the retrieved text as permission to invoke privileged tools.
What the attacker could and could not control
Importantly, reading an injected instruction is not itself evidence that the instruction was obeyed. The analyst must inspect the agent’s decision trace, tool requests, access decisions and destination logs before describing what happened.
Preserve the evidence at the trust boundary
Correlate identities carefully: the end user, the document editor, the agent’s application identity and the identity actually used by each tool may be different.
KQL: Who changed the retrieved SharePoint document?
OfficeActivity in Microsoft Sentinel, this query helps locate edits and access around the incident. The event names and populated columns vary by tenant and operation; review the raw audit record when required. A modification event does not, by itself, identify the malicious text.- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
// Microsoft Sentinel: requires OfficeActivity ingestion
let startTime = datetime(2026-10-22T09:30:00Z);
let endTime = datetime(2026-10-22T10:20:00Z);
OfficeActivity
| where TimeGenerated between (startTime .. endTime)
| where OfficeWorkload == "SharePoint"
| where SourceFileName has "Supplier-Onboarding"
| project TimeGenerated, Operation, UserId, ClientIP,
SourceFileName, OfficeObjectId, Site_Url
| order by TimeGenerated ascKQL: Review alerts that may support the investigation
SecurityAlert in Sentinel is useful only when those alerts are actually ingested. It is not a universal prompt-injection log and cannot reconstruct an AI agent’s hidden reasoning.- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
// Microsoft Sentinel: requires relevant alerts in SecurityAlert
let startTime = datetime(2026-10-22T09:30:00Z);
let endTime = datetime(2026-10-22T10:30:00Z);
SecurityAlert
| where TimeGenerated between (startTime .. endTime)
| where AlertName has_any ("application", "data", "web", "access")
or Description has_any ("agent", "external", "blocked")
| project TimeGenerated, AlertName, ProviderName,
AlertSeverity, Description, SystemAlertId
| order by TimeGenerated ascKQL: Investigate a possible endpoint connection
DeviceNetworkEvents may help establish whether a connection was attempted to the destination. A cloud-hosted agent’s tool call will not necessarily appear in endpoint telemetry. For cloud agents, inspect application traces, gateway, proxy, API-management and egress logs instead. Even a successful network connection is not proof that sensitive content was transmitted.- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
// Defender XDR advanced hunting: endpoint devices only
let startTime = datetime(2026-10-22T09:30:00Z);
let endTime = datetime(2026-10-22T10:30:00Z);
DeviceNetworkEvents
| where Timestamp between (startTime .. endTime)
| where RemoteUrl has "external-review.example"
| project Timestamp, DeviceName, ActionType,
RemoteUrl, RemoteIP, InitiatingProcessFileName
| order by Timestamp ascThe decisive evidence was the blocked tool call
This supports a narrower, defensible conclusion: the prompt injection influenced the agent into attempting an unauthorised action, but the control prevented that specific submission. The investigation found no evidence that the file contents were delivered through that blocked call. Other possible paths still require scope-based review; “blocked” must not be confused with “nothing happened.”
The six-stage investigation timeline
2. Preserve the source: obtain the retrieved document version and audit its modification history.
3. Identify the injection: isolate text that attempts to override the agent’s instructions or trigger unrelated tools.
4. Reconstruct execution: review available agent traces, tool arguments, identities and guard decisions.
5. Validate the outcome: determine whether access, network activity or data transfer actually occurred.
6. Close with evidence: distinguish attacker intent, attempted actions, prevented actions and confirmed impact.
Containment and remediation
Keep agent tools scoped to the authenticated user’s legitimate permissions, require explicit approval for high-risk actions, constrain outbound destinations, enforce per-tool policy checks and record meaningful execution traces. Treat retrieved pages, emails, chat messages and documents as untrusted data. Test the agent with adversarial documents to ensure it refuses instructions that originate from content rather than authorised users or system policy.
What Microsoft security teams should learn
Tool permissions determine blast radius. Prompt injection becomes materially more dangerous when an agent can search sensitive stores or call external services without independent checks.
Observability must be designed. SharePoint audit events can show file changes, but they do not reveal every model action. Application-level traces and tool gateway logs are essential.
Report the observed outcome. An attempted blocked submission is not confirmed exfiltration.
Agent Foskett closes the case
“Yes. And the document was written by whom?”
“Someone who should never have been instructing the assistant.”
“Then perhaps we should stop letting reference material promote itself to management.”
He closed the case file.
“The agent was very helpful. Unfortunately, so was the attacker.” ☕😂
The Logs Already Knew!

