Code Execution — Unique AI Documentation

Code Execution

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:

Triggering Code Execution

The orchestrator automatically invokes Code Execution when appropriate. Users can also explicitly trigger it with phrases such as:

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

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

LiteLLM (OpenAI) models

Security & Governance

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.

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

Generated Files

Name Description Type Default
fileDownloadFailedMessage The message to display when a file download fails after all retry attempts. str "⚠️ File could not be generated. Please try again."
maxConcurrentFileDownloads The maximum number of concurrent file downloads. int 10
maxDownloadRetries Maximum number of additional download attempts per container file after the first try (0 = no retries). int 2
downloadRetryBaseDelay Base delay in seconds for exponential backoff between download/upload retries. float 0.5
progressUpdateInterval Minimum seconds between progress message updates sent to the user. float 3.0
downloadChunkSize Chunk size in bytes for streaming container file downloads. int 8192
downloadReadTimeout HTTP read timeout in seconds for container file downloads. Applies per SDK attempt. float 120.0

Code Display

Name Description Type Default
enable Enable display of executed code before the assistant message. bool true
sleepTimeBeforeDisplay Time to sleep before displaying the executed code. Please increase this value if you experience rendering issues. float 0.2

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 Short description of the tool used to steer tool selection. str Access via Space management > Sources & Tools > Code Execution > Settings > Configuration > Tool > Tool Description
toolDescriptionForSystemPrompt 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). str Access via Space management > Sources & Tools > Code Execution > Settings > Configuration > Tool > Tool Description for System Prompt
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

Feature Flags

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

Name Value
FEATURE_FLAG_USE_OPENAI_V1_13819 true or list of comma-separated Company ids
FEATURE_FLAG_ENABLE_CODE_EXECUTION_UN_17498 true or list of comma-separated Company ids
FEATURE_FLAG_ENABLE_CODE_EXECUTION_SIDE_PANEL_UN_18787 true or list of comma-separated Company ids
FEATURE_FLAG_ENABLE_CODE_EXECUTION_FENCE_UN_17972 true or list of comma-separated Company ids