Skip to main content
This article describes the isolation-key model, which applies to hosted agents on container protocol version 1.0.0. Protocol 1.0.0 is deprecated. For the current model - where the platform isolates each user’s sessions automatically - see Isolate hosted agent sessions per user.
You can configure Microsoft Foundry agents for header-based isolation. Each session, conversation, file, and log query must include one or more isolation header values. You learn what each azd isolation flag does and how to pass the keys through every azd ai agent subcommand that talks to a session.

Prerequisites

  • A deployed hosted agent that’s configured for header-based isolation in Foundry. To deploy an agent, see Deploy a hosted agent.
  • The azd Foundry extensions installed. For installation steps, see Install the azd Foundry extensions.
  • An authenticated Azure Developer CLI session. Run azd auth login if needed.
  • Isolation key values from the system or platform team that configured the agent.
Isolation keys are an opt-in feature of the agent. If your agent doesn’t have isolation configured on the Foundry side, you can ignore these flags and every command works as before. The flags are no-ops when the agent doesn’t require them.

Understand isolation keys

A single deployed Foundry agent can serve many users from the same endpoint. Without isolation keys, every caller sees the same session catalog and the same files in $HOME. Isolation keys partition that state at the platform level. Requests with different keys see different sessions, different conversations, and different filesystems, even though they hit the same agent URL. Typical scenarios include:
  • Multi-tenant SaaS. Each tenant gets its own user isolation key. Sessions and files for tenant A are invisible to tenant B.
  • Per-user data planes. A chat product mints a user key when a customer signs in. The customer’s history and uploads are sandboxed to that key.
  • Per-thread isolation. Within a single user, a chat key further partitions state per conversation thread, such as “support” versus “billing”.
When a request omits a required isolation key, Foundry returns 403 or 404. An existing session isn’t visible to a caller without the key. The CLI surfaces this as a structured error with the platform’s response code.

Choose isolation flags

--user-isolation-key and --chat-isolation-key are passed through verbatim to Foundry. The CLI doesn’t interpret their values. It only sets the headers on outgoing requests. --isolation-key controls who owns the session and is therefore allowed to delete it. The CLI defaults this to a value derived from your Entra token, which is why most workflows don’t need to set it explicitly. Pass it only when you create a session under a different owner, such as when scripting a per-tenant setup, and want the same caller to be able to delete it later.
There is no generic --header K=V flag on invoke. The three flags above are the only custom headers the extension exposes. If you need to send other arbitrary headers, call the deployed endpoint with curl or a language SDK directly. See Invoke a hosted agent with the Azure Developer CLI for the --agent-endpoint URL format.

Invoke an agent with isolation headers

  1. Pass the headers on every invoke. The keys can be anything your agent understands, such as a tenant ID, a hashed user ID, or a chat thread UUID:
  2. Pass just one key if your agent only configures one dimension of isolation:
Both flags work with every invoke mode: local (--local), remote, version-pinned (--version), and the project-free --agent-endpoint form.

Create and delete sessions with an ownership key

Session create and delete also accept --isolation-key for session ownership. By default, the CLI derives this value from your Entra token, so within a single developer’s workflow you never need to set it. Set it explicitly when one identity creates a session that another identity must clean up.
The user and chat isolation flags also apply to all four session subcommands, so a session that was created with a user key must be looked up with the same user key.

Use isolation keys with files and logs

The same --user-isolation-key and --chat-isolation-key flags work everywhere a session is implied. A session that lives behind isolation headers is only reachable from commands that pass the same headers.
If you forget the keys, the CLI looks at the default, unisolated session and reports “session not found” because it can’t see the isolated state.

Verify isolation headers

Use --output raw (-o raw) on invoke to dump the full HTTP response, including any echoed headers and the platform’s response code. This is the fastest way to confirm a deployment is receiving and accepting the keys.
The output is the unmodified HTTP response, including the status line, response headers, and response body. Friendly summary lines like Session: and Invocation: are suppressed in raw mode. Combine --output raw with --debug to also see the outgoing request being constructed, including request URL, request headers, and request body. The two flags together produce enough detail to reproduce the call with curl.

Script isolation patterns

Loop per tenant

The flags compose well with shell loops. The pattern below invokes the same prompt for every tenant in a list, sandboxing each call to that tenant’s isolation key.

Wrap keys with environment variables

Many teams export the keys once per shell session, then let every azd ai agent invocation pick them up. Wrap the CLI behind a thin alias.

Use keys in CI pipelines

Put the keys in CI secrets and reference them in the same way.

Troubleshoot isolation keys

Understand unsupported scenarios

  • Generic --header K=V flag. Only the three isolation flags above are exposed. To send arbitrary headers, drop down to curl or an HTTP client targeting the URL from azd ai agent show.
  • Per-call isolation without the flags. The CLI doesn’t read isolation keys from env vars automatically. Pass the flags explicitly or wrap the CLI in a script as shown above.
  • Local enforcement. azd ai agent run and --local invokes don’t enforce isolation. That is a Foundry platform behavior. Test isolation with a deployed agent.