| Crates.io | eryx |
| lib.rs | eryx |
| version | 0.1.0 |
| created_at | 2025-12-09 18:59:08.842705+00 |
| updated_at | 2025-12-09 18:59:08.842705+00 |
| description | A Python sandbox with async callbacks powered by WebAssembly |
| homepage | |
| repository | https://github.com/sd2k/eryx |
| max_upload_size | |
| id | 1976024 |
| size | 203,367 |
eryx (noun): A genus of sand boas (Erycinae) - non-venomous snakes that live in sand. Perfect for "Python running inside a sandbox."
A Python sandbox with async callbacks powered by WebAssembly.
await invoke("callback_name", ...) to call host-provided functionsasyncio.gather()sys.settrace.pyi) for including in context windowsuse eryx::Sandbox;
#[tokio::main]
async fn main() -> Result<(), eryx::Error> {
let sandbox = Sandbox::builder().build()?;
let result = sandbox.execute(r#"
print("Hello from Python!")
"#).await?;
println!("Output: {}", result.stdout);
Ok(())
}
use eryx::{Callback, CallbackError, Sandbox};
use serde_json::{json, Value};
use std::future::Future;
use std::pin::Pin;
struct GetTime;
impl Callback for GetTime {
fn name(&self) -> &str {
"get_time"
}
fn description(&self) -> &str {
"Returns the current Unix timestamp"
}
fn parameters_schema(&self) -> Value {
json!({
"type": "object",
"properties": {},
"required": []
})
}
fn invoke(
&self,
_args: Value,
) -> Pin<Box<dyn Future<Output = Result<Value, CallbackError>> + Send + '_>> {
Box::pin(async move {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();
Ok(json!(now))
})
}
}
#[tokio::main]
async fn main() -> Result<(), eryx::Error> {
let sandbox = Sandbox::builder()
.with_callback(GetTime)
.build()?;
let result = sandbox.execute(r#"
import asyncio
async def main():
timestamp = await invoke("get_time", {})
print(f"Current time: {timestamp}")
asyncio.run(main())
"#).await?;
println!("Output: {}", result.stdout);
Ok(())
}
Runtime libraries bundle callbacks with Python wrappers and type stubs:
use eryx::{RuntimeLibrary, Sandbox};
let library = RuntimeLibrary::new()
.with_callback(MyCallback)
.with_preamble(include_str!("preamble.py"))
.with_stubs(include_str!("stubs.pyi"));
let sandbox = Sandbox::builder()
.with_library(library)
.build()?;
MIT OR Apache-2.0