Skip to main content

Embed isolated microVM sandboxes directly in your Python code — local (embedded) or smolfleet cloud.

Project description

smol — Python SDK

Embed isolated microVM sandboxes directly in your Python code. Same API locally (embedded engine, no server) or against the smolfleet cloud — the backend is chosen via ConnectOptions / SMOL_CLOUD_TOKEN. Mirrors the Node SDK.

Supported platforms (native local transport): macOS Apple Silicon, and Linux x64/arm64 with glibc ≥ 2.34 (RHEL 9, Ubuntu 22.04+, Debian 12, Amazon Linux 2023; the wheel is tagged manylinux_2_34). The cloud transport works anywhere the wheel installs. Not yet published: macOS Intel, and glibc < 2.34.

from smol import Machine, MachineConfig, ResourceSpec

# Local (embedded microVM) — boots in-process, no server.
with Machine.create(MachineConfig(resources=ResourceSpec(cpus=2, memory_mb=1024, network=True))) as m:
    res = m.run("python:3.12", ["python", "-c", "print(2 ** 10)"])
    res.assert_success()
    print(res.stdout)            # 1024
    m.write_file("/tmp/in.txt", "hi")
    print(m.read_file("/tmp/in.txt").decode())

# Cloud (smolfleet) — same API, just point at the cloud.
from smol import ConnectOptions
with Machine.create(
    MachineConfig(image="alpine:3.20"),
    ConnectOptions(target="cloud", api_key="smk_…"),  # or set SMOL_CLOUD_TOKEN
) as m:
    print(m.exec(["echo", "hi"]).stdout)

Architecture

  • Pure-Python layer (python/smol): Machine, transports, types, errors — zero third-party deps (the cloud transport uses only urllib).
  • Native core (src/lib.rs, crate smol-py): a pyo3 extension that links the smolvm engine in-process for the local path — the Python analogue of the smol-node NAPI crate. The local API is synchronous (the engine blocks).
  • Cloud transport: a REST client to smolfleet /v1 whose request/response shapes match smolfleet's OpenAPI contract (Bearer smk_…).

API

  • Machine.create(config=None, conn=None) — create and start a machine.
  • machine.exec(command, opts=None) / machine.run(image, command, opts=None)ExecResult
  • machine.read_file(path)bytes / machine.write_file(path, data, mode=None)
  • machine.pull_image(image) / machine.list_images() (local)
  • machine.stop() / machine.delete() / machine.state()
  • Use it as a context manager to auto-delete() on exit.
  • Errors are typed: SmolError (with .code), ExecutionError, NotSupportedError, InvalidConfigError.

ExecResult has .exit_code, .stdout, .stderr, .success, .output, and .assert_success().

Install / build from source

The cloud path is pure Python. The local path needs the native extension, which links libkrun from the sibling smolvm repo (three levels up).

python -m venv .venv && . .venv/bin/activate
pip install maturin
# Build + install the native extension (points at the repo's bundled libkrun):
LIBKRUN_BUNDLE=../../../lib maturin develop

To boot local microVMs the engine needs a code-signed boot helper carrying the macOS com.apple.security.hypervisor entitlement (the Python process itself does not). Point it at one (and the libkrun dir):

SMOLVM_BOOT_BINARY=../../../target/release/smolvm \
SMOLVM_LIB_DIR=../../../lib \
python your_script.py

On Linux the host needs /dev/kvm.

Tests

python tests/test_unit.py        # error parsing + path encoding (no VM/network)
python tests/test_cloud_mock.py  # cloud transport vs a mock /v1 (no VM/network)
# Local VM boot (needs the native build + the env above):
SMOLVM_BOOT_BINARY= SMOLVM_LIB_DIR= .venv/bin/python tests/test_local_e2e.py

License

Apache-2.0

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.

smolmachines-1.3.6-cp39-abi3-manylinux_2_34_x86_64.whl (49.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

smolmachines-1.3.6-cp39-abi3-manylinux_2_34_aarch64.whl (48.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ ARM64

smolmachines-1.3.6-cp39-abi3-macosx_11_0_arm64.whl (37.6 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file smolmachines-1.3.6-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for smolmachines-1.3.6-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6d56267a59505f477b2b726a5edc4e470be372fececf8603a278672c0fbc006e
MD5 5e0c1e3f5a1dfa2cce1a680aac2c981c
BLAKE2b-256 877be84265a4981732226a0f44f522fcc9b5d37591a3dab4aea02201e7d869f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for smolmachines-1.3.6-cp39-abi3-manylinux_2_34_x86_64.whl:

Publisher: release.yml on smol-machines/smol

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smolmachines-1.3.6-cp39-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for smolmachines-1.3.6-cp39-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 155ccc0b49e9c2a07ca17448e3d424a2b1bb39257319fdcfd8811f911b73f6f8
MD5 d89307ada5db108b9cbca522117ab74e
BLAKE2b-256 15ba33e62b5a93cb08621b3c8a80f3ef3039a71ef38e847c65d853b80e832141

See more details on using hashes here.

Provenance

The following attestation bundles were made for smolmachines-1.3.6-cp39-abi3-manylinux_2_34_aarch64.whl:

Publisher: release.yml on smol-machines/smol

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smolmachines-1.3.6-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for smolmachines-1.3.6-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f0537935957320771ff1a033024b38b4945d9b21cdfbf86ba4535b24830d43a
MD5 3e0a60082b9a7e9a62f955a9e2334168
BLAKE2b-256 bcf7e0c0c99b40757ed248d3c83a86c5c7cddca95a736abf3a710fbe5f976ad6

See more details on using hashes here.

Provenance

The following attestation bundles were made for smolmachines-1.3.6-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on smol-machines/smol

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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