Skip to main content

Crate eryx

Crate eryx 

Source
Expand description

§Eryx

A Python sandbox with async callbacks, powered by WebAssembly.

§Safety

By default, this crate uses #![forbid(unsafe_code)] for maximum safety. When the embedded or preinit features are enabled, this is relaxed to #![deny(unsafe_code)] to allow unsafe wasmtime APIs needed for pre-compiled component loading and CPU feature configuration (e.g., disabling AVX-512).

Eryx executes Python code in a secure WebAssembly sandbox with:

  • Async callback mechanism - Callbacks are exposed as direct async functions (e.g., await get_time())
  • Parallel execution - Multiple callbacks can run concurrently via asyncio.gather()
  • Execution tracing - Line-level progress reporting via sys.settrace
  • Introspection - Python can discover available callbacks at runtime
  • Composable runtime libraries - Pre-built APIs with Python wrappers and type stubs

§Quick Start

use eryx::Sandbox;

#[tokio::main]
async fn main() -> Result<(), eryx::Error> {
    // Use Sandbox::embedded() for zero-config setup (requires `embedded` feature)
    let sandbox = Sandbox::embedded().build()?;

    let result = sandbox.execute("print('Hello from Python!')").await?;

    println!("Output: {}", result.stdout_text());
    Ok(())
}

Re-exports§

pub use net::ConnectionManager;
pub use net::DEFAULT_BLOCKED_NETWORKS;
pub use net::HttpRule;
pub use net::NetConfig;
pub use net::NetTraffic;
pub use net::Resolver;
pub use net::TcpError;
pub use net::TlsError;
pub use package::ExtractedPackage;
pub use package::PackageFormat;
pub use pool::PoolConfig;
pub use pool::PoolError;
pub use pool::PoolStats;
pub use pool::PooledSandbox;
pub use pool::SandboxPool;
pub use replay::CallbackJournal;
pub use replay::CallbackJournalEntry;
pub use replay::CallbackOutcome;
pub use replay::ReplayCallback;
pub use replay::ReplayState;
pub use replay::SuspendedCallback;
pub use secrets::FileScrubPolicy;
pub use secrets::OutputScrubPolicy;
pub use secrets::SecretConfig;
pub use secrets::scrub_placeholders;
pub use secrets::scrub_placeholders_bytes;
pub use session::InProcessSession;
pub use session::PythonStateSnapshot;
pub use session::Session;
pub use session::SessionExecutor;
pub use session::SnapshotMetadata;
pub use session::VfsConfig;unstable-vfs
pub use session::VolumeMount;unstable-vfs
pub use session::VolumeSource;unstable-vfs

Modules§

bundlepreinit
The file format for a precompiled runtime that can be rebuilt.
cache
Component caching for faster sandbox creation.
callback_handlerunstable-internals
Shared callback, network, and trace handling for sandbox execution.
embeddedembedded
Embedded resources for zero-configuration sandboxes.
embedded_stdlibembedded-stdlib
Embedded Python standard library for use with custom runtimes.
net
Networking support for the sandbox.
package
Package extraction and management.
pool
Managed pool of warm sandbox instances for high-throughput scenarios.
preinitpreinit
Pre-initialization support for capturing Python memory state.
replay
Callback result replay.
secrets
Secrets management with placeholder substitution.
session
Session-based execution for persistent WASM state.
state
Marker types for compile-time builder state tracking.
vfsunstable-vfs
Virtual filesystem support for sandboxed file operations.

Structs§

CallbackRequestunstable-internals
Request to invoke a callback from Python code.
CancellationToken
A token for cancelling an execution or session state operation.
DynamicCallback
A callback defined entirely at runtime.
DynamicCallbackBuilder
Builder for DynamicCallback.
Error
The main error type for Eryx operations.
ExecuteResult
Result of executing Python code in the sandbox.
ExecuteStats
Statistics about sandbox execution.
ExecutionHandle
Handle to a cancellable execution.
ExecutionOutput
Output from executing Python code in the WASM sandbox.
OutputRequestunstable-internals
Request to stream output from Python code in real-time.
PrecompiledArtifactembedded or preinit
A shared pre-compiled component with an optional content-derived cache key.
PrefixCallback
One callback that handles every dotted name under a prefix.
PythonExecutor
The Python executor that manages the WASM runtime.
ReplayOutcome
Result of a replay-aware execution via Sandbox::execute_with_journal.
ResourceLimits
Resource limits for sandbox execution.
RuntimeLibrary
A composable set of callbacks with Python wrappers and type stubs.
Sandbox
A sandboxed Python execution environment.
SandboxBuilder
Builder for constructing a Sandbox.
Schema
An opaque JSON Schema type.
SharedEngineConfig
Settings for the process-wide shared engine and its warm-instance pool.
TraceEvent
An execution trace event.
TraceRequestunstable-internals
Request to report a trace event from Python code.

Enums§

CallbackError
Errors that can occur during callback execution.
CallbackHostResultunstable-internals
The result a callback handler sends back to the invoke host import.
CpuFeatureLevel
CPU feature level for AOT compilation.
ErrorKind
What went wrong, as a matchable category. See Error::kind.
InstanceAllocator
How wasmtime allocates sandbox instances. See SharedEngineConfig::with_allocator.
IpNet
An IP network address, either IPv4 or IPv6.
NetRequestunstable-internals
Request for a network operation from Python code.
TraceEventKind
The kind of trace event.

Constants§

POSITIONAL_ARGS_KEY
The key a call under a prefix callback carries its positional arguments under, in the arguments object the guest sends: {"__eryx_args__": [1, 2], "kw": 3} for f(1, 2, kw=3). It is present only when there are any, and the guest rejects a keyword argument of this name.
STREAM_BYTES_LIMIT
Most bytes one execution may queue for each of the trace and output streams, each queued event or chunk also being charged a small fixed overhead. The imports that feed them can’t wait for a slow consumer, so anything past this is dropped from the stream (captured stdout/stderr in the final result are unaffected) and the execution reports ExecutionOutput::stream_truncated. A consumer that builds its output from the stream, like eryx-server, can’t keep more than this.

Traits§

Callback
A callback that Python code can invoke.
JsonSchema
Re-export the JsonSchema derive macro.
OutputHandler
Handler for streaming output during execution.
TraceHandler
Handler for trace events during execution.
TypedCallback
A strongly-typed callback with compile-time schema generation.

Functions§

configure_shared_engine
Configure the process-wide shared engine and its warm-instance pool.
empty_schema
Helper function to create an empty parameters schema (no arguments).

Type Aliases§

PrefixHandler
A boxed async handler for a PrefixCallback: it receives the full name the guest called, its keyword arguments (an object) and its positional arguments.

Attribute Macros§

callbackmacros
Attribute macro for defining sandbox callbacks with minimal boilerplate.

Derive Macros§

JsonSchema
Re-export the JsonSchema derive macro.