.zip of your code (and optionally your dependencies), and Agent Service either runs it as-is or builds your dependencies for you in the cloud.
Use the SDK and REST procedures in this article when you need to deploy source-code agents programmatically—from the Python SDK or .NET SDK in your own applications, or directly over the REST API for custom tooling, language-agnostic automation, or integration with existing continuous-delivery systems. In this article, you complete the following tasks:
- Pick a dependency-resolution mode and package your source.
- Create the agent, wait for it to reach
active, and invoke it. - Update, version, download, and stream logs for the deployed agent.
Prerequisites
- A Microsoft Foundry project in a supported region.
- Azure CLI version 2.80 or later, signed in to the tenant that owns the project.
- Python
- C#
- REST API
-
pipfrom Python 3.13 or later, to package your source locally. -
The
azure-ai-projectsversion 2.2.0 or later andazure-identitypackages.
Supported runtimes
Thecode_configuration.runtime field in the agent definition accepts the following values. Pick the runtime that matches the binaries in your zip—Linux x86_64 wheels for Python, or the TargetFramework of your dotnet publish output for .NET.
Language version support policy
The Agent Service runtime includes the platform-built container image for each value ofcode_configuration.runtime. To keep your deployed agents fully supported, Foundry aligns hosted agent language support with end-of-life support for each language. Support ends on the community end-of-support date for the language version. Microsoft might retire a code_configuration.runtime value earlier when platform constraints (such as the underlying base image) require it.
For upstream end-of-support schedules, see:
- Python: Status of Python versions (python.org).
- .NET: .NET and .NET Core support policy.
Retirement phase
After a language end-of-life date, you can still create, update, and run hosted agents that use the retired runtime value. However, those agents aren’t eligible for support, new features, or security patches until you upgrade them to a supported runtime by setting a currentcode_configuration.runtime value and redeploying.
Required permissions
You need the Foundry Project Manager role at the project scope to deploy a hosted agent. This role grants the data-plane permissions to create and update agents, plus the ability to create role assignments for the platform-created agent identity if needed. For a detailed breakdown of the permissions involved, see Hosted agent permissions reference.The Foundry RBAC roles were recently renamed. Foundry User, Foundry Owner, Foundry Account Owner, and Foundry Project Manager were previously named Azure AI User, Azure AI Owner, Azure AI Account Owner, and Azure AI Project Manager. You might still see the previous names in some places while the rename rolls out. The role IDs and core permissions are unchanged by the rename.
Deployment lifecycle
Every source-code deployment follows the same sequence: package -> create or update -> poll untilactive -> invoke. The source-code path uses code_configuration in the agent definition. The image-based path uses container_configuration instead. These two options are mutually exclusive on a single version.
Choose the path that fits your workflow. If you’re not sure, start with the Azure Developer CLI or VS Code—it’s the recommended path for most customers.
Choose how dependencies are resolved
Before you start, pick a value forcode_configuration.dependency_resolution. This choice affects what you put in the zip.
For bundled mode, see Package the zip manually for the local build commands.
Firewall requirements for private virtual networks
If you secure your project with a private virtual network, update your network policy to allow outbound connections to the following endpoints before you deploy. All source-code deployments require outbound access to:mcr.microsoft.com*.login.microsoft.com
Deploy using the Azure Developer CLI or VS Code
The Azure Developer CLI (azd) and the Foundry Toolkit for VS Code automate the full source-code deployment lifecycle—they package your source into a zip, compute the SHA-256, upload it, poll for active, and configure role-based access control for you. These tools are the recommended path for most customers, and the fastest inner loop.
For a step-by-step walkthrough, see the Quickstart: Deploy your first hosted agent. Choose Code (or Source Code (ZIP upload)) when the quickstart asks for a deployment method.
Select source-code deployment
When you runazd ai agent init interactively, the tool prompts you to choose a deployment mode. Choose code to deploy from source as a ZIP upload instead of building a container image. Code deployment is the default mode for Python and .NET hosted agents. The Foundry Toolkit for VS Code prompts you for the deployment method in the same way.
To select source-code deployment non-interactively, for example, in a CI/CD pipeline, pass --deploy-mode code. This mode requires --runtime and --entry-point, and accepts an optional --dep-resolution value of remote_build (default) or bundled:
azd writes the source-code deployment settings to the codeConfiguration field on the azure.ai.agent service in azure.yaml:
azd up to provision and deploy. Use --deploy-mode container only when you want to build or reference a container image instead.
Use the SDK or REST paths in the following sections when you need to deploy programmatically from your own application or integrate with existing tooling.
Deploy from source code
Select your language or interface. Each tab walks through the same lifecycle: create the agent, poll until it reachesactive, invoke it, and download the deployed code.
- Python
- C#
- REST API
Use the Python SDK to deploy source-code agents from your own applications or automation. You build the zip yourself and pass its bytes and SHA-256 to the SDK, which uploads it and exposes the same create, poll, invoke, and download operations as the REST API. Code-deployment requires For the Invocations protocol, set the See Poll for active for the full list of status values and how to read the For the Invocations protocol, call the invoke endpoint directly with a bearer token, as shown in Invoke the agent.For a complete runnable example, see the Python hosted-agent samples.
azure-ai-projects version 2.2.0 or later.Build the zip
The Python SDK uploads a zip that you build. Use the same layout and dependency-resolution rules described in Package the zip manually. The minimalremote_build payload is a flat zip with main.py and requirements.txt at the root.Create the agent
protocol_versions entry to ProtocolVersionRecord(protocol="invocations", version="1.0.0"). For the Invocations (WebSocket) protocol, use ProtocolVersionRecord(protocol="invocations_ws", version="1.0.0"). For bundled mode, set dependency_resolution="bundled" and ship prebuilt dependencies in the zip. For more information, see Build Linux dependencies locally.Poll for active
error object on failure.Invoke the agent
After the version reachesactive, bind an OpenAI client to the agent endpoint and call it. This example uses the Responses protocol:Download the deployed zip
Verify exactly what’s deployed by downloading the zip and comparing its SHA-256 against the value you uploaded:Package the zip manually
If you useazd, skip this section—azd builds the zip for you. Read it if you use the REST API, if you switch to bundled dependency resolution, or if you need full control over the upload contents.
The zip must be flat at the root—no top-level wrapper folder.
Select the tab for your agent’s language.
- Python
- C#
- REST API
Python layout (remote build mode)
The service installs dependencies in the cloud fromrequirements.txt.Python layout (bundled mode)
You ship prebuilt Linux dependencies inpackages/.Build Linux dependencies locally (bundled, Python)
Use themanylinux2014_x86_64 platform tag so pip downloads Linux wheels even from Windows or macOS.Bash--only-binary=:all: forces wheels (no source builds). The --python-version must match the runtime value in the agent definition.Limits
For the supported
cpu and memory combinations, see Sandbox sizes.
Troubleshooting
Clean up resources
If you scaffolded the project from the Quickstart withazd, run azd down from the project root to remove the entire provisioned environment.
To delete an agent you deployed with the SDK or REST API, use the matching path below.