Governing AI Agent Dynamic Permissions & Sandboxes in Microsoft Entra ID: Zero Trust Runbook

As enterprise organizations accelerate the deployment of autonomous AI agents, Copilot extensions, and multi-agent workflows, identity systems face an unprecedented security dilemma. Traditional cloud application architectures treat service principals and OAuth apps as static entities: an app is granted high-privilege scopes (like Mail.ReadWrite or Directory.ReadWrite.All), and those permissions remain active 24/7/365.

If an autonomous AI agent is misled by a prompt injection attack or compromised through malicious third-party tool execution, static god-mode permissions grant the attacker immediate tenant-wide blast radius.

To address this emerging threat frontier, Microsoft introduced Dynamic Permissions and Microsoft Execution Containers (MXC) for AI identities in Microsoft Entra ID. In this security architecture runbook, we break down how dynamic permissions operate, how to enforce task-scoped ephemeral scopes, and how to govern AI service principals using the Microsoft Graph PowerShell SDK v2.


Static Permissions vs. Dynamic AI Sandboxing

In legacy app registration models, permissions are granted statically:

  • An AI customer support agent granted User.ReadWrite.All can modify executive account properties even when simply answering a shipping question.
  • An email summarization agent granted Mail.Read can read the entire CEO mailbox history rather than just the specific message thread referenced in the prompt.

Dynamic Permissions fundamentally alter this authorization model:

  1. Ephemeral Scope Elevation: The AI service principal holds zero standing broad permissions. When a user requests a task, the agent requests a short-lived, task-bound authorization token.
  2. Context-Aware Risk Evaluation: If the prompt originates from an untrusted source or involves high-risk parameters, Entra ID denies the dynamic permission request.
  3. Execution Sandboxing (MXC): Code execution and external API calls run within isolated Microsoft Execution Containers, preventing access to the host tenant runtime.
Entra ID Identity Governance: Static App Roles vs. AI Dynamic Permissions Legacy Static AI Service Principals (Hazardous) • Over-Privileged Standing Scopes - Static Directory.ReadWrite.All or Mail.ReadWrite • Prompt Injection Vulnerability - Adversary manipulates model to abuse standing API keys Security Risks: ✖ Uncontrolled blast radius across entire tenant ✖ Zero task-boundary validation Modern Dynamic Permissions & MXC (Zero Trust) • Zero Standing Permissions (ZSP) - Agent starts with baseline identity; no standing data scopes • Just-In-Time Task Scoping - Ephemeral token scoped strictly to current prompt context Governance Controls: ✔ Execution Sandboxing (MXC container isolation) ✔ Auto-revocation upon task completion AI Governance Rule of Thumb: 1. Never grant Application Permissions (App-Only) to conversational AI agents interacting with public inputs. 2. Enforce On-Behalf-Of (OBO) flow and Dynamic Permission consent policies via Microsoft Graph PowerShell.

Step 1: Auditing Existing AI & Service Principal Permissions

Before enforcing dynamic restrictions, audit your tenant for high-privilege service principals used by automated bots:

POWERSHELL
# Connect to Microsoft Graph using Certificate Authentication
$TenantId       = "ab85c7a1-366d-44ba-acc6-924fa0950045"
$ClientId       = "c841ae33-4093-4385-8a90-6a530761f9b9"
$CertThumbprint = "BEAC429DE404B46FF030811C0C9DE00DE701C027"

Connect-MgGraph -TenantId $TenantId -ClientId $ClientId -CertificateThumbprint $CertThumbprint -NoWelcome

# Identify Service Principals with High-Risk Static Scopes
$HighRiskScopes = @("Directory.ReadWrite.All", "RoleManagement.ReadWrite.Directory", "Mail.ReadWrite", "Files.ReadWrite.All")

$ServicePrincipals = Get-MgServicePrincipal -All

