Skip to main content

cVisor — Python SDK

A ctypes FFI wrapper over the libcvisor C ABI. Linux-only.

Quick try (Docker)

Drop into a Python REPL with cvisor installed, from any machine with Docker:

docker run -it --rm \
  --security-opt seccomp=unconfined --security-opt apparmor=unconfined \
  ghcr.io/astral-sh/uv:python3.12-alpine \
  uv run --with cvisor python
>>> from cvisor import Sandbox
>>> sb = Sandbox()
>>> print(sb.run("echo hi; uname -n").stdout)
hi
cvisor

The --security-opt flags are required: cVisor installs its own seccomp filter, which Docker's default profiles block. An Alpine (musl) image is needed — the published wheels are musllinux-tagged.

Install (uv)

uv add cvisor

Usage

from cvisor import Sandbox

with Sandbox() as sb:
    out = sb.run("echo hello")
    print(out.stdout)   # "hello\n"
    print(out.stderr)   # ""

Sandbox.run(cmd) blocks until the sandboxed command exits and returns an Output with .stdout / .stderr (str), .stdout_bytes / .stderr_bytes, and .exit_code (int, shell convention: the command's status, or 128+signo if it was killed by a signal).

Timeouts

Sandbox.run(cmd, timeout_ms=...) SIGKILLs the guest after timeout_ms milliseconds; a timed-out run reports exit code 137:

out = sb.run("sleep 30", timeout_ms=300)
assert out.exit_code == 137

Network policy

Sandbox.set_allow_network(allow) controls outbound INET/INET6 networking (allowed by default):

sb.set_allow_network(False)  # deny outbound networking

Interactive console

Launch an IPython REPL with a live sandbox preloaded:

uv run --extra console cvisor   # or: python -m cvisor
cVisor interactive console
  sb          -> a Sandbox instance
  sh("cmd")   -> run a shell command in the sandbox, printing stdout/stderr
  Sandbox     -> create your own: Sandbox()

In [1]: sh("echo hello; uname -n")
hello
cvisor

Without the console extra (IPython) it falls back to the stdlib REPL.

Development

The SDK loads libcvisor.so. Build it from the repo root and point the SDK at it via the CVISOR_LIB environment variable, or let the package resolve a copy bundled under cvisor/_native/:

# from the repo root — builds libcvisor.so into cvisor/_native/
cargo xtask ffi

# run the tests with uv
cd sdks/python
uv run pytest

Download files

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

Source Distribution

cvisor-0.2.0.tar.gz (617.6 kB view details)

Uploaded Source

Built Distribution

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

cvisor-0.2.0-py3-none-any.whl (602.7 kB view details)

Uploaded Python 3

File details

Details for the file cvisor-0.2.0.tar.gz.

File metadata

  • Download URL: cvisor-0.2.0.tar.gz
  • Upload date:
  • Size: 617.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cvisor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 75200a1032648357cf16d60bb6e9bd587bb5290bc2ae469e5f58b3c9af9b8a36
MD5 bd1b0d1c5d5be81c5ddbe31f3dcb92e1
BLAKE2b-256 4a314d187768a2879c0933b74dde788215cdc60300931979e10191056054b82e

See more details on using hashes here.

File details

Details for the file cvisor-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cvisor-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 602.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cvisor-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b0cc107525aef224dfa46f154deb0fcf556263fc0f570d140ec5c08dbf10c58
MD5 d8b6b6fc9393b79d530dd7b3b43ae38e
BLAKE2b-256 04f2ab7e7fb72f911b145a1508407e6dbd1e3223da74da1c01d91732a0d35429

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

4 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page