# Microsoft Foundry hosted agents

Create the Foundry project and the service principal that let Sandcovery run hosted agent sessions in your own Azure subscription.

Sandcovery runs each sandbox as a hosted agent session in a Foundry project of yours, through a service principal whose only role is Foundry User on that one project. It deploys its own agent there, one Python file on the standard library, as the agents `sandcovery-1x2` and `sandcovery-2x4`, and the agent runs every command, file read, file write, and listing in the session. Sandcovery wrote this adapter from Microsoft's [hosted agent docs](https://learn.microsoft.com/en-us/azure/foundry/agents/concepts/hosted-agents) and has not run it against Azure.

## What runs

| Option           | Support                                  |
| ---------------- | ---------------------------------------- |
| Size             | `1x2` and `2x4`                          |
| Egress           | `allow_all`                              |
| Lifetime         | Until the sandbox's TTL, at most 4 hours |
| Pause and resume | No                                       |
| Region           | The region of your Foundry resource      |

Snapshots, port previews, custom images, environment variables set at create, idle timeouts, disk sizes, and GPUs are not available on this provider. A create that asks for another size, an egress limit, or a longer TTL routes to another provider.

## Create the project

In the [Foundry portal](https://ai.azure.com/), create a Foundry resource and a project for Sandcovery in a region that runs [hosted agents](https://learn.microsoft.com/en-us/azure/foundry/agents/concepts/hosted-agents#region-availability), such as East US. Keep that project free of model deployments and connections: each session runs as the agent identity Foundry assigns, which can call model inference in its own project, so code in a sandbox can call it too.

## Create the service principal

Create a service principal whose only role is Foundry User, scoped to that project:

```sh
az ad sp create-for-rbac --name sandcovery \
  --role 53ca6127-db72-4b80-b1b0-d745d6d5456d \
  --scopes "/subscriptions/<subscription ID>/resourceGroups/<resource group>/providers/Microsoft.CognitiveServices/accounts/<resource>/projects/<project>"
```

`53ca6127-db72-4b80-b1b0-d745d6d5456d` is the ID of the Foundry User role, formerly Azure AI User. The command prints the service principal's `appId`, `password`, and `tenant`. Role assignments can take up to a minute to apply.

## Add the credential

In **Provider Credentials** in the [dashboard](/app/credentials), add these six fields for Microsoft Foundry hosted agents:

- Directory (tenant) ID: `tenant`
- Application (client) ID: `appId`
- Client secret: `password`
- Foundry resource name: the resource name, which its endpoint `https://<resource>.services.ai.azure.com` starts with
- Foundry project name: the project name
- Region: the resource's region, such as `eastus`

## Costs

Microsoft bills the vCPU and memory of each active session to your Azure subscription. Sandcovery's estimates and spend limits count them at the East US [list price](/providers/foundry) of hosted agents.
