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-vfspub use session::VolumeMount;unstable-vfspub use session::VolumeSource;unstable-vfs
Modules§
- bundle
preinit - The file format for a precompiled runtime that can be rebuilt.
- cache
- Component caching for faster sandbox creation.
- callback_
handler unstable-internals - Shared callback, network, and trace handling for sandbox execution.
- embedded
embedded - Embedded resources for zero-configuration sandboxes.
- embedded_
stdlib embedded-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.
- preinit
preinit - 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.
- vfs
unstable-vfs - Virtual filesystem support for sandboxed file operations.
Structs§
- Callback
Request unstable-internals - Request to invoke a callback from Python code.
- Cancellation
Token - A token for cancelling an execution or session state operation.
- Dynamic
Callback - A callback defined entirely at runtime.
- Dynamic
Callback Builder - Builder for
DynamicCallback. - Error
- The main error type for Eryx operations.
- Execute
Result - Result of executing Python code in the sandbox.
- Execute
Stats - Statistics about sandbox execution.
- Execution
Handle - Handle to a cancellable execution.
- Execution
Output - Output from executing Python code in the WASM sandbox.
- Output
Request unstable-internals - Request to stream output from Python code in real-time.
- Precompiled
Artifact embeddedorpreinit - A shared pre-compiled component with an optional content-derived cache key.
- Prefix
Callback - One callback that handles every dotted name under a prefix.
- Python
Executor - The Python executor that manages the WASM runtime.
- Replay
Outcome - Result of a replay-aware execution via
Sandbox::execute_with_journal. - Resource
Limits - Resource limits for sandbox execution.
- Runtime
Library - A composable set of callbacks with Python wrappers and type stubs.
- Sandbox
- A sandboxed Python execution environment.
- Sandbox
Builder - Builder for constructing a
Sandbox. - Schema
- An opaque JSON Schema type.
- Shared
Engine Config - Settings for the process-wide shared engine and its warm-instance pool.
- Trace
Event - An execution trace event.
- Trace
Request unstable-internals - Request to report a trace event from Python code.
Enums§
- Callback
Error - Errors that can occur during callback execution.
- Callback
Host Result unstable-internals - The result a callback handler sends back to the
invokehost import. - CpuFeature
Level - CPU feature level for AOT compilation.
- Error
Kind - What went wrong, as a matchable category. See
Error::kind. - Instance
Allocator - How wasmtime allocates sandbox instances. See
SharedEngineConfig::with_allocator. - IpNet
- An IP network address, either IPv4 or IPv6.
- NetRequest
unstable-internals - Request for a network operation from Python code.
- Trace
Event Kind - 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}forf(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, likeeryx-server, can’t keep more than this.
Traits§
- Callback
- A callback that Python code can invoke.
- Json
Schema - Re-export the
JsonSchemaderive macro. - Output
Handler - Handler for streaming output during execution.
- Trace
Handler - Handler for trace events during execution.
- Typed
Callback - 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§
- Prefix
Handler - 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§
- callback
macros - Attribute macro for defining sandbox callbacks with minimal boilerplate.
Derive Macros§
- Json
Schema - Re-export the
JsonSchemaderive macro.