Most programming courses for kids start with colored blocks to drag. Gray is the one I built to start with real code instead. A kid from about 8 to 13 types Python or Lua at a prompt, one line at a time, and the first challenge is 2 + 2. There are no accounts and no ads, and nothing to install beyond the language itself, or nothing at all if they play in the browser.

Gray explains an idea, the kid types code at the you> prompt, and Gray runs it, shows the result the way a REPL would, and checks it. This is the first challenge as it sits in gray.py:

{
    "say": (
        "First secret: your computer is a GIANT calculator.\n"
        "If you type some math, Python solves it instantly.\n"
        "\n"
        "Try it! Type:  2 + 2   and press Enter."
    ),
    "task": True,
    "hint": "Type exactly this and press Enter:  2 + 2",
    "must_use": ["+"],
    "expect": 4,
},

expect is the value the code has to produce and must_use is what the code has to contain, so knowing the answer is not enough:

  you> 4
  = 4

  🤔 You're allowed to know the answer — but let the COMPUTER do the work!
  Use the  +  sign in your code.

  you> 2 + 2
  = 4

  ⭐ Perfect!

Other lessons check what was printed, what a variable holds afterwards, or what a function the kid wrote returns.

What You Get

One file per language. gray.py is 2,177 lines and gray.lua is 2,085, engine and lessons together, with no dependencies. python3 gray.py starts the course.

Eleven sections, three of them projects. The 80 challenges of the Python track go from arithmetic through variables, if, loops, input and functions, and then into a number guessing game, a mad-libs story machine and a robot that guards a club door with a password.

A program of their own. In the last section each line the kid gets right is saved into my_first_program.py. Gray then shows them how to run it without Gray, with python my_first_program.py, and tells them that the you> prompt was a REPL all along.

Room for mistakes. A failed attempt is rolled back, so a wrong line cannot spoil a variable that a later lesson needs. A loop that never ends can be stopped and the lesson carries on: Ctrl+C does it in Python, and in Lua an instruction-count watchdog does it by itself. quit saves their place.

Updates at startup. Gray asks gray.academy for a newer version and, if there is one, replaces its own file and relaunches before any lesson begins. Offline it carries on, and GRAY_NO_UPDATE=1 turns the check off.

The Same File in the Browser

The play page runs those two files unmodified on Pyodide and Wasmoon, which are CPython and Lua 5.4 compiled to WebAssembly, in a Web Worker behind an xterm.js terminal. The course is written around input() and io.read(), which block until a line arrives, and a Web Worker has no such call. So the worker parks on Atomics.wait over a SharedArrayBuffer until the page writes the typed line into it. Browsers only allow SharedArrayBuffer on cross-origin-isolated pages and GitHub Pages cannot send the headers for that, so a 60-line service worker re-serves every response with them added.

What a kid types runs on their own device and is never sent anywhere, and their progress is kept in the browser’s local storage.

The Paid Paths

All of that is the Foundations course, and it is free. Three more paths build on it, The Game Maker, The Code Breaker and The Pixel Artist, and one subscription at US$5 a month opens all of them. Their lessons are not in the public repository: a build step splices each path’s sections into copies of the public engines and bundles them into a Cloudflare Worker, which serves a course only for a key whose subscription Stripe says is still running.

There are still no accounts. After Stripe’s checkout the play page trades the checkout session for a subscription key, stores it in the browser and shows it so that it can be pasted in on another computer (#36). A kid playing a paid path is never asked for a name or an email.

Each path was played from start to finish in both languages before it was published: 29 of 29 tasks for The Game Maker (#26), 36 of 36 for The Code Breaker (#38) and 35 of 35 for The Pixel Artist (#39).

Try It

curl -O https://gray.academy/gray.py
python3 gray.py

That needs Python 3, and gray.lua runs on Lua 5.1 or later. If you would rather install nothing, the play page is the same course in a browser tab. Foundations and the play page are Apache 2.0 and on GitHub. If you know a kid who is ready for more than dragging blocks, give Gray a try.