Code Execution
7 min read
Code Execution is compatible with only Azure OpenAI models. It is strongly recommended that Code Execution is used with Azure OpenAI GPT-5 or later.
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 lets users run Python against their own data and files directly from chat. Common capabilities:
Analyze uploaded CSV/XLSX: compute metrics, build charts, forecast trends, detect outliers
Perform reliable calculations — sums, totals, filters, subtotals — eliminating hallucinated numerical answers
Read macro-enabled Excel files (.xlsm) as data — macros will not execute
Export results as XLSX, DOCX, CSV, and PNG
Generate Word (DOCX) reports with formatted text, figures, and custom templates
Create Excel models with financial projections and year-over-year growth tables
Compare two Excel files and generate a structured difference report
Generate PowerPoint presentations from uploaded templates (quality varies — see Limitations)
Translate and reformat documents (text-layer PDFs work best; complex layouts are best-effort)
Upload up to 10 files at once, max 100 MB per file
Triggering Code Execution
The orchestrator automatically invokes Code Execution when appropriate. Users can also explicitly trigger it with phrases such as:
"Use code to…"
"Create a file…"
"Generate a visualisation…"
"Using code, calculate…"
Common Workflow Examples
Use Case | Setup | Example Prompt |
|---|---|---|
Excel Q&A | Upload CSV/XLSX | "What is total new revenue for this quarter? Use code." |
Excel analysis | Upload dataset | "Filter by segment X and calculate subtotals for each category." |
Excel comparison | Upload two Excel files | "Compare the two files and generate an Excel difference report." |
Financial model | No file needed | "Create an Excel revenue model with year-over-year growth and a simple forecast." |
Word report | Optional: upload template | "Create a Word report on Q3 waste management KPIs with a professional layout." |
Template-based doc | Upload Word/PPTX template | "Use the uploaded template to create a report on operational metrics." |
Document translation | Upload PDF or Word file | "Translate the uploaded document into French, preserving the structure." |
HTML dashboard | Upload data file | "Using code, generate an interactive HTML dashboard summarising the key metrics." |
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
The sandbox has no outbound internet access — no external API calls or runtime package installs are possible. Live data (e.g. market prices, news) must be retrieved via the Web Search tool and passed into the code interpreter.
Upload up to 10 files at once with maximum file size: 100MB. Allowed file types: PDF, DOCX, XLSX, PPTX, CSV, HTML, MD, TXT, PNG, JPG, JPEG.
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.
What Is Possible vs. Not Possible
Capability | Status |
|---|---|
Python execution on user-uploaded files | Supported |
Charts (PNG/SVG via matplotlib), styled tables, DOCX, XLSX artifacts | Supported |
Excel analysis: sums, filters, subtotals, calculations — real computation, no hallucinated numbers | Supported |
Excel macro-enabled files (.xlsm) — readable as data; macros themselves will NOT execute | Partial |
Excel model creation: projections, year-over-year growth, forecasts | Supported |
Compare two Excel files and generate a difference report | Supported |
Word (DOCX) report generation with text, figures, and templates | Supported |
Document translation and reformatting (text-layer PDFs work best) | Supported |
Up to 10 files / 100 MB per file | Supported |
Malware scanning on all uploads | Supported |
Hide raw Python code from end users (admin flag) | Supported |
PowerPoint (PPTX) generation from templates — quality varies; complex decks 10–15 min | Limited |
High-fidelity PDF translation (complex layouts) | Limited |
Generalizable templating for arbitrary client document formats | Limited |
Plotly PNG export for embedding in DOCX/PDF — use matplotlib instead | Not supported |
Excel macro execution | Not supported |
Overwriting original uploaded files — agent creates new files with suffix | Not supported |
Knowledge Base files accessible to Code Execution | Not supported |
Audio or video processing | Not supported |
Persistent workspace across sessions | Not supported |
All available models
The following models expose the RESPONSES_API capability and are therefore compatible with Code Execution. This list is derived directly from the tool's compatible_models configuration in the codebase.
Azure OpenAI 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_GPT_52_2025_1211AZURE_GPT_52_CHAT_2025_1211AZURE_GPT_54_2026_0305AZURE_GPT_54_PRO_2026_0305AZURE_GPT_55_2026_0424AZURE_GPT_55_PRO_2026_0424AZURE_GPT_4o_2024_0513Not recommendedAZURE_GPT_4o_2024_0806Not recommendedAZURE_GPT_4o_2024_1120Not recommendedAZURE_GPT_4o_MINI_2024_0718Not recommendedAZURE_o1_2024_1217Not recommendedAZURE_o3_MINI_2025_0131Not recommendedAZURE_o3_2025_0416Not recommendedAZURE_o4_MINI_2025_0416Not recommendedAZURE_GPT_41_2025_0414Not recommendedAZURE_GPT_41_MINI_2025_0414Not recommendedAZURE_GPT_41_NANO_2025_0414Not recommendedAZURE_MODEL_ROUTER_2025_1118
LiteLLM (OpenAI) models
litellm: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-gpt-5-2litellm:openai-gpt-5-2-thinkinglitellm:openai-gpt-5-4litellm:openai-gpt-5-4-thinkinglitellm:openai-gpt-5-5litellm:openai-gpt-5-5-prolitellm: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
Security & Governance
No outbound internet, no external API calls, no runtime package installs
Code runs inside Azure's hosted container — part of the Azure Responses API
Uploaded files are malware-scanned before processing
The agent cannot overwrite uploaded files — it always creates new output files with a suffix
Strict file-type allowlist: PDF, DOCX, XLSX, PPTX, CSV, HTML, MD, TXT, PNG, JPG, JPEG
Space-level toggle under 'Coding Capabilities' in Space Admin; the orchestrator auto-invokes — there is no manual toggle for end users
Admins can hide raw Python code from end users via the
enableflag in the Code Display configuration20-minute inactivity timeout (Azure maximum)
All actions, generated code, and outputs are fully auditable; privacy risk classified as Negligible
SOC2/HITRUST-aligned controls: identity, environment separation, logging, and privileged access management
Configuration
Users MUST use Responses V1 API models in order to enable the Code Execution Tool. The following feature flags MUST also be enabled for complete functionality Feature Flags.
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 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 |
Generated Files
Name | Description | Type | Default |
|---|---|---|---|
| The message to display when a file download fails after all retry attempts. |
|
|
| The maximum number of concurrent file downloads. |
|
|
| Maximum number of additional download attempts per container file after the first try (0 = no retries). |
|
|
| Base delay in seconds for exponential backoff between download/upload retries. |
|
|
| Minimum seconds between progress message updates sent to the user. |
|
|
| Chunk size in bytes for streaming container file downloads. |
|
|
| HTTP read timeout in seconds for container file downloads. Applies per SDK attempt. |
|
|
Code Display
Name | Description | Type | Default |
|---|---|---|---|
| Enable display of executed code before the assistant message. |
|
|
| Time to sleep before displaying the executed code. Please increase this value if you experience rendering issues. |
|
|
Tool
Name | Description | Type | Default |
|---|---|---|---|
| If set, the files uploaded to the chat will be uploaded to the container where code is executed. |
|
|
| Short description of the tool used to steer tool selection. |
| Access via Space management > Sources & Tools > Code Execution > Settings > Configuration > Tool > Tool Description |
| The full instructions for the tool that are included in the system prompt (file paths, markdown display syntax, visualization library rules, HTML rendering rules, dataframe display, and query handling). |
| Access via Space management > Sources & Tools > Code Execution > Settings > Configuration > Tool > Tool Description for System Prompt |
| 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. |
|
Feature Flags
The following feature flags must be set for code execution to function:
Name | Value |
|---|---|
|
|
|
|
|
|
|
|