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:

  1. 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?

  2. 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."

  3. 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."

  4. 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."

  5. 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 kaleido package, 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_0807

  • AZURE_GPT_5_MINI_2025_0807

  • AZURE_GPT_5_NANO_2025_0807

  • AZURE_GPT_5_CHAT_2025_0807

  • AZURE_GPT_5_PRO_2025_1006

  • AZURE_GPT_51_2025_1113

  • AZURE_GPT_51_THINKING_2025_1113

  • AZURE_GPT_51_CHAT_2025_1113

  • AZURE_GPT_51_CODEX_2025_1113

  • AZURE_GPT_51_CODEX_MINI_2025_1113

  • AZURE_o1_2024_1217

  • AZURE_o3_MINI_2025_0131

  • AZURE_GPT_41_2025_0414

  • AZURE_GPT_41_MINI_2025_0414

  • AZURE_GPT_41_NANO_2025_0414

  • AZURE_o3_2025_0416

  • AZURE_o4_MINI_2025_0416

  • litellm:openai-gpt-5

  • litellm:openai-gpt-5-mini

  • litellm:openai-gpt-5-nano

  • litellm:openai-gpt-5-chat

  • litellm:openai-gpt-5-pro

  • litellm:openai-gpt-5-1

  • litellm:openai-gpt-5-1-thinking

  • litellm:openai-o1

  • litellm:openai-o3

  • litellm:openai-o3-deep-research

  • litellm:openai-o4-mini

  • litellm:openai-o4-mini-deep-research

  • litellm:openai-gpt-4-1-mini

  • litellm: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

generatedFilesConfig

Configuration for how generated files are displayed, downloaded and uploaded.

Generated files

See below

executedCodeDisplayConfig

Configuration for how executed code is displayed.

Code Display

See below

toolConfig

Core tool configuration for the code interpreter.

Tool

See below

Tool

Name

Description

Type

Default

uploadFilesInChatToContainer

If set, the files uploaded to the chat will be uploaded to the container where code is executed.

bool

true

toolDescription

The description of the tool that will be included in the system prompt.

str

"Use this tool to run python code, e.g to generate plots, process excel files, perform calculations, etc."

toolDescriptionForSystemPrompt

The description of the tool that will be included in the system prompt.

str

(Full instructions with file paths, markdown syntax, dataframe display, and handling user queries) See full default prompt below.

expiresAfterMinutes

Minutes of inactivity after which the container is deleted. Maximum allowed by OpenAI is 20.

int

20

useAutoContainer

If set, use the auto container setting from OpenAI. Note that this will recreate the container on each call.

bool

false

additionalUploadedDocuments

Documents (content_ids) to always upload to the container from the Knowledge Base. Useful for example for templates.

list

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

fileDownloadFailedMessage

The message to display when a file download fails.

str

"⚠️ File download failed ..."

maxConcurrentFileDownloads

The maximum number of concurrent file downloads.

int

10

Code Display

Name

Description

Type

Default

sleepTimeBeforeDisplay

Time to sleep before displaying the executed code. Please increase this value if you experience rendering issues. (Will be removed in a future release).

float

0.2

Feature Flags

The following feature flags must be set for code execution to function:

Name

Value

Pod

FEATURE_FLAG_USE_OPENAI_V1_13819

true or list of comma-separated Company ids

backend-service-chat

FEATURE_FLAG_ENABLE_CODE_EXECUTION_UN_17498

true

backend-service-chat, web-app-admin

SOURCE_AVAILABLE_TOOLS_REMOTELY

true

backend-service-chat

FEATURE_FLAG_ENABLE_CODE_EXECUTION_FENCE_UN_17972

true

assistants-core

Last updated