Expand description
§Afterburner
Sandboxed JavaScript runtime for Rust. One crate, one entry point.
use afterburner::Afterburner;
use serde_json::json;
let ab = Afterburner::new()?;
let id = ab.register("(d) => d.n + 1")?;
let out = ab.run(&id, &json!({ "n": 41 }))?;
assert_eq!(out, json!(42));§Modes
- Adaptive (default): first call runs via
rquickjs(native, sub-microsecond); a background thread compiles the same script to WASM, and subsequent calls switch to the sandboxed Wasmtime path. - Native only: trusted code; sub-microsecond throughput, no sandbox.
- WASM only: untrusted code; Wasmtime + QuickJS, capability gates
via
Manifold. - Threaded: N worker threads behind a single
Afterburner. Hash-routed with Chase-Lev-style steal-when-idle, token-bucket admission, graceful drain. Enable viaAfterburnerBuilder::threaded.
§Feature flags
| feature | default | unlocks |
|---|---|---|
wasm | yes | Wasmtime backend (WasmCombustor) |
native | yes | rquickjs backend (NativeCombustor) |
thrust | yes | multi-threaded scheduler (ThrustEngine) |
adaptive | no | dual-tier native → wasm auto-switch |
flow | no | flow-engine glue (multi-module bundles) |
host-http | no | outbound HTTP host function |
bin | no | burn CLI binary deps (clap, rustyline) |
§Capability gating
Every thrust carries a Manifold (via FuelGauge) that controls
what host-backed modules (fs, crypto, net, env) the script can
reach. Default is Manifold::sealed - nothing accessible.
Re-exports§
pub use polyglot::Outcome;pub use afterburner_core as core;pub use afterburner_node_compat as node_compat;pub use afterburner_wasi as wasi;pub use afterburner_ignite as ignite;pub use afterburner_thrust as thrust_crate;
Modules§
- native
- Native backend - trusted code via rquickjs FFI.
- polyglot
- Unified polyglot facade: one entry point for every language.
- prelude
- Common imports, re-exported as a single glob target.
- thrust
- Multi-threaded scheduler.
- wasm
- WASM backend - untrusted code via Wasmtime + QuickJS plugin.
Structs§
- Afterburner
- One-stop entry point. Construct via
Afterburner::neworAfterburner::builder. - Afterburner
Builder - Configuration builder for
Afterburner. - Burn
Cache - Thread-safe compile-or-cache wrapper over a
Combustor. Identical sources produce exactly one compile across concurrent callers; losers of the insert race wait on the sameOnceLockrather than issuing a duplicateignite. Hit path is wait-free. - Call
Site - Where in the guest source the effect was requested. Optional because not every substrate can attribute a call site.
- Fuel
Gauge - Execution resource limits applied per call. Each field is optional;
Nonemeans “no cap on this dimension.” - Host
Effect - The seam record: the identity of one effect the guest requested, byte
safe. This is what a host inspects in
HostContext::on_host_callto decide record vs serve. - Host
Effect Record - The request plus its recorded result. On the original run the substrate executes the real effect and hands back one of these; on replay the host returns a stored one and the substrate performs no real effect.
- Http
Response - Response returned from
HostFunction::HttpRequest. - InMemory
State Store - Default in-process backend backed by a lock-free
HopscotchMap. Suitable for single-process deployments; not durable across restarts. - InProcess
Cache Backend - In-process default backend - no network involvement, state lives in a single lock-free map. Equivalent to the pre-Phase-G behavior.
- Manifold
- A full capability profile for one script execution.
- Null
Host - Zero-capability host context - useful as a default for tests and for the
minimal flow-engine path that only uses
Log. - Registry
Stats - Statistics the cache exposes for observability. Load-atomically; no snapshot guarantees across fields.
- RunResult
- Result of
crate::engine::Combustor::run_with_result- a full run that also surfaces the typed return value. - Script
Id - Identifier returned by
Combustor::igniteand consumed bythrust/extinguish. Content-addressed: thehashis SHA-256 of the JS source, so two identical sources produce the sameScriptIdregardless of whichCombustorcompiled them. - Script
Invocation - Input for
crate::engine::Combustor::run_script- the script source plus Node-styleprocess.argvandprocess.envvalues. - Script
Outcome - Result of
crate::engine::Combustor::run_script- top-level script-mode execution (no UDF envelope). - Threaded
Builder - Builder for the multi-threaded
Afterburnervariant. Obtained viaAfterburnerBuilder::threaded.
Enums§
- Afterburner
Error - Every failure mode Afterburner exposes to callers. Keep the set closed: callers match on it exhaustively.
- Effect
Detail - Op-specific detail for a
HostEffect.Fsneeds none (itsFileOpis already inEffectKind::Fs); the other kinds carry their shape here. - Effect
Kind - The broad category of a side effect.
Fscarries the concrete file operation inline; the raw op only - the effect class (idempotent, observed, mutating, …) is causarum’s concern and is deliberately not pre-baked here. - Effect
Status - The terminal status of a recorded effect. An error is carried as bytes,
never a lossy
String, so a non-UTF-8 error payload round-trips exactly. - Engine
Mode - Which backend produced a
ScriptId. Useful for adaptive tier switching and for diagnostics; callers generally shouldn’t branch on this. - EnvAccess
- Process-environment access for
process.envandgetenv. - FileOp
- The raw filesystem operation. Raw op only - no pre-baked classification.
- FsAccess
- Filesystem capability. Roots are resolved via
fs::canonicalizeat call time; any path escape (via.., symlinks, etc.) outside the listed roots is rejected withAfterburnerError::PermissionDenied. - Host
Function - The full host-function set.
- Http
Method - HTTP method for
HostFunction::HttpRequest. Present even when thehost-httpfeature is off so the enum shape is stable. - Language
- A source language supported by the afterburner runtime.
- Listen
Access - Inbound listening capability - which ports daemon-mode servers
(
http.createServer().listen(port), the HTTP/3 listener) may bind. Checked by the listen host-calls before any socket bind; a denied port surfaces asPermissionDenied, exactly like outboundnetandfsdenials. - LogLevel
- Log severity, mirroring
console.*in JS. - Mode
- Which backend
AfterburnerBuilder::buildshould construct. - NetAccess
- Outbound networking capability. Inbound listening is governed
separately by
ListenAccess-netmodels outbound only. - Output
Tag - Which
OutputValueshape a frame carries. - Output
Value - Result of an output-framing-aware invocation
(
thrust_out/thrust_raw_out) - the output-side mirror of the input framings.
Traits§
- Burn
Cache Backend - Pluggable storage for script source text, keyed by SHA-256 of the source. Enables distributed deployments where a single script is registered once on any node and replicated via an external coordinator (Redis, S3, NATS, etc.). Each node still compiles locally - the backend stores source text, not compiled modules, since the compiled form is engine-specific (wasmtime vs rquickjs) and not portably serializable today.
- Combustor
- The engine contract. Implementations must be
Send + Syncso a single instance can back a sharedBurnCacheacross threads. - Host
Context - Callbacks the host provides to the script runtime. Implementations supply
whichever methods are relevant; defaults are intentionally no-ops or
Noneso minimal hosts (e.g. tests) don’t need to stub every variant. - Session
- A stateful run session over a persistent, byte-exact filesystem root.
- State
Store - Pluggable cross-invocation key/value storage.
Functions§
- content_
hash - BLAKE3 the given bytes: the canonical content-address for effect and
output payloads. The frame carrier (
crate::frame) and the effect seam (crate::effect) both use this one function, so a value carried as anoutputand the same bytes seen as a filesystem effect content-address identically (the record/replay parity crux). Distinct fromsha256, which stays the source-address for aScriptId. - decode_
frame - Decode a frame, returning its tag and payload bytes.
- decode_
output_ value - Decode a frame back into an
OutputValue. AJson-tagged payload is parsed as JSON (a parse failure is loud); aBytes-tagged payload is returned verbatim. - encode_
frame - Encode
payloadinto a self-verifying frame taggedkind. - encode_
output_ value - Encode an
OutputValueinto a frame.Jsonis carried as its canonical serialized text bytes,Bytesverbatim. The inverse ofdecode_output_value. - sha256
- SHA-256 the given bytes. Shared helper so every engine hashes sources
identically and
ScriptIds round-trip between backends. This is the source-address (aScriptId); the content-address for effect and output payloads iscontent_hash(BLAKE3).
Type Aliases§
- Result
- Convenience alias used across the workspace.
- Shared
State Store - Convenience shared handle. The store is reference-counted and
Arc<dyn StateStore>is what gets stashed inWasmCombustor/ thread-local activator.