Crate sandkiste

source ·
Expand description

Run code in virtual machines (sandboxes)


This crate provides an abstract API for the Rust programming language to allow executing scripting language code snippets in a sandbox.

The scripting language (or VM which executes code written in that scripting language) is not specified by this crate. Instead, other crates may use this crate to provide a scripting-language-independent interface to execute certain functions or provide callbacks from the VM to Rust.

Central trait is a Machine, which is capable to compile certain code into a function (see trait Compile for compiling code into functions, and see associated type Machine::Function and trait Function for executing these functions).

Passing values from Rust to the VM or from the VM to Rust is done through a “datum” type that is specific to each particular VM used (see associated type Machine::Datum). Some VMs may support creating closures in Rust which can then be converted into a “datum” and passed to the VM (see trait Callback).

VMs may also support setting global variables or variables in modules (see traits Globals and HasModules).

As different VMs may have “datum” types with different features (e.g. some scripting languages might support integers while others only know strings, a Machine::Datum can implement different traits in the types module which determine which functionality is supported (e.g. types::MaybeString if a datum can be a string).



  • Error traits and error kinds
  • Prelude that (currently) re-exports everything
  • Unnameable traits to be included via wildcard syntax
  • Traits to be implemented by Machine::Datum to support specific types