1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Isola runtime embedding APIs.
//!
//! This crate exposes three public modules:
//! - [`sandbox`]: build/load guest templates and run sandboxes.
//! - [`host`]: host-side traits for hostcalls, HTTP, and output sinks.
//! - [`value`]: opaque CBOR values exchanged across the host/guest boundary.
//!
//! # Quickstart
//!
//! Download and extract the Python runtime bundle first:
//! ```bash
//! VERSION=v0.x.y
//! curl -L -o isola-python-runtime.tar.gz "https://github.com/brian14708/isola/releases/download/${VERSION}/isola-python-runtime.tar.gz"
//! tar xzf isola-python-runtime.tar.gz
//! mkdir -p isola-python-runtime/cache
//! ```
//! The archive extracts into `isola-python-runtime/` with `bin/python.wasm` and
//! `lib/`. Point `.build(...)` and `.mount(...)` at those extracted paths.
//!
//! ```no_run
//! use isola::{
//! host::{Host, NoopOutputSink},
//! sandbox::{DirPerms, FilePerms, SandboxOptions, SandboxTemplate, args},
//! };
//!
//! #[derive(Clone, Default)]
//! struct MyHost;
//!
//! #[async_trait::async_trait]
//! impl Host for MyHost {}
//!
//! #[tokio::main(flavor = "current_thread")]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let template = SandboxTemplate::builder()
//! .cache(Some("./isola-python-runtime/cache".into()))
//! .max_memory(64 * 1024 * 1024)
//! .mount(
//! "./isola-python-runtime/lib",
//! "/lib",
//! DirPerms::READ,
//! FilePerms::READ,
//! )
//! .build("./isola-python-runtime/bin/python.wasm")
//! .await?;
//!
//! let mut sandbox = template
//! .instantiate(MyHost, SandboxOptions::default())
//! .await?;
//!
//! sandbox
//! .eval_script("def add(a, b):\n\treturn a + b", NoopOutputSink::shared())
//! .await?;
//!
//! let output = sandbox.call("add", args!(1_i64, 2_i64)?).await?;
//! let result: i64 = output
//! .result
//! .ok_or_else(|| std::io::Error::other("missing result"))?
//! .to_serde()?;
//! assert_eq!(result, 3);
//!
//! Ok(())
//! }
//! ```
/// Host integration traits and transport types.
/// Runtime module and sandbox lifecycle APIs.
/// Opaque CBOR value helpers.