Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
By using Azure Agent Grid, each serverless sandbox in Azure Container Instances that you enroll in a grid gets a SPIFFE workload identity, and the system denies outbound traffic from the sandbox by default unless a policy group that's bound to the grid allows it. You can apply default policies to all sandboxes in the grid and add policies for individual sandboxes while they run.
In this tutorial, you associate an AI agents group with an Agent Grid resource (Microsoft.NetworkSecurity/agentFabrics), apply a default policy that allows *.bing.com for all grid members, verify that other destinations are blocked, and then add a policy that allows *.google.com for one sandbox's SPIFFE identity.
In this tutorial, you learn how to:
- Create a default outbound policy group and bind it to an Agent Grid
- Create an AI agents group associated with the Agent Grid
- Create a sandbox enrolled in the Agent Grid and test outbound rules
- Get the sandbox's SPIFFE identity and apply a per-sandbox policy
Prerequisites
An Azure subscription. If you don't have an Azure subscription, create a free account before you begin.
The Azure CLI, version 2.60 or later, signed in with
az login, or another tool to send authenticated REST requests to Azure Resource Manager.The
Microsoft.ContainerInstanceresource provider registered in your subscription.az provider register --namespace Microsoft.ContainerInstance --waitThe Contributor, Azure Deployment Stack Owner, and Storage Blob Data Contributor roles assigned to the Compute Sandbox Groups service principal on your subscription, so that the service can provision the managed resource group and snapshot storage account in your subscription. To assign the roles, you need permission to create role assignments on the subscription, such as the Owner or User Access Administrator role:
subscriptionId=$(az account show --query id --output tsv) spObjectId=$(az ad sp show --id 1eeacc2b-ec4a-4b1e-977a-2b5fef2131c6 --query id --output tsv 2>/dev/null || \ az ad sp create --id 1eeacc2b-ec4a-4b1e-977a-2b5fef2131c6 --query id --output tsv) for role in "Contributor" "Azure Deployment Stack Owner" "Storage Blob Data Contributor"; do az role assignment create --assignee-object-id $spObjectId --assignee-principal-type ServicePrincipal \ --role "$role" --scope /subscriptions/$subscriptionId doneRole assignments can take up to 15 minutes to take effect.
Quota provisioned for serverless sandboxes in Azure Container Instances on your subscription:
Open New support request in the Azure portal (with Issue type set to Service and subscription limits (quotas) and Quota type set to Container Instances), select your subscription, and go to the Additional details tab.
Select Enter details to open the Quota details pane, choose your Location, select AIAgentsGroups - StandardCores (Preview) for Quota type, and fill in Networking type, Container Type, Total AIAgentsGroups Group Limit, and Total AIAgentsGroups Core Limit:
Submit the support request. After your quota request is approved, re-register the
Microsoft.ContainerInstanceresource provider (az provider register --namespace Microsoft.ContainerInstance --wait) so that your subscription picks up the newly enabled capabilities.
To connect to a running sandbox after you create an AI agents group and a sandbox (see Quickstart: Create your first serverless sandbox), a gRPC client generated from the sandbox gateway protobuf file,
sandboxgateway.proto. A gRPC client is required because the sandbox gateway exposes a gRPC service (aci.sandboxgateway.SandboxGatewayService) for in-sandbox operations such as waiting for readiness, running commands, transferring files, and reading logs. To use the cross-platform sample C# CLI in this documentation (supported on Linux, macOS, and Windows), install the .NET 8 SDK and build the CLI.Note
A gRPC client isn't required if you schedule and manage serverless sandboxes through Azure Kubernetes Service (AKS).
- An Azure Agent Grid resource (
Microsoft.NetworkSecurity/agentFabrics) in the same subscription and region where you create your AI agents group, in a region where Agent Grid is available. For supported regions, see Agent Grid region availability.
Apply a default outbound policy to the Agent Grid
Policy groups (Microsoft.NetworkSecurity/policyGroups) define FqdnFiltering rules that match source SPIFFE workload identity patterns and allow outbound traffic to specified FQDNs and ports. The wildcard pattern spiffe://microsoft.agentfabric/ns/*/sa/* matches all sandboxes in the grid.
Create a default policy group that allows outbound traffic on ports
80and443to*.bing.comfor all grid members:PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.NetworkSecurity/policyGroups/default-egress-policy?api-version=2026-07-21-preview Content-Type: application/json { "location": "centralus", "properties": { "displayName": "Default corporate egress", "description": "Allow Bing subdomains for all current and future grid members.", "priority": 100, "networkSecurityPolicies": [ { "type": "FqdnFiltering", "name": "allow-approved-corporate-egress", "priority": 10, "direction": "Outbound", "ports": [80, 443], "source": { "type": "WorkloadIdPatterns", "patterns": [ "spiffe://microsoft.agentfabric/ns/*/sa/*" ] }, "destination": { "type": "Fqdns", "fqdns": [ "*.bing.com" ] } } ] } }Bind the policy group to your Agent Grid resource in
properties.defaultPolicyGroups:PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.NetworkSecurity/agentFabrics/myAgentGrid?api-version=2026-07-21-preview Content-Type: application/json { "location": "centralus", "properties": { "defaultPolicyGroups": [ "/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.NetworkSecurity/policyGroups/default-egress-policy" ] } }
Create an AI agents group associated with the Agent Grid
Create an AI agents group with
properties.agentFabricResourceIdset to the resource ID of the Agent Grid resource. You must setagentFabricResourceIdwhen you create the group, and you can't combine it withnetworkProfile:PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/AIAgentsGroups/myGridAgentsGroup?api-version=2026-08-01-preview Content-Type: application/json { "location": "centralus", "properties": { "agentFabricResourceId": "/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.NetworkSecurity/agentFabrics/myAgentGrid" } }Check the AI agents group until
properties.provisioningStateisSucceeded, and then callconnectto get its{endpoint}and{accessToken}:GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/AIAgentsGroups/myGridAgentsGroup?api-version=2026-08-01-previewPOST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/AIAgentsGroups/myGridAgentsGroup/connect?api-version=2026-08-01-preview
Create a sandbox enrolled in the Agent Grid
Create a sandbox in the AI agents group with properties.attachToAgentFabric set to true. Sandboxes that you create without it don't join the grid, and you can't change attachToAgentFabric from true to false after creation or combine it with confidential sandboxes:
PUT {endpoint}/sandboxes/grid-sandbox1?api-version=2026-08-01-preview
Authorization: Bearer {accessToken}
Content-Type: application/json
{
"location": "centralus",
"properties": {
"image": "mcr.microsoft.com/mirror/docker/library/alpine:3.16",
"attachToAgentFabric": true,
"resources": {
"cpu": 1,
"memory": 2
}
}
}
Wait until properties.provisioningState is Succeeded. Then copy properties.connectionString from the response, and wait until the guest is ready (WaitForReady). By using the sample C# CLI:
dotnet run -- -cs "<grid-sandbox1-connection-string>" wait
Verify the default outbound policy
From inside grid-sandbox1, test outbound HTTP requests to www.bing.com, www.google.com, and example.com. Use the sample C# CLI:
dotnet run -- -cs "<grid-sandbox1-connection-string>" exec /bin/sh -c '
for url in http://www.bing.com http://www.google.com http://example.com; do
out=$(if command -v curl >/dev/null 2>&1; then curl -sSD - -o /dev/null --max-time 15 "$url" 2>&1; else wget -S -O /dev/null -T 15 -t 1 "$url" 2>&1; fi)
code=$(printf "%s\n" "$out" | sed -n "s/^[[:space:]]*HTTP\/[^[:space:]]*[[:space:]]*\([0-9][0-9][0-9]\).*/\1/p" | head -n 1)
echo "$url -> HTTP ${code:-BLOCKED}"
done'
Because only *.bing.com is allowed by the default policy group, the request to www.bing.com succeeds with an HTTP 200 status code, while requests to www.google.com and example.com are blocked:
http://www.bing.com -> HTTP 200
http://www.google.com -> HTTP BLOCKED
http://example.com -> HTTP BLOCKED
Apply a per-sandbox policy by using the sandbox's SPIFFE ID
When a sandbox attaches to an Agent Grid, the grid registers it as a member and assigns it a unique SPIFFE workload identity (properties.spiffeId). You can target that exact SPIFFE ID in a policy group so that only that sandbox can reach extra destinations.
List the members of the Agent Grid resource and find the entry where
properties.workload.typeisACI,properties.workload.workloadIdisgrid-sandbox1, andproperties.workload.resourceIdis the AI agents group resource ID:GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.NetworkSecurity/agentFabrics/myAgentGrid/members?api-version=2026-07-21-previewCopy the
properties.spiffeIdvalue forgrid-sandbox1from the response (for example,spiffe://microsoft.agentfabric/ns/<namespace>/sa/<service-account>).Create a policy group that allows
*.google.comonly for that sandbox'sspiffeId:PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.NetworkSecurity/policyGroups/agent-specific-egress-policy?api-version=2026-07-21-preview Content-Type: application/json { "location": "centralus", "properties": { "displayName": "Agent-specific Google egress", "description": "Allow this sandbox member to access Google subdomains.", "priority": 90, "networkSecurityPolicies": [ { "type": "FqdnFiltering", "name": "allow-google-egress", "priority": 10, "direction": "Outbound", "ports": [80, 443], "source": { "type": "WorkloadIdPatterns", "patterns": [ "<sandbox-spiffe-id>" ] }, "destination": { "type": "Fqdns", "fqdns": [ "*.google.com" ] } } ] } }Bind the new policy group alongside the default policy group on the Agent Grid resource:
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.NetworkSecurity/agentFabrics/myAgentGrid?api-version=2026-07-21-preview Content-Type: application/json { "location": "centralus", "properties": { "defaultPolicyGroups": [ "/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.NetworkSecurity/policyGroups/default-egress-policy", "/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.NetworkSecurity/policyGroups/agent-specific-egress-policy" ] } }After the policy update propagates (which can take a few minutes), run the outbound test again inside the running sandbox without restarting or re-creating it. Use the sample C# CLI:
dotnet run -- -cs "<grid-sandbox1-connection-string>" exec /bin/sh -c ' for url in http://www.bing.com http://www.google.com http://example.com; do out=$(if command -v curl >/dev/null 2>&1; then curl -sSD - -o /dev/null --max-time 15 "$url" 2>&1; else wget -S -O /dev/null -T 15 -t 1 "$url" 2>&1; fi) code=$(printf "%s\n" "$out" | sed -n "s/^[[:space:]]*HTTP\/[^[:space:]]*[[:space:]]*\([0-9][0-9][0-9]\).*/\1/p" | head -n 1) echo "$url -> HTTP ${code:-BLOCKED}" done'Now both
www.bing.comandwww.google.comare allowed forgrid-sandbox1, whileexample.comremains blocked:http://www.bing.com -> HTTP 200 http://www.google.com -> HTTP 200 http://example.com -> HTTP BLOCKED
Clean up resources
Delete the sandbox, or delete the AI agents group if you no longer need it:
DELETE {endpoint}/sandboxes/grid-sandbox1?api-version=2026-08-01-preview
Authorization: Bearer {accessToken}
DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/AIAgentsGroups/myGridAgentsGroup?api-version=2026-08-01-preview
For more information about configuring policies, TLS inspection, MCP policies, and flow logs in the Azure portal, see Configure Azure Agent Grid.