
In the previous part: we moved AI agent governance from Defender into Agent 365 - one inventory of agents, their owners and the controls that come with agent identities.
Parts 1 to 6 were about seeing local AI agents, controlling what they connect to and governing them in Agent 365. Part 7 asks the next question: when someone runs an agent you have not approved, can you stop them signing in? At Ignite 2026 Microsoft announced a chain for exactly that - Entra Agent ID for local agents, an Intune compliance setting for unapproved agents, and a Conditional Access block. Most write-ups so far summarise the announcement. This post tests it in a lab and reports what actually happened.
Short version: the Microsoft-native route needs Agent 365, which this E5 lab does not have. So I built the chain from E5 parts. The device-compliance route stalled. The identity route worked end to end, from an unapproved agent launching to the user being blocked at sign-in.
The lab
- One onboarded Windows 11 VM, purview, used throughout the series.
- Test user edge: Microsoft 365 E5, no Entra roles, local admin on the VM.
- The admin account is excluded from every policy in this post, so a noncompliant lab device can never lock out the admin.
- Approved agents: Claude Code (CLI and VS Code), Claude Desktop and GitHub Copilot (CLI and VS Code). Anything else is unapproved - block-all by default, as in Part 5.
- The unapproved test agent: Gemini CLI, installed by edge with npm.
Before testing, the VM carried 31 alerts from earlier parts of the series, which left it at High device risk. I closed those as Benign Positive - Security Testing and dismissed the user risk, so every result below starts from a clean baseline.
What Defender already knows
Advanced hunting against AgentsInfo shows six local agents discovered on purview: Claude Code, the Claude Code and GitHub Copilot VS Code extensions, GitHub Copilot CLI, Claude Desktop and Gemini CLI.
AgentsInfo
| where Timestamp > ago(30d)
| where Platform == "LocalAgents"
| summarize arg_max(Timestamp, *) by Name
| project Timestamp, Name, Version, AgentId

The table now has an EntraAgentID column, which was not there when Part 3 was written. That is where the Ignite preview records the Entra identity given to a discovered local agent. In this lab it is empty for every agent, and Entra ID > Agents > Overview agrees: no agent identities. Every action these agents take is still recorded against the signed-in user. Keep that in mind - it decides which Conditional Access policy can stop them.

Route A: Microsoft’s agent compliance setting
The announced Intune setting marks a device noncompliant when it runs an unapproved local agent. In an E5 tenant without Agent 365 it does not appear. Creating a Windows 10 and later compliance policy offers only the classic policy and an empty Templates list. The new Agents node in Intune is for Security Copilot agents, not local AI agents.

So Route A is out for most E5 customers today. The rest of this post is Route B: the same outcome built from parts you already own.
Route B, step 1: detect the unapproved agent
The scheduled rule
AgentsInfo has no DeviceId column. The device, user and vendor sit inside RawAgentInfo.localAgentMetadata, so the query pulls them out to give the detection the entities it needs.
// Detect-UnapprovedLocalAgent.kql
// cloud-secure.ai - Defender AI agent runtime protection, Part 7
// Raises an alert when Defender discovers a local AI agent that is not on the approved list.
// AgentsInfo has no DeviceId column - the device and user live in RawAgentInfo.localAgentMetadata.
// Block-all-by-default: anything not in ApprovedAgents alerts.
// Matches on name fragments: "Claude Code" also covers the VS Code Claude extension, "GitHub Copilot" covers CLI and VS Code.
let ApprovedAgents = dynamic(["Claude Code", "Claude Desktop", "GitHub Copilot"]);
AgentsInfo
| where Timestamp > ago(4h)
| where Platform == "LocalAgents"
| where not(Name has_any (ApprovedAgents))
| extend Meta = RawAgentInfo.localAgentMetadata
| extend DeviceId = tostring(Meta.machineId),
DeviceName = tostring(Meta.deviceName),
AccountUpn = tostring(Meta.upn),
AccountSid = tostring(Meta.accountSid),
Vendor = tostring(Meta.vendor)
| summarize arg_max(Timestamp, *) by DeviceId, Name
| project Timestamp, DeviceId, DeviceName, AccountUpn, AccountSid,
AgentName = Name, Vendor, Version, ReportId = tostring(AgentId)
Saved as a custom detection: every hour, High severity, entities mapped to Device (DeviceId) and User (AccountSid). Two gotchas from the rule wizard:
- The alert description takes a maximum of three dynamic columns. Five were rejected with “Too many column names”.
- A new rule queries 30 days on its first run. Without the
ago(4h)filter inside the query, it would alert immediately on old discoveries.

