Skip to main content

Crate airsl

Crate airsl 

Source
Expand description

Embeddable Lua runtime with a host standard library.

airsl runs sandboxed Lua from Rust and gives those scripts the capabilities a shell or Python script would otherwise reach for — JSON, filesystem access, subprocesses, real regular expressions — through host modules implemented in Rust. Everything a script can do arrives under a single airsstack global, so the host decides the surface rather than the Lua standard library.

use airsl::{Engine, FailurePolicy, Policy, Script};

let engine = Engine::builder().policy(Policy::confined()).build()?;
let script = Script::from_file("hooks/enforce.lua")?;

if let Err(error) = engine.eval(&script) {
    // A hook must never block the tool call that triggered it.
    if !FailurePolicy::FailOpen.swallows_errors() {
        eprintln!("{error}");
    }
}

Extend the surface by implementing HostModule and adding it to a ModuleSet; the module becomes a subtable of airsstack alongside the built-ins.

Third-party scripts load as extensions: a directory with its own extension.toml manifest, negotiated against the host’s ceiling and run through an ExtensionHost that owns the resulting engines.

Re-exports§

pub use extension::Extension;
pub use extension::ExtensionHost;
pub use modules::HostModule;
pub use modules::InstallContext;
pub use modules::ModuleSet;
pub use sandbox::EnvGrant;
pub use sandbox::FsGrant;
pub use sandbox::GrantSet;
pub use sandbox::InstructionLimit;
pub use sandbox::LanguageSurface;
pub use sandbox::MemoryLimit;
pub use sandbox::Policy;
pub use sandbox::ProcGrant;
pub use sandbox::ResourceLimits;
pub use types::ChunkName;
pub use types::EventName;
pub use types::ExtensionName;
pub use types::ModuleName;
pub use types::RequireTarget;
pub use types::RootTable;
pub use mlua;

Modules§

extension
Loading third-party Lua extensions with negotiated capabilities.
modules
The airsstack Lua standard library, and the seam for extending it.
sandbox
The three independent axes of what a script is allowed to do.
types
Validated newtypes for the identifiers that cross into the Lua VM.

Structs§

Engine
A configured Lua state.
EngineBuilder
Configures and builds an Engine.
Missing
Type-state marker: the policy has not been chosen yet.
Present
Type-state marker: the policy has been chosen.
Script
Lua source together with the name it reports, the directory it may require from, and the arguments it was invoked with.

Enums§

Error
Everything that can go wrong loading, configuring, or running a Lua script.
ExhaustedLimit
Which resource ceiling a script exhausted.
FailurePolicy
How a caller reacts to a script that failed to load or raised while running.

Type Aliases§

Result
Convenience alias for results carrying an Error.