Code Interpreter has additional charges beyond the token-based fees for Azure OpenAI usage. If your agent calls Code Interpreter simultaneously in two different conversations, it creates two Code Interpreter sessions. Each session is active by default for one hour with an idle timeout of 30 minutes.
Prerequisites
- Basic or standard agent environment. See agent environment setup for details.
- Latest SDK package installed for your language. The .NET SDK is currently in preview. See the quickstart for installation steps.
- Azure AI model deployment configured in your project.
Code Interpreter isn’t available in all regions. See Check regional and model availability.
Usage support
The following table shows SDK and setup support.Create an agent with Code Interpreter
The following samples demonstrate how to create an agent with Code Interpreter enabled, upload a file for analysis, and download the generated output. Each file-upload sample generates a small CSV in the current working directory, uploads it, and then deletes the local temporary file.Check regional and model availability
Tool availability varies by region and model. For the current list of supported regions and models for Code Interpreter, see Best practices for using tools in Microsoft Foundry Agent Service.Supported file types
Troubleshooting
Clean up resources
Delete resources you created in this sample when you no longer need them to avoid ongoing costs:- Delete the agent version.
- Delete the conversation.
- Delete uploaded files.
Sandboxed execution environment
Code Interpreter runs Python code in a Microsoft-managed sandbox. The sandbox is designed for running untrusted code and uses dynamic sessions (code interpreter sessions) in Azure Container Apps. Each session is isolated by a Hyper-V boundary. Key behaviors to plan for:- Region: The Code Interpreter sandbox runs in the same Azure region as your Foundry project.
- Session lifetime: A Code Interpreter session is active for up to one hour, with an idle timeout (see the Important note at the beginning of this article).
- Isolation: Each session runs in an isolated environment. If your agent invokes Code Interpreter concurrently in different conversations, separate sessions are created.
- Network isolation and internet access: The sandbox doesn’t inherit your agent subnet configuration, and dynamic sessions can’t make outbound network requests.
- Files in the sandbox: The sandboxed Python runtime has access to files you attach for analysis. Code Interpreter can also generate files, such as charts, and return them as downloadable outputs.