CodeLab Runner & Admin Guide

Where programs run, how they are isolated, and how to set up the servers and Moodle


1. Where programs run

CodeLab examples and questions support 27 languages. Each one runs in one of three places:

  • In the browser: Python (Pyodide, with input(), Step and turtle graphics) and HTML / CSS / JS (a sandboxed preview frame with a console). No server load; this also works for guests.
  • On the CodeLab runner: C, C++, Java, C#, Python, JavaScript, TypeScript, Pascal, PHP, Bash, Go, Rust, R, Ruby, Lua, Kotlin, Perl, Octave, Julia, Scheme, Dart, Scala, Elixir, Swift, Haskell and SQL (MariaDB). Runs are interactive: the program asks for input while it runs, as in a terminal. C and C++ also have Step (the GDB debugger, Memory view) and Safe mode (AddressSanitizer and UndefinedBehaviorSanitizer).
  • On Jobe: C, C++, Java, C#, Python, JavaScript, Pascal and PHP, with the whole input given before the run.

Grading of quiz questions is always done on a server, never in the browser: on Jobe, or on the runner through its signed POST /run API. The runner grades like Jobe (the same statuses for compile errors, runtime errors and time limits), so a question gives the same grade on both.

2. How a run is protected

  1. Signed token: when a reader clicks Run, Moodle signs a short-lived token with the shared secret (CODELAB_SECRET). It carries only the numeric user id.
  2. WebSocket session: the browser opens wss://<runner>/session with the token and streams the code, the input and the output.
  3. Bubblewrap sandbox (bwrap): every compilation and run is in its own Linux namespace:
    • no network;
    • only /usr and /etc of the server, read-only, so compilers must be installed under /usr;
    • a private working folder and a small temporary folder;
    • limits with prlimit: CPU time, memory (the JVM, Mono and Node.js get a heap limit instead), file size and output size.
  4. SQL: each run gets its own temporary MariaDB database and user (cl_...), with a 5 second limit per statement; both are dropped at the end.
  5. Moodle side: a rate limit per user and a size limit for code and input protect the servers.

3. Setting up your own runner

The runner (open source, github.com/blagojevicboban/codelab-runner) is a small Node.js service for Ubuntu 24.04:

# 1. The base: sandbox, C/C++, Java, C#, debugger, SQL, Python, Node.js, Pascal, PHP
sudo apt-get install bubblewrap build-essential gdb openjdk-21-jdk-headless mono-mcs mariadb-server \
    python3 nodejs fp-compiler php-cli

# 2. Optional languages from Ubuntu (each is offered only when installed)
sudo apt-get install golang-go rustc r-base-core ruby lua5.4 perl octave guile-3.0 elixir ghc kotlin scala
# Julia, Dart and Swift come from their own downloads, installed under /usr

# 3. Service and settings
sudo cp deploy/codelab-runner.service /etc/systemd/system/
sudo cp deploy/codelab-runner.env.example /etc/codelab-runner.env
# Edit /etc/codelab-runner.env: CODELAB_SECRET, CODELAB_ORIGINS, MariaDB password
sudo systemctl daemon-reload && sudo systemctl enable --now codelab-runner

# 4. Check: the languages the server offers
curl -s http://127.0.0.1:8090/health

4. Moodle settings

Site administration > Plugins > Text editors > TinyMCE editor > CodeLab:

  • Server for running and grading: Automatic (Jobe when it is set, otherwise the runner), Jobe, or CodeLab runner (no Jobe needed). Interactive runs, Step and SQL always use the runner.
  • Address of the interactive server (wss://runner.example.org) and Secret of the interactive server (the same as CODELAB_SECRET).
  • Jobe server: for example https://jobe.example.org, or empty to use only the runner.
  • Connection key (optional): instead of your own servers, a hosted CodeLab runner with all languages. It is a paid plan with a monthly quota of runs, provided by the author of CodeLab (ask at boban.blagojevic@tsp.edu.rs).
  • Python in the browser: on (Chrome or Edge 137+; other browsers run Python on the server).
  • Languages: the languages teachers can choose; only those installed on the server run there.

The settings page tests Jobe and the runner, shows their versions and measures their speed.

5. The editor for readers

  • Themes: Visual Studio Light, Visual Studio Dark, High Contrast Dark, or Automatic (follows the site and the system). The administrator sets the default, the teacher can choose one per example, and readers switch with the theme button.
  • Interface in 29 languages, screen reader and keyboard friendly console, zoom with Ctrl and the mouse wheel, full screen, and input from a phone keyboard.
  • Help: typing help and program templates for every language, tooltips for beginners, explanations of 40 common compiler errors, and optional AI explanations through Moodle's AI subsystem.