Rhai
A small, safe, embeddable scripting language and evaluation engine for Rust.
Repository Health
Technical Analysis
Rhai is an embedded scripting language and evaluation engine for Rust that gives applications a safe, sandboxed, and ergonomic way to run user-supplied scripts. Its syntax borrows from JavaScript and Rust, supports dynamic typing, and integrates tightly with native Rust functions and types.
Designed to never panic the host and to defend against malicious scripts, Rhai is well suited to plugin systems, configuration-as-code, game logic, and any workload where end users need to extend behavior at runtime without recompiling. It runs everywhere Rust does, including WebAssembly and no-std targets.
What You Get
- A complete embeddable scripting engine with a JavaScript-and-Rust-like language
- Tight two-way integration between scripts and native Rust functions, types, getters/setters, and methods
- A sandboxed, don’t-panic execution model with guards against stack overflow, oversized data, and runaway scripts
Common Use Cases
- Adding user-scriptable plugins or extension points to a Rust application
- Expressing business rules or configuration as editable scripts rather than recompiled code
- Driving game logic, automation, or template generation at runtime
Under The Hood
Architecture
The engine centers on an Engine type that parses source into an optimized AST (src/ast), then evaluates it via a tree-walking interpreter (src/eval) against a Scope of variables and constants. Native functions and packages are registered into a function registry, and the module system (src/module) supports dynamically loadable code. Optimization passes fold constants and prune dead branches before evaluation.
Tech Stack
Pure Rust (edition 2018, MSRV 1.66) with a deliberately small dependency set: smallvec, thin-vec, ahash, num-traits, once_cell, bitflags, and smartstring, plus optional serde, rust_decimal, and rustyline. Extensive Cargo features gate no_std, sync, decimal, and metadata builds.
Code Quality
Mature and heavily exercised, with a large tests/ suite, fuzz targets under fuzz/, benches, and a documented “don’t panic” guarantee. Roughly 4,700 commits from 71 contributors over nearly a decade indicate strong maintenance discipline.
API Design
The public API is compact and approachable: create an Engine, register functions/types, and call eval/run. Procedural-macro plugins reduce boilerplate for exposing Rust APIs, and the extensive online Book documents ergonomics thoroughly.