Coding agents get much more useful when they can act on cloud resources directly: provision infrastructure, run experiments, collect results, and iterate. Tasks like benchmarking and system design can then run end-to-end, for instance benchmarking Small Language Models across a range of Azure VM SKUs like in repo az-slm.
Two challenges come up: how to have the agent authenticate without giving it credentials it could leak, and how to limit what it can do. Claude Code answers the first with network secrets: its agent proxy acquires Microsoft Entra access tokens and attaches them to requests to Azure Resource Manager (ARM), so credentials never enter the agent’s sandbox. Azure RBAC and Azure Policy answer the second.
This post covers creating an Entra identity for Claude, sandboxing it, configuring the Claude Code environment, and testing access.
Open a Bash session in Azure Cloud Shell, create a Resource Group for Claude, and create a service principal with the Contributor role on it:
az group create --name <resource-group> --location eastus
az ad sp create-for-rbac --name Claude --role Contributor --scopes /subscriptions/<subscription-id>/resourceGroups/<resource-group>In the command output, note the tenant ID (tenant), client ID (appId), and client secret (password). The secret cannot be retrieved later.
The role assignment confines Claude to the Resource Group: it can create, modify, and delete resources there, but cannot see anything else in the subscription.
Prefer Contributor over Owner unless the agent needs to assign permissions. Both grant full control over the resources in the Resource Group, but Owner also allows granting roles to other identities.
Azure Policy further restricts what Claude can deploy. Built-in policies such as ‘Allowed locations’, ‘Allowed resource types’, and ‘Allowed virtual machine size SKUs’ help keep costs in check. Assign them above the Resource Group, at the subscription or management group level, so Claude cannot remove them. For instance, run the following in Cloud Shell to limit VM sizes to an allow-list across the subscription (cccc23c7-8427-4f53-ad12-b6a63eb452b3 is the ID of the ‘Allowed virtual machine size SKUs’ policy):
az policy assignment create --name allowed-vm-skus --policy cccc23c7-8427-4f53-ad12-b6a63eb452b3 --scope /subscriptions/<subscription-id> --params '{"listOfAllowedSKUs": {"value": ["Standard_B2s", "Standard_D4s_v5"]}}'In the environment menu of a Claude Code session, select ‘New environment’, pick the repo to connect to, and create the environment. Then edit the newly-created environment and add a network secret with the following parameters:
management.azure.comappId from the command output (the application/client ID, not to be confused with the application object ID, both of which are GUIDs)password from the command outputhttps://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token, with tenant from the command outputhttps://management.azure.com/.default
The agent proxy runs the OAuth 2.0 client credentials flow against Entra and adds the resulting access token to requests to management.azure.com after they leave the session’s VM. Neither the client secret nor the tokens enter the sandbox. Hosts with network secrets are reachable regardless of the environment’s network access level, so management.azure.com does not need to be added to the allowed domains.
In ‘Network access’, consider adding learn.microsoft.com to the allowed domains so Claude can read the Azure docs.
In ‘Setup script’, consider installing the Bicep CLI so Claude can author infrastructure as code. Bicep files compile to ARM JSON templates (bicep build), which deploy through the ARM REST API without needing the Azure CLI:
#!/bin/bash
curl -fsSL -o /usr/local/bin/bicep https://github.com/Azure/bicep/releases/download/v0.49.2/bicep-linux-x64
chmod +x /usr/local/bin/bicepIn ‘Environment variables’, consider adding the Azure IDs to keep them out of the code. Environment variables are readable by anyone using the environment, which is fine for IDs but not for secrets:
AZURE_TENANT_ID=<tenant-id>
AZURE_SUBSCRIPTION_ID=<subscription-id>
AZURE_RESOURCE_GROUP=<resource-group>Start a session in the new environment and ask Claude to check its access:
Which Resource Group(s) do you have access to with which roles?
With no Azure login in the session, Claude calls the ARM REST API directly, leaving the Authorization header to the proxy. For instance, listing Resource Groups returns only the sandbox Resource Group:
curl -s "https://management.azure.com/subscriptions/$AZURE_SUBSCRIPTION_ID/resourcegroups?api-version=2021-04-01"Clients that require a token, such as the Azure SDKs, can be given a placeholder, which the proxy overwrites.