Skip to content

Spike: Investigate Client Side Python Execution using Pyodide #1

@AJaccP

Description

@AJaccP

🧠 Context

The questions site (questions.carletoncomputerscience.ca) needs to support code-execution questions where a student submits Python code and gets graded against a test suite. One option is Pyodide, which runs Python entirely in the browser using WebAssembly - no server required.

This spike determines whether Pyodide is a viable path and where its limits are. The repo already has example questions and sample submissions to test against. See SCHEMA.md for the question format and test file conventions, and questions/add-two-numbers/ and questions/reverse-string/ for concrete examples.

🎯 What we're hoping to do

  • Load a student's Python submission in the browser.
  • Run the corresponding test file from questions/<question-id>/tests.py against it.
  • Get back pass/fail results in the JSON format described in SCHEMA.md.
  • Do this entirely client-side, with no server round-trip.

🔍 What to look into

Work through the following questions and record your findings. Not all of them have clean answers — that's fine, note what you found and what's still unclear.

  1. Test and submission workflow. How does the full loop work: we write a test file, a student submits code, and the result comes back as structured pass/fail? Walk through how the test file runs against the submission inside Pyodide, following the SCHEMA.md conventions (import solution, virtual filesystem). Note any friction.

  2. Startup time. How long does the first Python execution take after the page loads (cold start)? How long do subsequent executions in the same session take (warm)?

  3. Missing stdlib modules. Are there Python standard library modules Pyodide doesn't support or behaves differently? Focus on what intro CS students commonly use: math, random, collections, dataclasses, typing, sys, os, io.

  4. Multi-file questions. If a question needs a helper module alongside the student's submission, how would that work? Does Pyodide support loading multiple files into the same Python environment?

  5. Timeout and infinite loops. If a student submits an infinite loop, what happens? Is there a way to interrupt execution after a time limit? Does this differ between running Pyodide in Node.js vs. in a browser Web Worker?

  6. Output capture. How do you capture stdout, stderr, and Python tracebacks from Pyodide? Can these be surfaced back to the student in a readable form?

  7. Browser deployment setup. If your demo runs in Node.js, what are the actual steps to deploy this in a browser? How is the Pyodide bundle delivered, is a Web Worker needed to keep the page responsive, and what's the rough impact on page load? Link to any relevant setup guides or docs — you don't need to have tested this directly.

🖥 How to demonstrate it

Build a minimal demo — a plain HTML page or a Node.js script. No styling, no UI framework, no code editor.

The demo should:

  1. Load Pyodide.
  2. Load a hardcoded student submission (try submissions/add-two-numbers/correct.py, then wrong-answer.py, then broken.py).
  3. Run the corresponding test file (questions/add-two-numbers/tests.py) against it.
  4. Print the JSON result and a plain-text pass/fail verdict to the page or console.
  5. Repeat with reverse-string to cover a slightly more complex case.

Include a short written document (a markdown file in your spike branch is fine) covering your answers to the questions above and any other friction you ran into. Key numbers (bundle size, startup time) should be included.

✅ Is it usable for our case?

Determine yes, no, or yes with caveats. If caveats, list the important ones. This is the main thing the team needs from this ticket.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions