Skip to main content Switch to mobile version pydantic-ai-kosa8 0.1.0 kosa8 Cloud microVM sandboxes as Pydantic AI workspaces
pip install pydantic-ai-kosa8==0.1.0 Copy PIP instructions
Run a Pydantic AI agent's commands and file edits in a kosa8 Cloud microVM sandbox instead of on your machine.
Kosa8Sandbox is a capability that supplies the run's workspace. Compose it with capabilities that use a workspace, such as Coder, Shell and FileSystem from Pydantic AI Harness, or your own tools through ctx.workspace.
pip install pydantic-ai-kosa8 Set KOSA8_API_KEY to a kosa8 Cloud API key (create one at app.kosa8.com). The Starter plan is free with no card and includes $10 of one-time kosa8 Cloud usage; paid plans start at $29 a month (pricing).
from pydantic_ai import Agent from pydantic_ai_harness.coder import Coder from pydantic_ai_kosa8 import Kosa8Sandbox agent = Agent('anthropic:claude-sonnet-4-5', capabilities=[Kosa8Sandbox(ttl_s=3600), Coder()]) result = agent.run_sync('Clone https://github.com/pydantic/pydantic-ai and summarize how capabilities work.') print(result.output) The sandbox is created on the first workspace operation. Commands start in /workspace (set working_dir= to change it).
Continue in the same sandbox
The sandbox's WorkspaceRef is in the message history and in result.workspace.ref. A later run with that history continues in the same sandbox, and kosa8 wakes it if it was asleep:
again = agent.run_sync('Now run the tests.', message_history=result.all_messages()) Or pass the ref yourself: agent.run_sync(..., workspace=Kosa8Sandbox().backend(ref)).
Ending a run does not delete the sandbox. Delete it when you are done:
await Kosa8Sandbox().destroy(result.workspace.ref) or give new sandboxes a lifetime with ttl_s (60 s to 90 days), after which kosa8 deletes them, and sleep_after_s to put an idle one to sleep.
Errors from kosa8 Cloud are typed: Kosa8PaymentRequiredError (402, with upgrade_url), Kosa8OrgFrozenError (423), Kosa8RateLimitError (429) and Kosa8Error for the rest. A sandbox that was deleted raises Pydantic AI's WorkspaceUnavailableError.
Kosa8WorkspaceBackend implements Pydantic AI's WorkspaceBackend and SupportsCommands protocols. Each command is one exec request to the kosa8 Cloud API, run by a small POSIX sh wrapper that:
starts the command in a process group of its own, with stdin at EOF;
returns as soon as the command exits, even if a background child keeps its output open;
enforces timeout= inside the sandbox and kills the process group when it fires, or when the call is cancelled;
returns stdout and stderr base64-encoded, so any bytes survive (undecodable bytes become U+FFFD), and reads large output back in chunks.
File operations (read, write, stat, list, remove, realpath) come from Pydantic AI's Workspace, which derives them through the sandbox's shell, so path handling and error types match Pydantic AI's other backends. The sandbox image needs sh, base64, dd, find and the other coreutils, which kosa8's templates include.
tests/test_harness.py runs an Agent with Pydantic AI Harness's Shell and FileSystem capabilities on top of Kosa8Sandbox, and checks that their write_file, run_command and read_file calls land in the sandbox. It runs against the bundled fake kosa8 API, and against kosa8 Cloud in the live tier.
The backend passes Pydantic AI's WorkspaceBackendSuite conformance suite (39 of 40 rules run and pass against the bundled fake kosa8 API; the 40th is for the optional SupportsRealpath protocol, which this backend leaves to the shell).
Each kosa8 sandbox is a microVM. kosa8's SOC 2 audit is in progress; kosa8 does not have a SOC 2 report yet. See kosa8.com/security.
uv venv && uv pip install -e . pytest ruff mypy pytest # unit tests and the conformance suite, against a local fake API ruff check . && mypy The live tier runs the same conformance suite against kosa8 Cloud. It creates sandboxes (each with a 15-minute lifetime as a backstop) and deletes them:
PYDANTIC_AI_KOSA8_LIVE=1 KOSA8_API_KEY=... pytest -m kosa8_live pydantic_ai_kosa8/_kosa8.py is the kosa8 Cloud client shared, unchanged, with langchain-kosa8, inspect-kosa8 and harbor-kosa8.
agents kosa8 microvm pydantic-ai sandbox workspace
Intended Audience Developers
License OSI Approved :: MIT License
Programming Language Python :: 3
Topic Scientific/Engineering :: Artificial Intelligence
Release files for pydantic-ai-kosa8 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 67.5 kB
Release files / pydantic_ai_kosa8-0.1.0.tar.gz
Security for pydantic-ai-kosa8 0.1.0
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.
Release history Release notifications | RSS feed
Nov 29, 2026 2 release files No provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation




