ChatGPTCanvasLevel 2: Context

How Do You Edit and Run Code in ChatGPT Without Canvas?

Use code blocks. OpenAI moved coding from Canvas into code blocks inside chat responses, and its help page says you can edit supported blocks directly, open them full screen, switch between Code and Preview, and select Run for supported Python. These actions depend on your plan, device and workspace, so you may not see all of them.

Prompt to copy
Write this as one [Python / HTML / React] code block so I can edit it directly:

[what the code should do]

Input example: [paste a small sample]
Expected output: [what it should produce]
Constraints: [version, libraries allowed, no external network calls]

From now on, when I ask for a change, update this same block and tell me in one line what changed. Don't reprint unrelated code in the chat. If it can't run in ChatGPT's sandbox, tell me why.
Code blockinside a chat
  • Edit in place
  • Preview HTML, React, SVG
  • Run supported Python
Codex local projectdesktop app
  • Opens your folders
  • Reads and changes your files
  • Git from the primary folder
Code blocks are for a piece of code in a sandbox, and a Codex local project is for real files on your computer. From OpenAI's docs.

Try it now

  1. 1Paste the prompt with a small real task, such as a Python script that totals a column in sample CSV text.
  2. 2If Run appears on the block, select it and read the console output. For HTML or SVG, select Preview instead.
  3. 3Change one line in the block by hand, then ask "What does the current version do differently?"
  4. 4It worked if the answer mentions your edit. If there's no Preview button, OpenAI says that block doesn't support a preview.

Use it when

One script, component or query you're shaping over several rounds. It's also good for seeing a quick result, such as a page mockup, a diagram or a small Python data check, without setting anything up.

Skip it when

Work spread over many files or tied to your real dependencies. The sandbox isn't your project. For that, use a local project in the ChatGPT desktop app, which OpenAI says can read and change the files in folders you attach. Don't use Run as proof that code works in production either, because it hasn't touched your environment.

Why it works

A code block keeps code apart from the rest of the reply, with a language label and one version to work on. Your edits save with the conversation after a short delay, and ChatGPT uses your latest version when you follow up, so it isn't patching an older copy. Preview can show HTML pages, React components, SVG images, Mermaid diagrams and Vega or Vega-Lite charts. Run opens a code workspace with console output and errors, and you can stop it mid-run. Both run in a sandbox, and ChatGPT may ask permission before a preview connects to outside resources.

Example

Say you've got a messy CSV export and want a script that normalizes dates. You paste ten sample rows and ask for one Python block. You run it, see the error in the console, and ask for a fix to the block. When the output looks right, you copy the script out and run it against the real file on your own machine, where its actual dependencies live.

Going further

Diagrams created in code blocks can be exported as images, according to February 27, 2026 release notes. That's useful for Mermaid flowcharts going into a document. Admins can control whether code execution and network access are available in a workspace, so a missing Run at work may be a policy rather than a bug. For real repositories, OpenAI's docs say a ChatGPT project can't directly access a folder on your computer, while a local project can. Use Edit project to add folders, and Codex uses the primary folder as the default for Git operations and for finding AGENTS.md.

Common mistakes

  • Assuming every language can run. OpenAI only describes Run for supported Python, and Preview only for certain formats.
  • Testing a preview that needs an outside API, then blaming the code. A sandboxed preview may need your permission to connect, and workspace admins can block network access.
  • Copying from an old reply after you've edited the block. Copy from the latest block, since it holds your changes.
  • Pasting secrets into a block to make it run. Use placeholder values, and keep real keys on your own machine.

Sources

Checked 6 November 2026. Products change often, so confirm details with the vendor.

Related

Beyond the course