Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Code interpreter in Microsoft Copilot Studio and AI Builder prompts lets makers build AI agents that:
- Execute Python code for data analysis, processing Word, Excel, PowerPoint, and PDF files, and visualizations
- Use language models for generative responses
This feature is tailored for developers, business analysts, and low-code makers. Code generation and execution integrate seamlessly with the Copilot Studio ecosystem to create powerful, AI-driven solutions.
Developers should read Code interpreter for developers and review the Code interpreter Power Apps Component Framework (PCF) component sample to understand how they can use the Dataverse Predict message to invoke prompts and process the responses returned.
Requirements
- Licensing: Microsoft Copilot Studio billing and licensing. Code generation and execution count as text and generative AI tools (premium) features. 
- Supported regions: Available for all public clouds. Sovereign clouds aren't currently supported. 
Code interpreter capabilities in a glance
Code interpreter lets agents write and execute Python code for advanced tasks. Use cases include:
- Excel file processing: Create, copy, and update Excel worksheets in a workbook, read StyleNames, apply StyleNames, copy formatting across cells, copy and update formulas across cells, and so on.
- Word and PowerPoint file processing.
- PDF file processing: Create and copy PDF files, read tables, and text paragraphs.
- Dataverse table data processing.
- Complex mathematical and statistical computations.
- Data analysis, manipulation, and visualization (for example, charts and graphs).
Code interpreter adds the following capabilities to prompts:
- Support for files as an output type in prompts
- Support for Excel files as input and output types for prompts
You can create prompts in two ways:
- Using the Build your own prompt option in AI Hub in Power Apps
- Within a prompt tool added to an agent in Copilot Studio at the agent level
For more information on prompts, see Prompts overview.
You can also use code interpreter in agent chat in Copilot Studio.
Turn on code interpreter for the environment in Power Platform admin center
For all uses of code interpreter, you first need to turn on code interpreter for the environment in Power Platform admin center.
Important
A tenant admin must turn on code interpreter using Power Platform admin center. The setting is a per environment setting and is configured as Off by default. Once you turn on the setting in Power Platform admin center, you can turn on code interpreter in your agents and prompts. Make sure you carry out this step before proceeding with the rest of the setup.
To turn on code interpreter for the environment:
- In Power Platform admin center, go to Copilot, and then select Settings. 
- Scroll to the Copilot Studio section and select Code generation and execution in Copilot Studio. A pane with list of environments opens. 
- Select the environment and select Add. A pane opens. 
- Select On to turn on code generation and execution in Copilot Studio. 
- Select Save. 
Create a new empty prompt and turn on code interpreter for the prompt
First, you start by creating a new empty prompt in either AI Hub or Copilot Studio. Then, you turn on code interpreter in the prompt settings.
Create prompt in Power Apps AI Hub and turn on code interpreter
You can create a new empty prompt in AI Hub in Power Apps and turn on code interpreter in the prompt settings. You can see examples of how to write and configure prompts that use code interpreter, see Use code interpreter in prompts examples.
Important
Before you begin, make sure that code interpreter is already turned on for the environment in Power Platform admin center.
- Go to Power Apps. 
- Select AI hub in the left pane. 
- Select Prompts.   
- Select Build your own prompt.   
- Provide the name of your prompt. 
- In the Instructions section, select ... > Settings.   
- On the Settings page, turn on code interpreter. 
- Close the settings page to return to the prompt editor. 
An empty prompt is created with code interpreter turned on. Next, you can write the prompt instructions and configure the prompt as needed.
Create a prompt as a tool within an agent and turn on code interpreter
You can create a new empty prompt as a tool within an agent in Copilot Studio and turn on code interpreter for that prompt. Later in this article we show you how to write and configure a prompt that uses code interpreter.
Important
Before you begin, make sure that code interpreter is already turned on for the environment in Power Platform admin center.
- In Copilot Studio, go to the agent where you want to turn on code interpreter. 
- Select the Tools tab, and then select Add a tool > New tool > Prompt.   - The embedded AI Builder prompt authoring interface opens in Copilot Studio. 
- Select ... > Settings on the information bar.   
- On the Settings page, select Enable code interpreter. 
- Close the settings page to return to the prompt editor. 
An empty prompt is created with code interpreter turned on.
Next steps with code interpreter in prompts
Next, you can write the prompt instructions and configure the prompt as needed.
For detailed examples of how to use code interpreter in prompts, see Code interpreter prompt examples.
Best practices for code interpreter in prompts
- Use other AI tools like Copilot to get the optimized prompt to start.
- Use precise prompts with examples (few-shot prompting).
- Specify outputs (for example, "Return as JSON" or "Excel" or "PDF").
Use code interpreter in agent chat (preview)
This functionality is in public preview and is subject to change.
You can also turn on code interpreter at the agent level in Copilot Studio and then trigger it in agent chat using prompt instructions that the agent needs code to perform.
Turn on code interpreter in agent settings
Important
Before you begin, make sure that code interpreter is already turned on for the environment in Power Platform admin center.
- Go to your agent and select Settings.   
- On the Generative AI page, turn on Code interpreter.   
- Save the settings and close the settings page to return to your agent.   
Trigger code interpreter with a prompt in agent chat
- Enter the following instructions in the Test your agent chat: - 1. You are given: - An Excel file with thousands of procurement transactions, including vendor name, invoice amount, PO number, and transaction date. 2. Your tasks: - Process the Excel file to identify: - Transactions over $10,000 with missing or blank PO numbers. - Flag transactions that meet either of the following criteria: - High-value transaction with missing PO. - For each flagged transaction: - Highlight the row in red. - Add a comment explaining the issue (for example, "PO Missing"). 3. Generate a summary report listing: - Total flagged transactions. - Vendor names involved. - Reasons for flagging. 4. Return: - The updated Excel file with highlights and comments. - A summary of updates made in text.
- Upload an Excel file with procurement transactions as input to the chat. You can use the agent chat to generate a sample Excel file with procurement transactions as needed. 
- In a few seconds, you should see the summary output in text as the agent response along with the updated Excel file. You can download the file to verify.   
Limitations
- Analyzing multiple files uploaded in a single prompt isn't supported.
- Returning multiple file outputs in a single prompt isn't supported.
- Asking questions about an uploaded file over multiple turns isn't supported.