Python SDK for Blokhus, Mistral AI's microVM sandbox platform
Actively maintained. Last release 4 weeks ago. A safe choice.
pip install mistralai-blokhusREADME as published on PyPI with version 0.215.0.
mistralai-blokhus
Typed async Python client for Blokhus, Mistral AI's microVM sandbox platform. Commands use HTTP/SSE, files use streamed HTTP, and terminals and port forwarding use WebSockets. Requires Python 3.12 or later.
Install
uv add mistralai-blokhus
The import package is blokhus.
Configure
Set MISTRAL_API_KEY, or pass a ClientConfig to override the key or the
endpoint. The key is sent as Authorization: Bearer <key>.
Service accounts set MISTRAL_SA_TOKEN_PATH to the file that holds their token.
The client reads the file on every request, so it follows token rotation. An
explicit api_key takes priority over the token, and the token over
MISTRAL_API_KEY.
from blokhus import ClientConfig, Sandbox
config = ClientConfig(base_url="https://example.com/v1/blokhus", api_key="...")
async with await Sandbox.create(image="python:3.12-slim", config=config) as sandbox:
print((await sandbox.commands.exec("printf hello")).stdout)
Run a command
import asyncio
from blokhus import Sandbox
async def main() -> None:
async with await Sandbox.create(image="python:3.12-slim") as sandbox:
result = await sandbox.commands.exec("printf hello")
print(result.stdout)
await sandbox.files.write("/tmp/example.txt", "hello")
print(await sandbox.files.read("/tmp/example.txt"))
asyncio.run(main())