Python bindings and client APIs for sagens microVM sandboxes.
Project description
sagens Python
Python package for managing sagens daemons and BOX workspaces.
What it includes
- Rust bindings for daemon lifecycle helpers and smoke-test server bootstrap
- A synchronous Python client for the
box_apiwebsocket protocol - High-level classes for
Daemon,Box,BoxFs,BoxCheckpoint, andBoxShell pytestsmoke and gated full e2e coverage
Support
- Secure host path: Linux
x86_64, Linuxarm64/aarch64 - macOS
arm64: dev/test only withSAGENS_ISOLATION_MODE=compatandSAGENS_INSECURE_COMPAT=1 - Python versions:
3.11+(pyo3abi3-py311; classifiers for3.11,3.12, and3.13) - Linux secure mode requires
/dev/kvm, delegated cgroup access throughSAGENS_CGROUP_PARENT, and Linux Landlock support - The current backend does not support Windows or secure macOS runtime release paths
Quickstart
Build the host binary, install the package, and run Python inside a BOX:
cargo run --bin xtask -- dev --python-package-root python
python3 -m pip install -e python[test]
python3 - <<'PY'
from tempfile import TemporaryDirectory
from sagens import Daemon
with TemporaryDirectory() as state_dir:
with Daemon.start(state_dir=state_dir) as daemon:
box = daemon.create_box()
# Settings are stop-only, so set them before start or after stop.
box.set("memory_mb", 512)
box.set("fs_size_mib", 1024)
box.set("cpu_cores", 2)
box.set("network_enabled", False)
box.start()
box.fs.write("/workspace/input.txt", b"hello from python\n")
result = box.exec_python(
[
"-c",
(
"from pathlib import Path; "
"text = Path('/workspace/input.txt').read_text(); "
"print(text.strip().upper())"
),
]
)
print(result.stdout.decode().strip())
box.stop()
PY
BOX settings examples
All BOX settings are updated with box.set(...) while the BOX is stopped:
box.set("memory_mb", 512) # Guest RAM in MiB.
box.set("fs_size_mib", 1024) # Persistent workspace disk in MiB.
box.set("cpu_cores", 2)
box.set("network_enabled", True) # Enable network in compat mode only.
box.set("network_enabled", False) # Disable network.
Named Images
See examples/named_images.py for building a local
chromium image and creating two BOXes from it through the SDK.
Local development
Build the host binary and stage it into the package layout:
cargo run --bin xtask -- dev --python-package-root python
Install the package in editable mode:
python3 -m pip install -e python[test]
Run smoke tests:
python3 -m pytest python/tests -q
Run full e2e when runtime assets and env are ready:
SAGENS_RUN_E2E=1 python3 -m pytest python/tests/test_e2e.py -q
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 104.0 MB
- Tags: CPython 3.11+, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
259131e46814901d0f58cfb7863a6c81f02d867952187c05c53f1f83db10b183
|
|
| MD5 |
88b966081ebd91b46b458b89ce66549a
|
|
| BLAKE2b-256 |
dd6bf771efc8a191eb1beafa2766ee0dab631e6fd469954487671d05fa636040
|
File details
Details for the file sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_aarch64.whl.
File metadata
- Download URL: sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_aarch64.whl
- Upload date:
- Size: 103.7 MB
- Tags: CPython 3.11+, manylinux: glibc 2.39+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48206f4283f17cbfe24eaf1e53806b8aa5950b3ce3c329c3152c41752cfd1194
|
|
| MD5 |
59c4a80ee7ddadb637bc789e51ff5d3d
|
|
| BLAKE2b-256 |
ac141cae15eb0398df258ba91e748ae0386b671d09e77e976c6910ef15eb185a
|
File details
Details for the file sagens-0.0.0.0.4-3-cp311-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: sagens-0.0.0.0.4-3-cp311-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 83.0 MB
- Tags: CPython 3.11+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d138a542771875dc3039d80603d82994a5f07b82a76f4c34dd7bbb03b9271edd
|
|
| MD5 |
2af69ed5bd18ea0b8c1ba212db94be7a
|
|
| BLAKE2b-256 |
c9115a1da6bb6043f394b5e924b60451b8c4220b83dec9a6fa04f556b5c4d098
|