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.
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 loginif 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”.
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
-
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:
-
Pass just one key if your agent only configures one dimension of isolation:
--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.
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.
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.
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 everyazd 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=Vflag. Only the three isolation flags above are exposed. To send arbitrary headers, drop down tocurlor an HTTP client targeting the URL fromazd 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 runand--localinvokes don’t enforce isolation. That is a Foundry platform behavior. Test isolation with a deployed agent.
Related content
- Invoke a hosted agent with the Azure Developer CLI for every invoke variant and option.
- Monitor hosted agent logs with the Azure Developer CLI to stream isolated session logs.
- Run a hosted agent locally with the Azure Developer CLI to understand local behavior.