Get up and running with BoxLite Python SDK in 5 minutes.
pip install boxliteRequirements:
- Python 3.10 or later
- pip 20.0+
Verify Installation:
python3 -c "import boxlite; print(boxlite.__version__)"
# Output: installed boxlite package versionCreate a file hello.py:
import asyncio
import boxlite
async def main():
# Create a box and run a command
async with boxlite.SimpleBox(image="python:slim") as box:
result = await box.exec("python", "-c", "print('Hello from BoxLite!')")
print(result.stdout)
# Output: Hello from BoxLite!
if __name__ == "__main__":
asyncio.run(main())Run it:
python hello.pyWhat's happening:
- BoxLite pulls the
python:slimOCI image (first run only) - Creates a lightweight VM with the image
- Executes the Python command inside the VM
- Streams output back to your application
- Automatically cleans up when the context exits
Create a file codebox.py:
import asyncio
import boxlite
async def main():
# Execute untrusted code safely
code = """
import requests
response = requests.get('https://api.github.com/zen')
print(response.text)
"""
async with boxlite.CodeBox() as codebox:
# Install packages explicitly before use
await codebox.install_package("requests")
result = await codebox.run(code)
print(result)
if __name__ == "__main__":
asyncio.run(main())Run it:
python codebox.pyWhat's happening:
- CodeBox executes the code in complete isolation
- Returns the output
- Your host system remains completely safe
Note: Each run() call executes in a fresh Python process. Variables, imports, and state do not persist between calls. To share state, combine code into a single run() call.
BoxLite includes 9 comprehensive Python examples:
# Clone the repository
git clone https://github.com/boxlite-labs/boxlite.git
cd boxlite
# Build Python SDK
make dev:python
# Run examples
python examples/python/01_getting_started/run_simplebox.py
python examples/python/01_getting_started/run_codebox.py
python examples/python/05_browser_desktop/automate_with_playwright.py
python examples/python/05_browser_desktop/automate_desktop.py
python examples/python/03_lifecycle/manage_lifecycle.py
python examples/python/01_getting_started/list_boxes.py
python examples/python/03_lifecycle/share_across_processes.py
python examples/python/04_interactive/run_interactive_shell.py
python examples/python/07_advanced/use_native_api.pyExamples overview:
- run_simplebox.py - Foundation patterns (
01_getting_started/) - run_codebox.py - AI code execution (
01_getting_started/) - automate_with_playwright.py - Browser automation (
05_browser_desktop/) - automate_desktop.py - Desktop automation (
05_browser_desktop/) - manage_lifecycle.py - Box lifecycle management (
03_lifecycle/) - list_boxes.py - Runtime introspection (
01_getting_started/) - share_across_processes.py - Multi-process operations (
03_lifecycle/) - run_interactive_shell.py - Interactive shells (
04_interactive/) - use_native_api.py - Low-level Rust API (
07_advanced/)
- Python SDK README - Complete API reference
- Core API (Boxlite, BoxOptions, Box, Execution)
- Higher-level APIs (SimpleBox, CodeBox, BrowserBox, ComputerBox)
- API Patterns (async/await, context managers, streaming I/O)
- Configuration Reference (resources, volumes, ports)