ChatGPT Canvas Code Execution: Run and Check Python
Canvas can display and execute Python code in a side panel, letting you see results alongside the code. Here is how to use it, what to check when execution fails, and how to record what worked.
Updated 5 min read
ChatGPT Canvas can run Python code in a sandboxed environment alongside the chat, letting you see output, fix errors, and iterate without leaving the session. Tools like fenbs let you record the task assumptions, the outputs you have reviewed, and the remaining steps so a future session can continue from the verified point rather than re-running code you have already checked.
This guide explains how code execution works in Canvas, what its limits are, and how to handle common failure cases.
How to trigger code execution in Canvas
Ask ChatGPT to write or display a Python snippet in Canvas: "Write a Python function that reads a CSV file and calculates the mean of each column. Show it in Canvas." When the code appears in the Canvas panel, a run button becomes available. Click it to execute the code.
You can also tell ChatGPT explicitly: "Run the code." It will execute the current snippet and show the output below the code block. If the code produces a chart or a table, that appears in the output area as well.
Canvas code execution is tied to specific ChatGPT plans and models. If you do not see a run option in the Canvas toolbar, check whether your plan includes code execution or whether a different model needs to be selected. See ChatGPT Canvas not available if the Canvas panel itself is missing.
Reading and verifying the output
After execution, read the output carefully before treating the result as correct. Numbers that look plausible are not necessarily right. For data analysis, check the output against a known small example where you can verify the result by hand. For file operations, check that the expected file was created and contains the expected content.
If the output includes a chart, check the axis labels, the scale, and the data points. AI-generated plots sometimes display the correct shape but swap axis labels or omit units.
Output from the executed code does not transfer automatically to another session. Copy the output you want to keep before closing the conversation.
What the execution environment can and cannot do
The Canvas execution environment runs Python in an isolated sandbox. You can use standard data science libraries such as NumPy and Pandas and produce charts with Matplotlib. The environment does not have access to the internet, cannot read files from your local machine unless you upload them in the session, and resets when you start a new conversation.
There are time and memory limits. A long-running computation may be cut off before it completes, and the environment cannot hold very large datasets in memory. For large-scale data work, use a local environment or a cloud notebook and use Canvas to develop and test the logic on a smaller sample first.
Handle execution errors
When the code produces a traceback, read the error message before asking ChatGPT to fix it. Understanding the error — missing dependency, index out of range, wrong data type — lets you give a more useful correction instruction and verify that the fix addressed the right problem.
For persistent errors, describe the error message in the chat and ask the AI to explain what caused it. Then ask for a corrected version. Repeat the fix-and-run cycle until the output matches your expectation.
See What is Claude Code and Claude vs ChatGPT for coding for comparisons of coding environments across AI tools.
Iterate and keep the verified result
Once the code produces the expected output, copy both the code and the output before continuing. The Canvas session is not persistent across conversations, and verified code is easy to lose if you do not save it explicitly.
If you are building toward a larger analysis, note which steps have been verified and which remain. An unverified step in the middle of a pipeline may produce correct-looking output that is silently wrong further down.
Before ending the session, add short comments to the code explaining what each main function does and what input it expects. A future session reading the code without that context may change a function in a way that breaks a step the original session had already verified. Treating confirmed code as stable until there is a specific reason to revisit it reduces the risk of introducing errors during follow-up analysis.
Track task assumptions and verified results in fenbs
fenbs keeps the task assumptions, reviewed outputs, and remaining debugging steps in a place that persists between sessions. Create a free account, add the analysis as a task, and note the data source, the expected result, and what has been verified so far. The next session reads that context first so it does not re-run steps you have already confirmed.
Create a free accountFree for one person · No credit card · Works with Claude, ChatGPT, Cursor and more
How to track code work across sessions with fenbs
- Create a free account and add the analysis or script as a task in a fenbs project.
- Write the task assumptions as a context note: the data source, the expected output, and any constraints such as performance requirements.
- After each verified execution, note the confirmed output and the next unverified step in Where we left off.
- Copy the verified code snippet into the task or link to the repository where it is stored.
- Connect your AI app to fenbs from Integrations so the next session reads the verified state before writing new code.
See ChatGPT Codex for more on AI-assisted coding workflows. Browse the AI at work topic for guides on using AI tools for analysis and development.