Skip to content

Python Lab: pyodide on separate domain behind experiment#73741

Merged
bencodeorg merged 17 commits into
stagingfrom
ben/pythonlab-separate-domain-experiment
Jul 17, 2026
Merged

Python Lab: pyodide on separate domain behind experiment#73741
bencodeorg merged 17 commits into
stagingfrom
ben/pythonlab-separate-domain-experiment

Conversation

@bencodeorg

@bencodeorg bencodeorg commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

(extends work and copies description from this PR, but puts it behind an experiment. New layer is pyodideManager, which chooses between the old and new approach based on an experiment flag.): #73653

Sets up Python Lab such that the core execution (Web Worker running pyodide) happens on a separate domain behind an experiment. Can be turned on with the URL param ?pythonlab-separate-domain=1.

The implementation is very similar to what we do in Web Lab 2.

  • studio.code.org creates an iframe where we load a codeprojects subdomain.
  • That page then creates the Web Worker and Service Worker that power the core Python Lab experience.
  • A messaging layer passes messages between the studio.code.org parent page and the iframe.
image

Testing story

I tested manually that I could run Python Lab programs with and without the experiment enabled, and I only observed the sandbox iframe added to the DOM with the experiment enabled.

Follow-up work

There's some initial work that was done to support network requests in Python Lab that has been on pause: https://codedotorg.atlassian.net/browse/CT-537

I did some exploration here just to validate that I could get GET requests working with pyodide running on the separate domain if wanted to add that eventually, which was successful (although worth investigating in more detail). More information here: https://codedotorg.slack.com/archives/C03DBDN67B7/p1784142244745509?thread_ts=1783019149.114019&cid=C03DBDN67B7

@bencodeorg bencodeorg changed the title Ben/pythonlab separate domain experiment Python Lab: pyodide on separate domain behind experiment Jul 14, 2026
# every module in an eval() call for source maps -- wasm-unsafe-eval doesn't cover
# that, only actual eval() does. Minified/production builds use devtool: 'source-map'
# instead, which doesn't need this.
script_src += " 'unsafe-eval'"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had issues running the new sandboxed version via yarn start (although yarn start:cheapest worked because it doesn't have source maps), as well as on Drone (when I had the experiment enabled by default) without this. I'm not sure if there's a better approach here, so could use a second pair of eyes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also allow this on any version of the web lab 2 preview, so I think it's ok.

@bencodeorg
bencodeorg requested a review from a team July 16, 2026 21:17

@molly-moen molly-moen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

# every module in an eval() call for source maps -- wasm-unsafe-eval doesn't cover
# that, only actual eval() does. Minified/production builds use devtool: 'source-map'
# instead, which doesn't need this.
script_src += " 'unsafe-eval'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also allow this on any version of the web lab 2 preview, so I think it's ok.

@bencodeorg
bencodeorg merged commit c4b08f0 into staging Jul 17, 2026
8 checks passed
@bencodeorg
bencodeorg deleted the ben/pythonlab-separate-domain-experiment branch July 17, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants