Open-source project
rhaiscript/rhai avatar
rhaiscript/rhai

Rhai: an embedded scripting engine for Rust that you configure to distrust its scripts

Rhai - An embedded scripting language for Rust.

5,826 stars264 forksRustApache-2.0

At a glance

What is it?
Rhai is a scripting language and evaluation engine written in Rust, meant to be embedded in a host application. This analysis covers its typing and speed claims, how Rust values cross into scripts, which safety limits it offers, and what you must switch on or build yourself.
Who is it for?
Rhai fits a Rust application that needs user-editable logic, rules or a small DSL, and where you are willing to set the evaluation limits yourself. It is the wrong pick if you need a language with static typing, or if you expect the quoted speed figure to hold on your own hardware without measuring it with the Grain feature on and off.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • rhaiscript/rhai5,826 ★ · +132
Star history
Repository2026-09-242026-11-22
rhaiscript/rhai5.7k5.8k

132 Stars in the last 59 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

Rhai is a language you embed, with JavaScript and Rust habits and dynamic types

Rhai is an embedded scripting language and evaluation engine for Rust, aimed at adding scripting to an application without leaving Rust. The syntax is described as similar to JavaScript plus Rust, and values are dynamically typed, so a variable can hold an integer one moment and a string the next. The crate is published on crates.io as rhai, the description in Cargo.toml reads Embedded scripting for Rust, and the repository's homepage points at the crate page. Targets are broad: all CPU and operating system targets that Rust supports, including WebAssembly and no-std builds. The minimum Rust version is 1.66.0, stated both in the README and in Cargo.toml as rust-version. The repository also keeps a Cargo.msrv.lock file at the top level, which suggests the minimum version is checked against a fixed lockfile. The consequence of dynamic typing is that type mistakes in a script show up when the script runs, not when your Rust code compiles. Your host code stays statically checked, but the script boundary does not, so plan error handling around script evaluation.

The speed figure comes from one 2.6 GHz virtual machine and the AST walker

The README quotes one million iterations in 0.14 seconds on a single-core 2.6 GHz Linux VM, running scripts/speed_test.rhai through the standard AST walker. That is the only performance number given on the front page, and it describes a loop benchmark on one machine. It says nothing about scripts that call back into Rust functions, build large arrays or concatenate strings, which are the workloads that dominate in real applications. A second execution path exists: Rhai Grain is a bytecode compiler and virtual machine that is advertised as around 1.8 to 2 times faster, and it is enabled with the grain feature. Because it sits behind a feature flag, you get the standard walker unless you ask for Grain in your Cargo.toml. The repository includes examples/grain_bench.rs and examples/lazy_bench.rs, along with a benches directory, so you can measure both paths on your own hardware with your own scripts. Do that before choosing, since the 1.8 to 2x claim is relative to the same machine and the same benchmark.

Rust values reach scripts through Scope, with no trait to implement

Passing data in is done through an external Scope. You push Rust values into it as variables or constants, and the README states that all clonable Rust types are supported, with no need to implement any special trait. If you want finer control, you can tap directly into the variable resolution process instead. Registering native Rust functions and custom types is supported, including getters and setters, methods and indexers, and the engine supports function overloading and operator overloading. Going the other way, you can call a script-defined function from Rust. The examples directory shows each of these as a runnable file: hello.rs, simple_fn.rs, callback.rs, custom_types.rs, custom_types_and_methods.rs, arrays_and_structs.rs, strings.rs, reuse_scope.rs and pause_and_resume.rs. The clone requirement has a practical cost. A value placed in the scope is copied for the script's use, so a large structure that you push on every call is cloned each time. If that matters for your data, the custom types and getter route lets scripts reach into Rust-owned data without copying all of it, and reusing one Scope across evaluations is the pattern shown in reuse_scope.rs.

Sandboxing is a set of limits you declare, not a default that protects you

Rhai is positioned for running untrusted scripts, and it lists its protections plainly. A Don't Panic guarantee says that any panic is a bug and that a library should never panic the host system. The engine is sandboxed: if declared immutable, it cannot mutate the containing environment unless explicitly permitted. It is described as protected against stack overflow, over-sized data and runaway scripts, and it can track evaluation progress so that you can terminate a run by hand. The project also states that it passes Miri. The names of the limit pages in the documentation are max-call-stack, max-string-size and max-operations, which tell you which dimensions are capped. The catch is the words if declared and explicitly permitted. These are configuration decisions in your host code, so a script engine that you create and leave alone has only the protections you chose to apply. The README also admits to relatively little unsafe code, with some present for performance reasons. For a service that evaluates scripts from third parties, set operation, stack and size caps deliberately and test them with a hostile script before release. The fuzz directory in the repository is evidence that fuzzing is part of the project's checking.

You can shrink the language itself until it is a DSL

A section of the README is addressed to people who want their own language. You can use Rhai as a DSL, disable language features such as looping, and surgically disable keywords and operators. You can also define custom operators and extend the language with custom syntax. This changes how you reason about risk. If your users only need to write conditions and arithmetic, turning off looping removes a whole class of runaway scripts rather than relying on an operation counter to stop them. The cost is that every restriction is something you document to your users, because a script that works in the general language may be rejected by your configured one, and Rhai will not tell your users why in your product's terms. Disabling keywords also changes error messages and editor behavior, so the editor plugins listed on the front page for Visual Studio Code, JetBrains and Sublime Text, which target the general language, may highlight code that your engine rejects. Plan a short reference for your own dialect and keep example scripts in your repository.

The sync feature, serde and no-std are opt-in, and no-std pulls a git dependency

Several capabilities are behind Cargo features. The engine is re-entrant and can be made Send plus Sync through the sync feature, and examples/threading.rs exists to show multi-threaded use. Serialization and deserialization through serde needs the serde feature, with examples/serde.rs as the sample. Minimal builds are supported by excluding language features you do not need. The dependency list is short: smallvec, thin-vec, num-traits, once_cell, ahash, bitflags and smartstring, plus the workspace member rhai_codegen at version 3.3.0 for the plugin system's procedural macros. The no-std path is less tidy. Cargo.toml lists no-std-compat as an optional dependency fetched from a GitLab git repository, alongside optional libm, hashbrown and core-error. A git dependency does not come from crates.io, which affects offline builds, vendoring and supply chain review in embedded projects. If you target no-std, check how your build resolves those optional dependencies, and read the no_std directory in the repository before assuming a plain cargo build will work.

Compile once, evaluate many times, and let the optimizer fold machine-written scripts

For repeated evaluation, Rhai can compile a script once into an AST and run that AST again, which avoids re-parsing on each call. Scripts are also optimized, which the README says is useful for template-based machine-generated scripts, where constants substituted into a template can be folded before evaluation. The sample script in the README is the standard Fibonacci test, deliberately written with a naive recursive algorithm to stress the engine:

ts
// This Rhai script calculates the n-th Fibonacci number using a
// really dumb algorithm to test the speed of the scripting engine.

const TARGET = 28;
const REPEAT = 5;
const ANSWER = 317_811;

fn fib(n) {
    if n < 2 {
        n
    } else {
        fib(n-1) + fib(n-2)
    }
}

print(`Running Fibonacci(${TARGET}) x ${REPEAT} times...`);
print("Ready... Go!");

Note the syntax: const declarations, fn definitions without type annotations, an if expression that returns a value, and backtick strings with interpolation. The scripts subdirectory holds more samples. Because the benchmark is recursion heavy, it measures call overhead more than anything else, so a rules engine that mostly evaluates conditions will behave differently.

Release 1.27.0 landed in October 2026, and the licensing text differs between places

The repository is not archived, and the last push was on 31 October 2026. Recent releases are v1.25.0 on 24 May 2026, v1.26.0 on 25 August 2026 and v1.27.0 on 21 October 2026, matching version 1.27.0 in Cargo.toml. That is roughly one release every two to three months, so changes arrive in steps, and a CHANGELOG.md at the top level records them. Licensing needs a second look. The GitHub metadata lists Apache-2.0, while Cargo.toml declares MIT OR Apache-2.0, and the repository carries both LICENSE-APACHE.txt and LICENSE-MIT.txt. In practice the crate is offered under either license, but check which text your compliance process expects. The authors field lists four names, which shows a small group behind the crate. Rhai also ships documentation as a separate book at rhai.rs, plus a RHAI-CHEATSHEET.md and an AGENTS.md in the repository root. Most of the detail the front page links to lives in that book, so the repository README is a feature index and not a tutorial.

Editorial conclusion

Rhai fits a Rust application that needs user-editable logic, rules or a small DSL, and where you are willing to set the evaluation limits yourself. It is the wrong pick if you need a language with static typing, or if you expect the quoted speed figure to hold on your own hardware without measuring it with the Grain feature on and off.

Frequently asked questions

What is Rhai?

Rhai is an embedded scripting language and evaluation engine for Rust. It gives a way to add scripting to an application, with a JavaScript and Rust like syntax and dynamic typing.

Does Rhai support WebAssembly and no-std?

Yes. Rhai lists all CPU and operating system targets supported by Rust, including WebAssembly and no-std, with a minimum Rust version of 1.66.0.

Is Rhai safe for running untrusted scripts?

Rhai has a Don't Panic guarantee, a sandboxed engine and protections against stack overflow, over-sized data and runaway scripts. These are limits you configure in your host application, and the project says it passes Miri.

What license does Rhai use?

Cargo.toml declares MIT OR Apache-2.0, and the repository contains LICENSE-APACHE.txt and LICENSE-MIT.txt. GitHub lists the license as Apache-2.0.

Official sources

  1. License: Apache-2.0
  2. Project website
  3. README
  4. Releases
  5. rhaiscript/rhai on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/rhaiscript-rhai.svg)](https://hysenlabs.com/projects/rhaiscript-rhai)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/rhaiscript-rhai.svg)](https://hysenlabs.com/projects/rhaiscript-rhai)

Was this useful?