[!WARNING] EXPERIMENTAL: The APIs and tools described here are experimental and are not meant for production use.
This guide shows you how to get started with the gVisor Python SDK to run commands inside a sandboxed environment.
runsc installed and available
in your PATH. See the Installation Guide for
details.Install the gvisor package using pip:
pip install gvisor
Here is a minimalist runnable example demonstrating sandbox initialization and
command execution (uname -a) using context manager syntax:
from gvisor import Sandbox
with Sandbox() as sb:
stdout, stderr = sb.exec("uname", "-a")
print(f"Stdout: {stdout.strip()}")
main.py.Run the application:
python3 main.py
You should see output similar to:
Stdout: Linux 5.15.0-gvisor
This indicates the command successfully ran inside the gVisor sandbox, which emulates a Linux kernel.
For more examples and advanced usage patterns, see the complete CLI recipes.
For detailed API documentation, see the API Reference.