A small Flask service that runs submitted Mux programs with the released mux
binary and returns their output. Hosted on Fly.io as
mux-lang-api (mux-lang-api.fly.dev), consumed by
mux-website over HTTP.
POST /api/compilewith{ "code": "<mux source>" }->{ "output": "..." }. Browser traffic reaches this endpoint through the Cloudflare Worker. The Fly origin accepts compile requests only when the Worker supplies the privateMUX_API_ORIGIN_TOKENheader.GET /healthfor health checks- The service runs
mux runinside a disposable bubblewrap namespace on the existing Fly machine. The child has no network, a read-only view of the runtime image, an isolated writable workspace, an allowlisted environment, and CPU/memory/process/file limits. If that boundary cannot be created, the request fails closed; it never falls back to an ordinary child process.
The Dockerfile installs a released mux binary (no Rust/LLVM build),
pinned via ARG MUX_VERSION. The playground therefore runs a known, deliberately
chosen compiler release. The API itself is identified by its deployment commit
and image digest, not by a separate SemVer release. To upgrade the playground:
- Ensure the target version is released in
mux-compiler (the
mux-linux-x86_64.tar.gzasset must exist). - Bump
MUX_VERSIONin theDockerfile. - Deploy (below).
The release pin above is intentional: the playground must run a stable released
compiler, not arbitrary main. To catch a compiler-main regression that would
break this API's contract before the next release bump, a scheduled
.github/workflows/canary-compiler-main.yml job builds mux from
mux-compiler main and runs a smoke
test (tests/canary_smoke.py) against it.
It runs only on a nightly schedule and manual dispatch (never on push or pull
request), so it does not gate normal CI or deploys and is not a required check.
It never changes the MUX_VERSION pin.
pip install -r requirements.txt
# Needs a `mux` binary on PATH (see the mux-compiler install instructions).
MUX_BIN=mux gunicorn --bind 0.0.0.0:8080 server:appOr build/run the production image (matches Fly):
docker build -t mux-website-api .
docker run --rm -p 8080:8080 \
-e MUX_ENV=production \
-e MUX_API_ORIGIN_TOKEN="replace-with-a-random-secret" \
mux-website-apiThe production image requires MUX_API_ORIGIN_TOKEN so the public compile
endpoint cannot be bypassed by calling the Fly hostname directly. Generate one
random value and configure it as a Fly secret and a Cloudflare Worker secret;
never commit it to fly.toml. The Worker provides the distributed edge rate
limit and Cloudflare absorbs volumetric traffic. The API keeps a bounded
in-process limiter as defense in depth, so no Redis or Valkey service is needed
for the single-machine deployment. A shared Redis or Valkey URI remains
supported through RATE_LIMIT_STORAGE_URI if one is already available. The
image also requires /usr/bin/bwrap and /usr/bin/prlimit; these are installed
in the same image and do not require a second Fly application or machine.
fly deployThe slim image bundles clang-22 + the LLVM runtime libraries (the compiler shells
out to clang and links LLVM at compile time) and sets MUX_RUNTIME_LIB so it
never tries to build the runtime from source.
After both the API and Worker deploys, run the credential-free integration smoke from a trusted machine. It checks that direct Fly requests are rejected and that the Worker can compile through the authenticated origin path:
MUX_WORKER_COMPILE_URL=https://mux-ai.corniedj.workers.dev/api/compile \
MUX_API_ORIGIN_URL=https://mux-lang-api.fly.dev/api/compile \
python tests/origin_contract_smoke.py| Repo | What it is |
|---|---|
| mux-compiler | The language and compiler whose release this serves |
| mux-runtime | Runtime + standard library linked by compiled programs |
| mux-website | Docs site (mux-lang.dev) and playground UI |
| tree-sitter-mux | Tree-sitter grammar + highlight queries |
| mux-syntax-highlighting | TextMate grammar, VSCode extension, canonical syntax spec |
| mux-context | Cross-repo architecture, design rationale, glossary, releases |
MIT - Maintained by Derek Corniello