Why one rule was not enough
AgentsInfo is a periodic inventory, not a live feed. In the lab its last report was hours old. And searching process events for “gemini” found nothing, because npm-installed agent CLIs run as node.exe - the agent name only appears in the command line. So I added a near-real-time (NRT) rule on DeviceProcessEvents:
DeviceProcessEvents
| where FileName =~ "node.exe"
| where ProcessCommandLine has "gemini-cli" or ProcessCommandLine has "@openai" or ProcessCommandLine has "qwen-code"
| project Timestamp, DeviceId, DeviceName, AccountName, AccountSid, InitiatingProcessAccountUpn, InitiatingProcessAccountObjectId, ProcessCommandLine, InitiatingProcessFileName, ReportId
The Continuous (NRT) option stayed greyed out until the query was this simple. NRT rules reject let, dynamic(), has_any, column renames and even comments, so the notes live in a README alongside the query in the repo.

Route B, step 2: the device route
The plan: a High alert raises the device risk, Intune marks the device noncompliant, and Conditional Access requires a compliant device.
The connector switch that is easy to miss
Intune only receives Defender’s device risk if, under Endpoint security > Microsoft Defender for Endpoint, Connect Windows devices version 10.0.15063 and above is switched on for compliance policy evaluation. In the lab it was off. With it off, a machine risk score setting silently does nothing. It is tenant-wide, so check the impact before switching it on.

Compliance policy and Conditional Access
A Windows compliance policy requiring a machine risk score at or under Low, marking the device noncompliant immediately. One lesson: I first assigned it to a user group containing edge, and it applied to zero devices. User-targeted compliance follows the device’s primary user, which on this VM is the admin. Compliance is a device state, so it now targets a device group containing only purview.
The Conditional Access policy targets the user: edge only, admin excluded, All resources, grant Require device to be marked as compliant, created in Report-only and then switched on. The Users pane now states that user policies apply when users access resources directly or through agents acting on their behalf - exactly the case for a local agent with no identity of its own. The new All agent resources option is for agent identities and needs Agent 365.

Result: the device route stalled
edge installed Gemini CLI with npm and ran it. The NRT rule fired as High alerts within minutes, and Defender correlated them into one incident. The attack graph tells the story at a glance: the device, the user and the processes that triggered the alerts.

Drilling into the processes node shows why the NRT rule matches on the command line: both are node.exe, launched from edge’s npm folder. Nothing in the process name says Gemini.

But the device risk level did not move: it was still None more than 30 minutes later.

Custom detection alerts did not feed device risk in this lab, so the device never became noncompliant and the compliant-device policy had nothing to act on. If you are planning this route, test it in your own tenant before relying on it.
Route B, step 3: the identity route
Since the agent acts as the user, the user is the better place to apply the control. Custom detections have a response action, Mark user as compromised, which sets the user’s Entra risk to High. Conditional Access can block on that.
The action stays greyed out until the query returns an Entra object ID. Adding InitiatingProcessAccountObjectId to the NRT query and mapping User > AadUserId to it unlocks it.

Then a second Conditional Access policy: edge, admin excluded, condition user risk High, grant Block access.

Result: blocked
edge ran Gemini CLI again. The NRT rule fired, ID Protection showed edge as Confirmed compromised with High risk, and the next sign-in was refused.


What worked, what didn’t
| Link in the chain | Route A (Microsoft native) | Route B (built from E5) |
| Detect the agent | Defender local agent discovery | Scheduled AgentsInfo rule plus NRT process rule - worked |
| Agent identity | Entra Agent ID - needs Agent 365 | Not used; the agent acts as the user |
| Mark it risky | Intune agent compliance setting - not available | Device risk: did not move. User risk via Mark user as compromised: worked |
| Block | Agent CA templates - need Agent 365 | CA user risk High → Block access - worked |
Before you use this in production
- It is a blunt instrument. Marking a user compromised blocks them everywhere, not just the agent. Running an unapproved CLI is a policy breach, not proof of compromise. Scope it to high-sensitivity groups, and have a fast path for an admin to dismiss the risk.
- Keep the approved list current. Anything not on it is treated as unapproved, including a new version that reports a different name.
- Exclude your admins from both policies, and start in Report-only.
- Check the connector switch before trusting any machine risk compliance setting.
Licensing
- Local agent discovery and custom detections: Defender for Endpoint P2.
- Mark user as compromised and user risk in Conditional Access: Entra ID P2 (included in E5).
- Compliance policy and compliant-device Conditional Access: Intune and Entra ID P1.
- Entra Agent ID for local agents, the Intune agent compliance setting and the agent Conditional Access templates: Agent 365 or Microsoft 365 E7.
Next in the series
Next in the series: Part 8 looks at Route A properly - automatic Entra Agent IDs for local agents and the agent Conditional Access templates - and what changes when an agent gets an identity of its own.
The detection queries and the NRT README are in the GitHub repo for this series.
Pingback: Part 6: Microsoft Defender AI agent runtime protection – moving AI agent governance from Defender into Agent 365 | Cloud-Secure.ai