Code that runs on the page
Put an editor and a Run button in any page, for any of 23 languages. The code runs in the reader's browser, in a sandbox, with no server.
<code-playground language="lua" label="Lua, running on this page">
-- Press Run: Lua starts in your browser.
print("Hello from " .. _VERSION)
</code-playground>
The editor understands the code
The language's own server runs in the page: errors as you type, types on hover, completion. Nothing starts until you click into the editor.
- Hover
clampto see its type. - Type
Math.for completions. - Fix the red line:
clamptakes three arguments.
Outputs beyond text, linked to the code
A proof is a tree, drawn as one. Press Run on the Proof tab, then hover a step: the part of the sequent it is about lights up in the editor.
Safe for code you did not write
Code runs in a sandboxed frame with no network, and cannot reach the page. Nothing runs until the reader presses Run. Try to escape it.
What a playground can be
Each demo is a page built with the framework. Open one and run it.
On a page
- One idea, six shapes
- The same program as an editor, a notebook cell, a chat message, an exercise, a slide and a tooltip.
- Any width
- Drag the edge, or pick a width: the same playground wraps and scrolls inside its box, never the page.
- Styling
- One playground in six complete looks, each with the CSS that makes it: custom properties, parts, and a start from nothing.
- Plain HTML, Markdown or Solid
- One playground three ways, with the source of each beside it.
- Many languages, one interface
- Switch the language under one idea; every language is the same element.
- Bring your language
- A language is a package: a manifest, a grammar and a worker. Here is one running beside its own files.
Outputs
- The editor knows the language
- Errors, types on hover, completion and signature help from the language's own server, and a proof assistant's goals as you edit.
- Outputs beyond text
- Proof trees, countermodels, intermediate forms, tables, a typeset page.
- Outputs linked to the code
- Outputs are panes you place anywhere; hover one and the code it came from lights up.
- Outputs before any script
- The output was computed when the site was built, and shows with scripts off.
Teaching
- A notebook of shared cells
- Cells share one engine, a hidden setup, a folded prelude, and outputs that follow the code.
- Exercises with hidden tests
- Write the function; hidden tests judge it. Vim keys, saved code and share links.
Trust
- Limits and containment
- A run that never ends is stopped; the sandbox has no network and cannot reach this page.
Languages
23 ready-made packages, from Python and Rust to Rocq and Agda, with their outputs: proofs, intermediate forms, types. Each name opens a runnable example.
General purpose
Functional
Proof assistants and logics
Data and typesetting
Get started
The playgrounds are a framework and a set of languages. There are three ways to put one on a page.
An element and a script
For any site: serve the playgrounds directory, load the script, write the tag.
<script type="module" src="/playgrounds/element/define.js"></script>
<code-playground language="python">
print(sum(n * n for n in range(1, 11) if n % 2))
</code-playground>
npm
For a site with a bundler. The package is the framework; the languages come from the next step. It is not on the npm registry: the flake builds it as packages.npm. A site built with nixpkgs' importNpmLock installs it from the store, as the framework's README shows. Any other npm site installs the built package from a path:
# in a checkout of code-playgrounds
nix build .#npm --out-link /path/to/your-site/.playgrounds
# in your site
echo "install-links=true" >> .npmrc
npm install file:.playgrounds
import "code-playgrounds/element/define";
A Nix flake
Builds the directory of languages to serve, with the headers for your host.
{
imports = [ inputs.playgrounds.flakeModules.default ];
perSystem.playgrounds = {
engines = inputs'.languages.engines;
languages.python.enable = true;
};
}
The documentation has the rest, and /llms.txt with a Markdown copy of every page is there for agents. The sources are code-playgrounds and languages.