Skip to main content

Installation

pip install boxlite
Requirements:
  • Python 3.10 or later
  • pip 20.0+
Verify Installation:
python3 -c "import boxlite; print(boxlite.__version__)"
# Output: 0.4.4

Basic Execution

1

Create 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())
2

Run it

python hello.py
What’s happening:
  1. BoxLite pulls the python:slim OCI image (first run only)
  2. Creates a lightweight VM with the image
  3. Executes the Python command inside the VM
  4. Streams output back to your application
  5. Automatically cleans up when the context exits

Code Execution (AI Agents)

1

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:
        result = await codebox.run(code)
        print(result)


if __name__ == "__main__":
    asyncio.run(main())
2

Run it

python codebox.py
What’s happening:
  1. CodeBox automatically installs required packages (requests)
  2. Executes the code in complete isolation
  3. Returns the output
  4. Your host system remains completely safe

Running Examples

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/simplebox_example.py
python examples/python/codebox_example.py
python examples/python/browserbox_example.py
python examples/python/computerbox_example.py
python examples/python/lifecycle_example.py
python examples/python/list_boxes_example.py
python examples/python/cross_process_example.py
python examples/python/interactivebox_example.py
python examples/python/native_example.py
Examples overview:
#ExampleDescription
1simplebox_example.pyFoundation patterns
2codebox_example.pyAI code execution
3browserbox_example.pyBrowser automation
4computerbox_example.pyDesktop automation
5lifecycle_example.pyBox lifecycle management
6list_boxes_example.pyRuntime introspection
7cross_process_example.pyMulti-process operations
8interactivebox_example.pyInteractive shells
9native_example.pyLow-level Rust API

Next Steps