Code Execution
6 min read
This feature is currently in BETA. It may change significantly before general availability. Documentation may lag behind feature updates. Use in production environments at your own discretion. Please refer to our Upgrade and Release Process for more information.
It is strongly recommended that Code Execution is used with Azure OpenAI GPT-5. In current deployment, Code Execution is only compatible with Azure OpenAI models.
Functionality
The Code Execution tool allows users to direct models to write and run Python code within a safely containerized execution environment to solve complex problems in subjects such as math, data analysis, and coding. This tool enhances the natural language capabilities of models with deterministic code based logic.
Use Cases
The Code Execution Tool is ideal for:
Data Analysis & Visualization: Exploring datasets, computing statistics, and generating charts without leaving the chat.
Example: "I've uploaded
sales_2024.csv. Can you calculate monthly revenue growth and visualize it with a line chart?
File Transformation & Cleaning: Converting between formats, fixing messy data, or standardizing schemas.
Example: "Convert this Excel workbook into separate cleaned CSVs per sheet and fix inconsistent date formats."
Rapid Prototyping & Snippet Generation: Trying out small algorithms, testing ideas, or generating runnable code.
Example: "Prototype a function that detects outliers using z-scores and show it working on a small synthetic dataset."
Statistical Modeling & Forecasting: Building simple models to estimate trends, forecasts, or correlations.
Example: "Forecast next quarter's website traffic from the last 24 months using ARIMA and plot the prediction with confidence intervals."
Image/Document Parsing & Insights: Extracting structured information from PDFs, images, or logs.
Example: "Extract the table from page 3 of this PDF into a CSV and summarize the key metrics by category."
Output Rendering
Code Execution outputs are rendered as interactive cards inline in the chat interface. Users can toggle between the Python source code view and the rendered output view using tabs on each card. The following output types are supported:
Output Type | Description |
|---|---|
Charts & Images (PNG/SVG) | Rendered inline with responsive scaling, aspect ratio preservation, and one-click copy |
Tables | CSV/tabular data displayed as a styled, horizontally scrollable table with column headers |
HTML | Rendered in a sandboxed preview with the option to download as HTML or PNG |
Files (PDF, DOCX, XLSX, etc.) | Presented as download cards with type-specific icons and one-click download |
Each card also includes a Code View with Python syntax highlighting, copy, and expand functionality.
Limitations
Models are currently restricted to those available through the Azure Responses API. The Unique Quality Assessment team strongly recommends that Code Execution is only used with Azure OpenAI GPT-5 or later.
Knowledge Base files are not accessible to Code Execution
Upload up to 10 files at once with maximum file size: 100MB
Plotly graphs cannot be directly exported as PNG images for embedding in PDF, Word (DOCX), or PowerPoint (PPTX) files. The Azure OpenAI code execution container does not include the
kaleidopackage, which Plotly requires for static image export. If you need charts embedded as images in exported documents, request that the model use matplotlib instead of Plotly.
All available models
AZURE_GPT_5_2025_0807AZURE_GPT_5_MINI_2025_0807AZURE_GPT_5_NANO_2025_0807AZURE_GPT_5_CHAT_2025_0807AZURE_GPT_5_PRO_2025_1006AZURE_GPT_51_2025_1113AZURE_GPT_51_THINKING_2025_1113AZURE_GPT_51_CHAT_2025_1113AZURE_GPT_51_CODEX_2025_1113AZURE_GPT_51_CODEX_MINI_2025_1113AZURE_o1_2024_1217AZURE_o3_MINI_2025_0131AZURE_GPT_41_2025_0414AZURE_GPT_41_MINI_2025_0414AZURE_GPT_41_NANO_2025_0414AZURE_o3_2025_0416AZURE_o4_MINI_2025_0416litellm:openai-gpt-5litellm:openai-gpt-5-minilitellm:openai-gpt-5-nanolitellm:openai-gpt-5-chatlitellm:openai-gpt-5-prolitellm:openai-gpt-5-1litellm:openai-gpt-5-1-thinkinglitellm:openai-o1litellm:openai-o3litellm:openai-o3-deep-researchlitellm:openai-o4-minilitellm:openai-o4-mini-deep-researchlitellm:openai-gpt-4-1-minilitellm:openai-gpt-4-1-nano
Configuration
Users MUST use Responses API models in order to enable the Code Execution Tool. The following feature flags MUST also be enabled for complete functionality Feature Flags.
As of release 2026.14, the Code Execution tool is located under a dedicated "Coding Capabilities" subsection within the Sources & Tools configuration in Space Admin. Code execution is by default turned on when a model for compatible models. Admins can also toggle Code Execution on/off as desired. The tool will display an error if an incompatible model is selected for the space.
The fields in this schema define the essential parameters and configurations required for conducting queries with code execution. Each field contributes to the overall functionality specifying tool calling instructions, file upload and download handling, container lifecycle, and error handling behavior. These configurations ensure a comprehensive and tailored code execution user experience.
Name | Description | Type | Default |
|---|---|---|---|
| Configuration for how generated files are displayed, downloaded and uploaded. | Generated files | See below |
| Configuration for how executed code is displayed. | Code Display | See below |
| Core tool configuration for the code interpreter. | Tool | See below |
Tool
Name | Description | Type | Default |
|---|---|---|---|
| If set, the files uploaded to the chat will be uploaded to the container where code is executed. |
|
|
| The description of the tool that will be included in the system prompt. |
|
|
| The description of the tool that will be included in the system prompt. |
| (Full instructions with file paths, markdown syntax, dataframe display, and handling user queries) See full default prompt below. |
| Minutes of inactivity after which the container is deleted. Maximum allowed by OpenAI is 20. |
|
|
| If set, use the |
|
|
| Documents (content_ids) to always upload to the container from the Knowledge Base. Useful for example for templates. |
| empty |
Use this tool to run python code, e.g to generate plots, process excel files, perform calculations, etc.
Instructions:
Uploaded and generated files:
- All files uploaded to the chat are available at the path `/mnt/data/<filename>`.
- All files generated through code MUST be saved in the `/mnt/data` folder.
CRUCIAL Instructions for displaying images and files in the chat:
- Once files are generated in the `/mnt/data` folder you MUST reference them in the chat using markdown syntax in order to display them in the chat.
WHENEVER you reference a generated file, you MUST use the following format:
```
**Descriptive Title of Graph/Chart/File** (linebreak is important. You must choose a good user friendly title, Other markdown syntax such as `#` can be used too)
[*Generating your {Graph/Chart/File}…*](sandbox:/mnt/data/<filename>)
```
IMPORTANT: Do NOT append a leading `!` even when displaying an image.
Always use a line break between the title and the markdown!
- Files with image file extensions are displayed directly in the chat, while other file extensions are shown as download links.
- Not using syntax above will FAIL to show images to the user.
- YOU MUST use the syntax above to display images, otherwise the image will not be displayed in the chat.
- Only the following file types are allowed to be uploaded to the platform, anything else will FAIL: PDF, DOCX, XLSX, PPTX, CSV, HTML, MD, TXT, PNG, JPG, JPEG.
- You MUST always use this syntax, otherwise the files will not be displayed in the chat.
# Displaying Dataframes/Tables:
- Whenever asked to display a dataframe/table, it is CRITICAL to represent it faithfully as a markdown table in your response.
Handling User Queries:
- Whenever the user query requires using the python tool, you must always think first about the steps required.
- Use the tool multiple times:
- You MUST NOT guess anything about the structure of the data / files uploaded. Rather, you MUST perform some data exploration first.
- Example: User uploads an excel files and asks a question about it. First Read the data, explore the columns, columns types, etc. Then use the tool to answer the user's query.
In this case, you can simply call the tool multiple times.
- REMEMBER that you can always read the content of text, csv files if needed. In this case, you MUST always limit the amount of data displayed.
- If a tool step fails, you must recover as much as possible.
- After exhausting all possible solutions without success, inform the user of what was tried and request clarification/help.Generated Files
Name | Description | Type | Default |
|---|---|---|---|
| The message to display when a file download fails. |
|
|
| The maximum number of concurrent file downloads. |
|
|
Code Display
Name | Description | Type | Default |
|---|---|---|---|
| Time to sleep before displaying the executed code. Please increase this value if you experience rendering issues. (Will be removed in a future release). |
|
|
Feature Flags
The following feature flags must be set for code execution to function:
Name | Value | Pod |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|