Skip to content
Aubrey J Cook Programmer

← Portfolio

Sandbox terminal

A terminal that runs real code in the page. Every demo is genuine JavaScript executed in an isolated worker — including modules that were written in TypeScript and compiled before shipping. connect owner/repo loads demos from a sandbox repository and runs them in that same worker.

AUBREY-1 · SANDBOX · ECMASCRIPT 2020+ IDLE

Up and down arrows walk your command history. Ctrl + L clears the screen. Esc interrupts a running demo, or cancels a connect that is still fetching.

Connect a repository

  1. In that repository, add sandbox.json at the root. schema is 1, runner is "worker", and demos lists demo files relative to the manifest.
  2. Each demo file is a classic script that calls Demos.define('name', { title, blurb, lang }, fn), the same shape as demos/collatz.js. The name in that call is the command. Compile TypeScript first. Relative imports of other files in the repo work. Leave node: imports out of those files; they run in a browser worker.
  3. The repository has to be public. In the terminal above, type the commands below. connect owner/repo@ref pins a tag, branch, or commit. A local server is connect http://127.0.0.1:8080/. Opening this page with ?sandbox=owner/repo links it on load.
  4. demos lists what was linked. run hello runs one. link shows the manifest URL. disconnect drops the link and restores a built-in that shared a name.
connect owner/repo
demos
run hello

How this works

Runs for real

Demos are ordinary functions. The terminal serialises each one, hands it to an isolated worker, and streams back everything it prints — including return values and thrown errors.

TypeScript included

Modules authored in TypeScript are compiled to ES modules before shipping, so no compiler is downloaded at runtime. type-basics is one: its .ts source ships beside its build output.

Isolated

Code runs in a Web Worker with no DOM access, in a throwaway scope, with a time limit. A runaway loop interrupts instead of freezing the page.

External sandboxes

A sandbox repo publishes sandbox.json and demo files in the same shape as the ones here. Linking it fetches those files and resolves their relative imports against the repo.