$RiskyAgents = foreach ($sp in $ServicePrincipals) {
    $AppRoles = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id
    foreach ($role in $AppRoles) {
        if ($role.ResourceDisplayName -eq "Microsoft Graph") {
            [PSCustomObject]@{
                DisplayName = $sp.DisplayName
                AppId       = $sp.AppId
                ServicePrincipalId = $sp.Id
                AssignedRole = $role.PrincipalDisplayName
            }
        }
    }
}

$RiskyAgents | Format-Table -AutoSize

Step 2: Provisioning an AI Identity with Dynamic Permissions

Using Microsoft Graph PowerShell, register an AI Service Principal configured with Task-Scoped Dynamic Authorization Policies:

POWERSHELL
# Script: New-EntraDynamicAIAgent.ps1
# Description: Registers an AI Agent with zero standing permissions and dynamic execution sandboxing

# 1. Register the Application Definition
$AppParams = @{
    displayName = "AI-Enterprise-Copilot-Agent"
    signInAudience = "AzureADMyOrg"
    description = "Task-Scoped Autonomous Assistant Governed by Entra Dynamic Permissions"
}

$App = New-MgApplication @AppParams
Write-Host "[+] Application registered: $($App.DisplayName) (AppId: $($App.AppId))" -ForegroundColor Green

# 2. Instantiate the Service Principal
$Sp = New-MgServicePrincipal -AppId $App.AppId

# 3. Configure Dynamic Permission Governance Policy (Beta Endpoint)
$DynamicPolicyPayload = @{
    "@odata.type" = "#microsoft.graph.permissionGrantPolicy"
    id            = "Policy-Dynamic-AI-$($App.AppId)"
    displayName   = "Dynamic AI Permission Scoping Policy"
    description   = "Restricts AI agent to task-scoped ephemeral scopes; prevents standing privilege escalation"
    isDefault     = $false
    includes      = @(
        @{
            permissionType = "delegated"
            riskLevel      = "low"
            userPermissionType = "dynamicTaskScoped"
        }
    )
    excludes      = @(
        @{
            permissionType = "application" # Completely blocks god-mode App-Only standing tokens
        }
    )
} | ConvertTo-Json -Depth 5

Write-Host "[+] Enforcing Dynamic Permission Grant Policy..." -ForegroundColor Cyan
Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/beta/policies/permissionGrantPolicies" -Body $DynamicPolicyPayload

Step 3: Enforcing Execution Sandboxing via Conditional Access

To ensure AI workloads cannot access sensitive corporate data from untrusted networks, bind the AI service principal to a dedicated Workload Identity Conditional Access Policy:

POWERSHELL
# Enforce Trusted Location and Compliance Controls on AI Workload Identities
$CaParams = @{
    displayName = "Block-AI-Workload-Untrusted-Networks"
    state       = "enabled"
    conditions  = @{
        clientAppTypes = @("all")
        servicePrincipals = @{
            includeServicePrincipals = @($Sp.Id)
        }
        locations = @{
            includeLocations = @("All")
            excludeLocations = @("AllTrusted") # Only permitted inside verified datacenter / Azure virtual networks
        }
    }
    grantControls = @{
        operator = "OR"
        builtInControls = @("block") # Block untrusted execution
    }
}

New-MgIdentityConditionalAccessPolicy -BodyParameter $CaParams
Write-Host "[✔] Workload Conditional Access policy enforced for AI Agent: $($Sp.DisplayName)" -ForegroundColor Green

Summary Best Practices for AI Governance

  1. Eliminate Standing App-Only Grants: Replace static background daemon permissions with Dynamic Delegated On-Behalf-Of (OBO) tokens.
  2. Isolate Runtime Containers: Ensure custom agents run within sandboxed runtimes (MXC) with network egress controls.
  3. Audit Workload Sign-Ins: Stream ServicePrincipalSignInLogs to Microsoft Sentinel. Configure detection rules for anomalous token generation spikes or attempts to query unauthorized Microsoft Graph endpoints.