The practical question about Microsoft Agent 365 is whether it only governs agents built inside Copilot Studio, or whether it can govern code-first agents built with open-source frameworks running in your own containers.
The short answer is yes, as long as you attach controls to the protocol boundaries instead of trying to rewrite every agent runtime around a vendor SDK. In production, I run the open-source Python Hermes Agent across Linux and WSL2 containers alongside a managed Windows 11 endpoint. Every agent identity, tool call, telemetry trace, and customer-facing draft passes through Microsoft Entra Agent ID, Microsoft Agent 365, Global Secure Access (GSA), Microsoft Defender, and Microsoft Purview.
Onboarding code-first agents built outside Microsoft SDKs#
Microsoft Agent 365 does not require Copilot Studio or a Microsoft agent SDK: you onboard any Python, Node, or Go agent as a first-class enterprise workload by wiring three Entra and Microsoft Graph primitives together.
Three objects turn a code-first runtime into a governed enterprise agent#
No Copilot Studio or vendor agent SDK required. Wire the blueprint, issue an identity per trust boundary, and publish one converged registration record.
Agent Identity Blueprint#
Reusable template & credential root
#microsoft.graph.agentIdentityBlueprintHolds the X.509 Federated Identity (FMI) credential and declares inheritable permissions shared across agent instances.
Tools.ListInvoke.AllAgent365.Observability.OtelWriteConnectivity.Connections.Read
Agent Identity#
Per-boundary workload identity
#microsoft.graph.agentIdentityConcrete workload identity issued per trust boundary, separating internal operations, customer-facing studio work, and fleet orchestration.
Scoped per trust boundaryConditional Access targetZero shared static secrets
Converged Agent Registration#
Unified M365 & Defender registry record
/beta/copilot/agentRegistrations/{id}Surfaces each agent in M365 Admin Center (Agents > Registry) and correlates OpenTelemetry spans in Defender (Assets > AI agents). Replaces /beta/agentRegistry/agentInstances.
M365 Admin Center inventoryDefender AI asset correlationReplaces retired agentInstances API
One prerequisite trips up early pilots: identity hygiene. Global Secure Access clients and On-Behalf-Of (OBO) app registrations reject personal Microsoft accounts and external B2B guests. Licensing active native organizational members keeps token flows clean while upstream SaaS accounts (email, CRM, design tools) stay completely decoupled at the gateway layer.
The map below shows how the containerized runtimes, managed Windows endpoint, self-hosted control plane, and Microsoft security plane fit together. Notice two boundaries right away: Linux containers hold zero Entra tenant credentials, and one OpenTelemetry collector feeds both local storage and Microsoft Agent 365.
End-to-end control plane for code-first agents#
Open-source agents keep zero tenant credentials inside the container. Identity exchange, MCP guardrails, and dual-pipeline telemetry run at the protocol boundary.
WSL2 and Linux Docker Agents#
- Hermes Agent (Open-Source SDK)
Holds zero Entra tenant credentials. Sends HTTPS MCP calls with a revocable virtual key and emits gen_ai.* OTel spans.
- Isolated Headless Browser Sidecar
Restricts container outbound egress at the kernel level so browser automation cannot bypass the gateway.
Windows 11 Endpoint (thornet-win11-01)#
- Native Windows Endpoint
Provides hardware-backed device identity, native MDE local AI agent discovery, and non-interactive GSA tunnel acquisition.
Control Plane (poplar-srv-ops-01)#
- LiteLLM MCP Gateway
Enforces per-key tool scoping, deterministic PII and injection inspection, and fail-open Defender pre_mcp_call evaluation.
- OpenTelemetry Collector (OTLP/HTTP)
Receives gen_ai.* spans from Hermes and LiteLLM, then fans out simultaneously to local storage and Microsoft Agent 365.
- Pipeline A: Arize Phoenix
Retains full trace history locally so tenant rotations or cloud outages never create telemetry blind spots.
- Pipeline B: X.509 FMI S2S Forwarder
Uses an OpenBao-managed X.509 blueprint assertion to mint identity-scoped OTLP write tokens out of band.
Agent 365, Entra, Defender, and Purview#
- Entra Agent ID + Conditional Access
Issues workload identities and enforces Conditional Access via includeAgentIdServicePrincipals.
- Global Secure Access MCP Firewall
Inspects decrypted Streamable HTTP/SSE JSON-RPC traffic on managed endpoints and forwards approved traffic to the gateway.
- Defender & Agent 365 Observability
Correlates runtime OTel spans across Defender, Sentinel, and Purview, and returns inline pre-tool threat verdicts.
- M365 Admin Center & Purview
Centralizes agent and MCP server inventory, Communication Compliance, sensitivity labels, and DLP auditing.
Primary request and telemetry paths#
- Container MCP Path
Hermes Agent -> LiteLLM MCP Gateway - Caller presents its scoped virtual key over HTTPS; Layer 1 iptables blocks direct egress around the gateway.
- Endpoint MCP Path
Windows 11 -> GSA MCP Firewall -> LiteLLM MCP Gateway - GSA tunnels and TLS-inspects covered traffic, enforces wire-level tool blocks, and forwards approved requests to the gateway.
- Dual-Pipeline Telemetry
Hermes + LiteLLM -> OTel Collector -> Phoenix + FMI Forwarder -> Agent 365 - One gen_ai.* instrumentation feeds permanent local traces and identity-attributed Microsoft Defender, Sentinel, and Purview sinks.
- Inline Threat Check & Inventory
LiteLLM <-> Defender pre_mcp_call (fail_open) & M365 Admin Center Gateway Connector - Delegated OBO evaluation checks pending tool arguments before execution; least-privilege proxy_admin syncs server inventory.
Mermaid flowchart source
flowchart LR
subgraph WS["Containerized Agent Runtime (WSL2 / Linux Docker)"]
H["Hermes Agent (Open-Source SDK)\n7 Role Profiles · OTLP Export · Virtual Key Auth"]
B["Isolated Headless Browser Sidecar\nLoopback CDP · Layer 1 iptables Egress Lock"]
end
subgraph WIN["Managed Windows 11 Endpoint (thornet-win11-01)"]
W["Native Windows Endpoint\nEntra Joined · MDE Plan 2 · GSA Client"]
end
subgraph CP["Self-Hosted AI Control Plane (poplar-srv-ops-01)"]
GW["LiteLLM MCP Gateway\nLayer 2 Guardrails + Microsoft Agent 365 pre_mcp_call"]
OT["OpenTelemetry Collector (OTLP/HTTP)"]
PH["Pipeline A: Arize Phoenix\nPermanent Local System of Record"]
FW["Pipeline B: X.509 FMI S2S Forwarder\n2-Leg Entra Agent ID Token Exchange"]
end
subgraph MS["Microsoft Security & Agent 365 Plane (ThorNet Tenant)"]
EA["Entra Agent ID + Conditional Access\nBlueprints · Agent Identities · CA for Agent IDs"]
GSA["Global Secure Access MCP Firewall\nTLS Inspection + Per-Tool Allow/Block"]
DEF["Defender & Agent 365 Observability\nflashpoint · sentinel · esp · pre_mcp_call"]
MAC["M365 Admin Center\nAgents > Registry · Tools · Gateways"]
PRV["Microsoft Purview\nDSPM for AI · DLP · Communication Compliance"]
end
H -->|HTTPS MCP + Scoped Key| GW
W -->|GSA Tunnel + TLS Inspect| GSA
GSA -->|Forwards approved MCP traffic| GW
H -->|gen_ai.* OTLP| OT
GW -->|gen_ai.* OTLP| OT
OT --> PH
OT --> FW -->|2-Leg FMI Token| DEF
GW -.->|OBO pre_mcp_call fail_open| DEF
GW <-->|Gateway Connector| MAC
EA --- DEF
DEF --- PRVVerified live across Linux/WSL2 containers, a managed Entra-joined Windows 11 endpoint, a self-hosted LiteLLM and OTel control plane, and the ThorNet Microsoft 365 tenant.
Containerized agent identity: managed identity vs. brokered sidecars#
Use Managed Identity or Entra Join where the host supports it, and use an out-of-band brokered sidecar for on-premises Linux Docker and WSL2 containers where Azure Instance Metadata Service (IMDS) does not exist. Dropping a long-lived Entra client secret into a container environment variable is an unacceptable shortcut because a single prompt injection or shell escape hands an attacker tenant-wide credentials.
The cleaner design splits runtime tool access from Entra token exchange:
- Scoped virtual keys inside the container: Each containerized agent holds only a revocable MCP gateway key limited to its approved tools. Its companion headless browser runs as an isolated sidecar over loopback Chrome DevTools Protocol (CDP) behind a Layer 1
iptablesegress lock so browser traffic cannot walk around the gateway. - Out-of-band 2-leg X.509 FMI exchange: A dedicated forwarder on the control plane reads an X.509 certificate from OpenBao for the blueprint, then runs a 2-leg Entra Agent ID
fmi_pathexchange to mint identity-scoped tokens for the Agent 365 Observability Service (9b975845-388f-4429-889e-eab1ef63949c/.defaultwithAgent365.Observability.OtelWrite). - Hardware-backed identity on managed endpoints: On managed Windows 11 endpoints, Microsoft Entra Join (
AzureAdPrt: YES) provides TPM 2.0 device identity and non-interactive GSA tunnel token acquisition with zero static keys.
# 2-Leg Entra Agent ID FMI Token Exchange (Sanitized Excerpt)
# Leg 1: Blueprint X.509 client_assertion -> FMI assertion for target agentIdentity
# Leg 2: Exchange FMI assertion for Agent 365 Observability OTLP write token
OBSERVABILITY_SCOPE = "9b975845-388f-4429-889e-eab1ef63949c/.default"
OTLP_TARGET = (
"https://agent365.svc.cloud.microsoft/observabilityService/"
"tenants/{tenant_id}/otlp/agents/{agent_identity_sp_id}/traces?api-version=1"
)
Keeping the X.509 private key outside the container cuts blast radius immediately. Even a fully compromised agent container cannot extract a blueprint key or mint tokens for another agent identity.
What telemetry and control Agent 365 has after registration#
Once registered, Agent 365 gives your security team end-to-end OpenTelemetry traces across every agent invocation and tool call, paired with three active enforcement planes: Entra Conditional Access for Agent IDs, wire-level GSA MCP filtering, and inline Defender pre-call inspection.
SDK- and framework-agnostic governance via MCP and OpenTelemetry#
You get that telemetry and control without tying governance to a vendor SDK or rewriting agents when teams switch from Hermes Agent to LangGraph, CrewAI, or Claude Code. Standardizing two open protocol boundaries solves framework churn permanently: Model Context Protocol (MCP) for every tool call and OpenTelemetry (gen_ai.*) for every trace (invoke_agent, chat, execute_tool, gen_ai.agent.id, gen_ai.tool.name, and security.guardrail.verdict). Switch between the two scenarios below to watch how a single tool call travels through the control plane, branches between ALLOW and BLOCK, and fires dual telemetry spans to both Arize Phoenix and Microsoft Agent 365.
Watch a single tool call cross the control plane#
Every tool call enters the same gateway. Benign requests pass inline checks and reach the connector; risky arguments stop before dispatch while both telemetry sinks record the verdict.
Switch between Benign call and PII or injection to see where enforcement stops execution without losing telemetry in either sink.
Three active enforcement planes back up what you just saw:
- Identity control: Conditional Access for Agent IDs (
/beta/identity/conditionalAccess/policies) targets workload identities throughconditions.clientApplications.includeAgentIdServicePrincipals. StandardincludeServicePrincipalsrules do not match Entra Agent Identity workloads. - Layer 1 wire control: The GSA MCP Firewall runs default-block with TLS inspection, an explicit allowlist of approved MCP servers, and per-tool blocks on decrypted Streamable HTTP and SSE JSON-RPC
tools/calltraffic. - Layer 2 gateway control with fail-open resilience: The LiteLLM MCP Gateway enforces per-key tool scoping (
object_permission), inline Microsoft Defenderpre_mcp_callchecks (ThreatProtection.Evaluate.Allvia delegated OBO JWT), and deterministic local guardrails (default_on: true). Settingmicrosoft-agent-365tounreachable_fallback: fail_openguarantees a tenant rotation or transient cloud outage never halts production workflows. In our live drill (--disable-a365), the production call returnedHTTP 200, Arize Phoenix recorded the full trace locally, and the forwarder loggedfail_open_drops: 1.
# LiteLLM Dual-Guardrail Configuration (Sanitized Excerpt)
guardrails:
- guardrail_name: "layer2-mcp-guard"
litellm_params:
guardrail: layer2_guardrail.ThorNetLayer2McpGuardrail
mode: ["pre_call", "pre_mcp_call"]
default_on: true
- guardrail_name: "microsoft-agent-365"
litellm_params:
guardrail: agent_365
mode: pre_mcp_call
default_on: false
unreachable_fallback: fail_open
tenant_id: os.environ/AGENT365_TENANT_ID
client_id: os.environ/AGENT365_CLIENT_ID
client_secret: os.environ/AGENT365_CLIENT_SECRET
Stopping bad decisions and PII exfiltration inside legitimate permissions#
Valid identity permissions alone cannot stop an agent from making a bad decision inside its allowed scope, such as running a bulk contact export or copying CRM PII into an external social-drafting connector after reading a poisoned email. Because prompt instructions will not hold that line, we stop both failure modes at execution time with four deterministic barriers:
- Least-privilege key splitting: High-trust internal CRM read keys stay isolated from external publishing keys through
object_permission. Calling a tool outside a key’s realm returnsError: User not allowed to call this toolin both directions. - Hard bulk-export block on two layers: High-risk tools such as
export_all_client_contactsare blocked both on the wire in the GSA MCP Firewall and inside the Layer 2 gateway before execution begins. - Deterministic PII and injection inspection: Before any external or customer-facing tool (
social,publish,post,email,webhook,draft_listing) runs, the gateway inspects arguments for Social Security Numbers, payment card numbers, bulk emails, email-plus-phone pairs, and prompt-injection markers (ignore all previous instructions,id_rsa,webhook.site). - Redacted security spans into Purview and Defender: Every blocked call stops pre-execution and emits a redacted OTel span (
security.guardrail.verdict=Blocked) so Defender, Sentinel, Purview DSPM for AI, and local Phoenix record the exact policy trigger without storing raw sensitive values.
Run through the three live gateway scenarios below to watch the command go in and the guardrail respond.
See the command go in and the guardrail respond#
Toggle between a benign listing draft, a synthetic SSN leak, and a prompt-injected bulk export to watch how the MCP gateway decides before an external tool ever runs.
mcp-call draft_listing_social_copy --neighborhood "Highland Creek" --beds 4[gateway] key_scope=external_publishing defender_pre_mcp_call=PASS layer2_pii=CLEAN
[verdict] HTTP 200 OK · ALLOWED · compliance="fair_housing_checked"
[tool] draft_listing_social_copy -> isError: false (draft queued for human approval)
[otel] trace_id=9f3a...c201 -> phoenix=stored · agent365=200 ok (flashpoint, sentinel, esp)Sanitized replay of verified runtime tests run on 2026-11-29. All PII strings are synthetic test fixtures; zero real client records were used.
The external-connector PII check is intentionally deterministic and small enough to audit in one screen:
# Deterministic PII Exfiltration Guard on External Connectors (Sanitized Excerpt)
EXTERNAL_CONNECTOR_HINTS = (
"social", "publish", "post", "email", "mail",
"send", "webhook", "slack", "discord", "sms", "draft_listing",
)
PII_PATTERNS = [
("pii_ssn", re.compile(r"\b\d{3}-\d{2}-\d{4}\b")),
("pii_card", re.compile(r"\b(?:4\d{3}|5[1-5]\d{2}|3[47]\d{2})[- ]?\d{4}[- ]?\d{4}[- ]?\d{3,4}\b")),
("pii_bulk_email", re.compile(r"(?:[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}.*){2,}", re.DOTALL)),
("pii_phone_plus_email", re.compile(
r"(?=[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}).*(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}",
re.DOTALL,
)),
]
Those controls are backed by live telemetry verified on November 29, 2026: 15,813 spans across 827 traces stored permanently in local Arize Phoenix, and 13,434 spans forwarded with 0 rejections (HTTP 200, status: ok) across all three Microsoft Agent 365 downstream sinks (flashpoint for Defender, sentinel for Sentinel, and esp for Purview).
Dual-pipeline volume and runtime enforcement proof#
Real production telemetry shows both halves of the design working together: zero rejected spans into Microsoft Agent 365 and deterministic pre-execution blocks when synthetic PII hits an external tool.
Verified runtime tests#
render_runtime.py --disable-a365Production call succeeded while Agent 365 was disabled. Local Phoenix recorded the trace; forwarder logged fail_open_drops: 1.
draft_listing_social_copy ("Highland Creek", 4 beds)Passed deterministic Layer 2 guardrail and returned isError: false with Fair Housing verification.
"Highland Creek buyer SSN 123-45-6789"Rejected pre-execution by layer2_guardrail.py. Emitted redacted OTel span with security.guardrail.verdict=Blocked.
"Contact jane.doe@example.com or 704-555-0199"Blocked before external connector dispatch and recorded as a redacted security span in Phoenix and Agent 365.
Counts and verdicts captured live on 2026-11-29 from the ThorNet control plane. All PII test inputs are synthetic fixtures; zero real client data was used.
Registering, controlling, and monitoring MCP servers and tools#
Every MCP server and tool must be explicitly registered, scoped to least-privilege permissions, and bound behind a default-deny network profile so shadow MCP servers cannot bypass governance. Microsoft 365 Admin Center closes that loop through two registration paths:
- Direct external MCP servers (
Agents > Tools): Register approved vendor MCP servers directly, grantTools.ListInvoke.Allon the blueprint’sinheritablePermissions, and approve them in M365 Admin Center so zero unapproved servers sit in pending state. - Connected MCP gateway (
Agents > Settings > Gateways): Register the self-hosted gateway using a least-privilegeproxy_adminkey instead of a master key. At the public HTTPS reverse proxy, expose only/v1/models,/v1/mcp/*,/mcp-rest/*, and/mcp, returning403on/ui,/openapi.json,/key/generate,/user, and raw LLM chat routes. Bind that inventory to managed endpoints through a default-deny GSA security profile enforced by Conditional Access.
AI communications oversight and protected customer-facing outputs#
To govern customer-facing outputs in regulated work such as real estate, separate autonomous drafting from external publishing and enforce Purview oversight, Fair Housing screening, and a human approval gate before anything leaves the tenant:
- Purview Communication Compliance and DSPM for AI: Audit prompts and responses flowing through Microsoft 365 and the
esptelemetry sink for regulatory issues, missing disclosures, and sensitive matches. - Protected outputs and pre-publish screening: Pair Purview sensitivity labels and DLP rules with deterministic pre-publish checks such as Fair Housing vocabulary screening (
compliance: "fair_housing_checked"). - Human approval gate: Let agents draft autonomously inside governed guardrails, but require an explicit human approval step before any social post, message, or client email crosses the external boundary.
- Single audit chain: Share one correlated
gen_ai.*trace ID across Arize Phoenix, Defender, Sentinel, and Purview so compliance reviewers can trace any output back to the exact tool call and policy check.
The matrix below maps each failure mode to the exact identity, wire, gateway, and telemetry control that stops it.
Where each governance layer stops a real failure mode#
No single control covers identity, wire transport, tool arguments, and customer-facing output. Stacking these four planes closes the gaps between them.
Scroll horizontally to compare all four control planes. Keyboard: focus the table region and use the arrow keys.
| Failure mode | Identity & Registry | Layer 1: Network / Wire | Layer 2: Gateway / Guardrail | Telemetry & Oversight |
|---|---|---|---|---|
| Credential theft from container escape or prompt injection | Entra Agent ID Blueprint + 2-Leg X.509 FMI exchange in out-of-band forwarder | Layer 1 iptables egress lock on Linux container and sidecar | Container holds only a scoped, revocable LiteLLM virtual key | FMI forwarder mints per-agent OTLP tokens; zero tenant secrets in runtime |
| Cross-domain tool misuse (confused deputy within valid access) | Conditional Access for Agent IDs (includeAgentIdServicePrincipals) | GSA MCP Firewall inspects decrypted Streamable HTTP/SSE JSON-RPC | LiteLLM object_permission isolates virtual keys across realms + Defender pre_mcp_call | Blocked calls emit security.guardrail.verdict=Blocked to Phoenix and Agent 365 |
| PII exfiltration from internal CRM to external connector | Split agent profiles: internal CRM read key separate from external publishing key | GSA MCP Firewall blocks export_all_client_contacts on the wire | layer2_guardrail.py blocks SSNs, payment cards, bulk emails, and email+phone pairs | Redacted security spans flow to Defender, Sentinel, and Purview DSPM for AI |
| Unauthorized MCP server or shadow tool invocation | 7 BYO MCP servers approved in M365 Admin Center with Tools.ListInvoke.All | AI Endpoint Security Profile (priority 300): web allowlist + TLS inspect + default block | LiteLLM registered via least-privilege proxy_admin key; /ui and /key/generate return 403 | M365 Admin Center auto-discovers gateway servers; GSA logs traffic centrally |
| Non-compliant customer-facing copy (Fair Housing, disclosures) | Native organizational UPNs separate from vendor publishing accounts | Outbound publishing endpoints constrained by approved connector routes | Pre-publish compliance checks + hard human approval gate separating draft from send | Purview Communication Compliance, sensitivity labels, DLP, and correlated gen_ai.* trace IDs |
Mapped directly from verified production controls in the ThorNet tenant. Every row pairs at least one preventative gate with an independent audit trail.
What this architecture proves#
Governing code-first AI agents does not require abandoning open-source runtimes or waiting for every framework to ship native vendor plugins. Register the workload cleanly in Entra Agent ID, keep tenant secrets out of containers through an out-of-band FMI forwarder, enforce policy on the MCP wire and gateway boundary, and dual-write OpenTelemetry to both local storage and Microsoft Agent 365. When every tool call, blocked argument, and customer-facing draft hits those boundaries, your security posture holds across whatever agent framework your teams adopt next.