Skip to main content

smolagents-kosa8

kosa8: Zero Trust cybersecurity infrastructure for AI agents. Every agent sealed in its own microVM. Every action verified and recorded.

Run a smolagents CodeAgent's Python actions in a kosa8 Cloud microVM sandbox instead of on your machine.

Kosa8Executor is a smolagents remote Python executor, built on RemotePythonExecutor like the E2B, Modal and Blaxel executors. The agent and the model stay on your machine; each code step runs in the sandbox's long-lived Python process. Tested against smolagents 1.26.

Install

pip install smolagents-kosa8

Set KOSA8_API_KEY to a kosa8 Cloud API key (create one at app.kosa8.com, or run kosa8 login). The Starter plan is free, no card needed; plans are at kosa8.com/pricing.

Example

from smolagents import CodeAgent, InferenceClientModel
from smolagents_kosa8 import Kosa8Executor

with Kosa8Executor(additional_imports=["numpy"]) as executor:
    agent = CodeAgent(
        tools=[],
        model=InferenceClientModel(),
        executor=executor,
        additional_authorized_imports=["numpy"],
    )
    print(agent.run("Use numpy to compute the mean of the first 20 primes."))

Leaving the with block (or calling executor.cleanup()) deletes the sandbox. A new sandbox also gets a one hour lifetime by default (ttl_s), so a crashed process cannot leave it running.

Pass the same packages to additional_imports (installed in the sandbox) and to the agent's additional_authorized_imports (allowed in the agent's code).

What works

smolagents feature kosa8
State between steps (variables, imports, functions) yes: one Python process per sandbox
final_answer yes, with smolagents' safe JSON encoding; pickle only with allow_pickle=True
Tools (send_tools), including their pip requirements yes
Agent state (send_variables) yes
Images (a PIL.Image as a step's last expression) yes, returned as a PIL.Image
Several runs of one agent, with reset=False or not yes
Managed agents no: smolagents does not support them with remote executors

Packages install with pip through a shell command in the sandbox, so a long install is not held to the code step time limit. Import names map to their distribution (PIL to pillow, sklearn to scikit-learn), and standard library modules are skipped.

Options

Kosa8Executor(additional_imports=None, logger=None, allow_pickle=False, **options):

Option Default
api_key KOSA8_API_KEY, then the key kosa8 login saved kosa8 Cloud API key
base_url https://api.kosa8.com kosa8 Cloud API address
cloud none a ready kosa8.Cloud client
sandbox none an existing persistent sandbox (or its id) to use; the executor never deletes a sandbox it did not create
template "python" kosa8 template for a new sandbox
size template size vCPU x GiB: 0.25x0.5, 0.5x1, 1x2, 2x4, 4x8, 8x16 or 16x32
ttl_s 3600 lifetime of a new sandbox, 60 s to 90 days; None for none
labels none labels for a new sandbox (it also gets integration=smolagents)
create_kwargs none anything else kosa8.Cloud().sandboxes.create takes: env, region, egress, secrets, ...
timeout_s kosa8's limit time limit for one code step
install_timeout_s 600 time limit for one pip install

For example, a sandbox that can reach only PyPI:

Kosa8Executor(create_kwargs={"egress": {"internet": False, "presets": ["pypi"]}})

executor_type="kosa8"

smolagents plans an executor registry through the smolagents.executors entry point group (huggingface/smolagents#2722). This package registers kosa8 there, so once smolagents resolves it, CodeAgent(..., executor_type="kosa8", executor_kwargs={...}) will work too. Until then, pass the executor with executor=.

Tests

uv run --group test pytest                                      # unit tests, against a fake kosa8 Cloud
KOSA8_API_KEY=... uv run --group test pytest tests/test_live.py   # live tier, on kosa8 Cloud

The unit tests cover sandbox creation and cleanup, state between steps, errors, final_answer (and pickle refused by default), tools, variables, images, installs and their failures, and CodeAgent runs with a scripted model. The live tier (skipped without KOSA8_API_KEY) runs a multi-step CodeAgent with a tool and a scripted model on a real sandbox, a second run on the same agent, a package install, an image result and an error, and checks the sandbox is deleted afterwards. No LLM is called.

License

MIT

Metadata

Release files for smolagents-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)

Source distribution for smolagents-kosa8 0.1.0
File Size Uploaded Provenance Actions
smolagents_kosa8-0.1.0.tar.gz 12.0 kB Without provenance Details for smolagents_kosa8-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for smolagents-kosa8 0.1.0
File Interpreter ABI Platform Actions
smolagents_kosa8-0.1.0-py3-none-any.whl Python 3 none any Details for smolagents_kosa8-0.1.0-py3-none-any.whl

Total release size: 20.8 kB

Release files / smolagents_kosa8-0.1.0.tar.gz

Download URL smolagents_kosa8-0.1.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
35518f25808203407b4995e3029fbf200cef6c96e6d9551d5a80121d303605ce
BLAKE2b-256 checksum
How to use checksums
699c81b4c36108bf2c2867777524c6039bc7a9b1273af1661739196df18403a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / smolagents_kosa8-0.1.0-py3-none-any.whl

Download URL smolagents_kosa8-0.1.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb331ab3f8b34bab6e48dd92152f1c33fae14a95800daafae695dec589d8bffd
BLAKE2b-256 checksum
How to use checksums
2a4c01f2c93506e37d48760f91cca988deddda2252abbdb15adad1a893f92e7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Security for smolagents-kosa8 0.1.0

Provenance

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.

No provenance found

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

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page