Skip to main content

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_api websocket protocol
  • High-level classes for Daemon, Box, BoxFs, BoxCheckpoint, and BoxShell
  • pytest smoke and gated full e2e coverage

Support

  • Secure host path: Linux x86_64, Linux arm64 / aarch64
  • macOS arm64: dev/test only with SAGENS_ISOLATION_MODE=compat and SAGENS_INSECURE_COMPAT=1
  • Python versions: 3.11+ (pyo3 abi3-py311; classifiers for 3.11, 3.12, and 3.13)
  • Linux secure mode requires /dev/kvm, delegated cgroup access through SAGENS_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_x86_64.whl (104.0 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.39+ x86-64

sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_aarch64.whl (103.7 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.39+ ARM64

sagens-0.0.0.0.4-3-cp311-abi3-macosx_11_0_arm64.whl (83.0 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 259131e46814901d0f58cfb7863a6c81f02d867952187c05c53f1f83db10b183
MD5 88b966081ebd91b46b458b89ce66549a
BLAKE2b-256 dd6bf771efc8a191eb1beafa2766ee0dab631e6fd469954487671d05fa636040

See more details on using hashes here.

File details

Details for the file sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_aarch64.whl.

File metadata

File hashes

Hashes for sagens-0.0.0.0.4-cp311-abi3-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 48206f4283f17cbfe24eaf1e53806b8aa5950b3ce3c329c3152c41752cfd1194
MD5 59c4a80ee7ddadb637bc789e51ff5d3d
BLAKE2b-256 ac141cae15eb0398df258ba91e748ae0386b671d09e77e976c6910ef15eb185a

See more details on using hashes here.

File details

Details for the file sagens-0.0.0.0.4-3-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sagens-0.0.0.0.4-3-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d138a542771875dc3039d80603d82994a5f07b82a76f4c34dd7bbb03b9271edd
MD5 2af69ed5bd18ea0b8c1ba212db94be7a
BLAKE2b-256 c9115a1da6bb6043f394b5e924b60451b8c4220b83dec9a6fa04f556b5c4d098

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page