A zero-dependency, pure-memory POSIX Shell sandbox powered by MoonBit.
MoonBash is a complete rewrite of vercel-labs/just-bash using MoonBit, compiled to pure JavaScript with no WASM dependencies. It provides a secure, embeddable Bash interpreter for AI Agents, Serverless Edge functions, browser-based terminals, and any environment that needs sandboxed shell execution.
| Feature | just-bash (TS) | MoonBash (MoonBit) |
|---|---|---|
| Language | TypeScript | MoonBit -> Pure JS |
| Type Safety | Structural (TS) | Algebraic Data Types + Pattern Matching |
| ReDoS Protection | JS RegExp (vulnerable) | VM-based regex engine (immune) |
| Commands | ~30 | 87 (incl. awk, sed, jq, tar, diff, gzip) |
| Bundle Size | ~200KB+ | 432 KB npm tarball / 434 KB gzip publish build |
| Cold Start | Fast | Faster (sync init, no WASM instantiate) |
| WASM Required | No | No |
| API Surface Compatible | N/A | 100% drop-in replacement |
Status note (as of 2026-04-20): command coverage is complete (87/87) and comparison tests are at 523/523 (100%). Security test suites are fully passing, gzip/gunzip/zcat use real DEFLATE compression via gmlewis/gzip, and the browser website demo now ships under examples/website/ with MoonBit owning the runtime flow in src/website/*.mbt. Spec compatibility hardening remains in progress. See docs/ROADMAP.md.
Current npm package measurements, taken on 2026-04-20 from real release builds and npm pack --dry-run outputs:
| Build flavor | dist/index.mjs |
gzip | npm tarball | unpacked | Notes |
|---|---|---|---|---|---|
release package (vp run build) |
4.56 MB | 663 KB | 650 KB | 4.57 MB | readable ESM output, no sourcemaps published |
publish package (vp run build:publish) |
1.65 MB | 434 KB | 432 KB | 1.67 MB | release build plus JS minification |
Why this is still larger than the older 997 KB / 245 KB figures sometimes cited in project notes:
- those numbers refer to a separately minified MoonBit release artifact benchmark, not the current npm package emitted by
vp pack - the npm package no longer ships sourcemaps; the tarball contains only
dist/index.mjs,dist/index.d.mts, andpackage.json vp run buildkeeps output readable for debugging, whilevp run build:publishis intended to optimize publish size
Compared with the standard release package, vp run build:publish cuts the raw ESM bundle by about 64% and the npm tarball by about 34%.
- Zero Dependencies - Compiles to a single pure JS file, no WASM, no native binaries
- Memory Safe - MoonBit's type system prevents null pointer crashes and buffer overflows
- ReDoS Immune - Built-in VM-based regex engine eliminates catastrophic backtracking
- API Compatible - Drop-in replacement for
just-bashwith identical TypeScript API - Multi-Target - Same MoonBit source compiles to JS (npm), WASM (Python/Rust), and native
- AI Agent Frameworks - LangChain, AutoGen, OpenDevin, Claude Code
- Serverless Edge - Vercel Edge, Cloudflare Workers, Deno Deploy
- Browser - Online coding education, interactive documentation
- Embedded - Game engines, cross-platform build tools, CI/CD pipelines
import { Bash } from "moon-bash";
const bash = new Bash({
env: { USER: "agent" },
});
const result = await bash.exec('echo "Hello from MoonBash!" | tr a-z A-Z');
console.log(result.stdout); // "HELLO FROM MOONBASH!\n"
console.log(result.exitCode); // 0MoonBash currently has three distinct build outputs:
- npm package -
vp run buildrunsmoon -C src build --target js --release && vp pack, bundlingsrc/wrapper/index.tsinto an ESM package atdist/.vp run build:publishuses the same release build but enablesvp packminification viaMOONBASH_PACK_MINIFY=1. The published entrypoints aredist/index.mjsanddist/index.d.mts; sourcemaps are not shipped in the npm package. - MoonBit / mooncakes package - the pure MoonBit runtime is packaged from
src/usingsrc/moon.mod.json. The TypeScript wrapper and browser demo are excluded from that package, and MoonBit publish artifacts are produced undersrc/_build/publish/. - Browser demo -
vp run build:websitebuilds the static site intoexamples/website/dist/.
Useful commands:
vp run build:mbt- compile the MoonBit core to JavaScript inreleasemodevp run build:ts- bundle the TypeScript wrapper into the npm package underdist/vp run build- run both steps for the npm packagevp run build:publish- run the release build plus minified npm packagingvp run build:website- build the browser demo bundle
Build pipeline in practice:
MoonBit (.mbt) -> moon -C src build --target js --release -> generated JS in src/_build/...
-> src/wrapper/index.ts -> vp pack -> dist/index.mjs + dist/index.d.mts
-> examples/website/main.js + src/website -> vp build -c vite.website.config.ts -> examples/website/dist/
MoonBash now includes a browser demo that recreates the justbash.dev terminal experience, but uses MoonBash as the runtime.
Key pieces:
src/website/- MoonBit package for DOM creation, browser state, async command flow, and verification playbacksrc/wrapper/browser.ts- browser-friendly wrapper exports exposingBash,defineCommand, and related APIsexamples/website/main.js- thin bootstrap that injects config/data intoglobalThisexamples/website/- static website assets and bundle output
Build and run it locally:
vp run build:website
vp run serve:websiteThen open http://localhost:4173.
What the demo proves:
- MoonBash can run entirely in the browser as pure JavaScript
- the in-memory filesystem can preload real repository docs for interactive exploration
- custom commands such as
about,install, andgithubcan be layered on top without changing the MoonBit core - MoonBit can own the website runtime itself, not just the shell core, while keeping JS as a thin host/config bridge
See examples/website/README.md for the demo-specific README.
┌─────────────────────────────────────────────────────┐
│ TypeScript API Layer │
│ (100% compatible with just-bash API) │
├─────────────────────────────────────────────────────┤
│ MoonBit Core Engine │
│ ┌──────────┐ ┌──────────┐ ┌───────────────────┐ │
│ │ Lexer │→ │ Parser │→ │ AST Evaluator │ │
│ │(lexmatch)│ │(ADT+PM) │ │(pattern matching) │ │
│ └──────────┘ └──────────┘ └───────────────────┘ │
│ ┌──────────────────┐ ┌──────────────────────────┐ │
│ │ 87 Built-in │ │ Virtual Filesystem │ │
│ │ Commands │ │ (InMemoryFs + AgentFS) │ │
│ └──────────────────┘ └──────────────────────────┘ │
├─────────────────────────────────────────────────────┤
│ moon build --target js │
│ Pure JavaScript Output (no WASM) │
└─────────────────────────────────────────────────────┘
| Document | Description |
|---|---|
| Architecture | System architecture and module design |
| API Specification | Public API surface and type definitions |
| Commands | All 87 built-in command specifications |
| Ecosystem Mapping | Command-to-library implementation strategy and FFI boundary |
| Filesystem | Virtual filesystem design and implementation |
| Security | Sandbox security model and threat mitigation |
| FFI & Interop | MoonBit-JavaScript interop design |
| Roadmap | Development phases and milestones |
examples/website/README.md |
Browser demo structure, build, and local serving |
Apache-2.0