Skip to main content

adk-kosa8

Run the code a Google Agent Development Kit (ADK) agent writes in a kosa8 Cloud sandbox instead of on your machine.

  • Kosa8CodeExecutor is an ADK code executor (BaseCodeExecutor). Give it to an LlmAgent as code_executor=, and each Python block the model writes runs in a kosa8 sandbox. You get stdout, stderr, the exit code and output files (saved as ADK artifacts).
  • kosa8_mcp_toolset() gives an agent kosa8's sandbox tools (run, sandbox_create, sandbox_exec, file_read, file_write, sandbox_delete and more) from kosa8's remote MCP server, through ADK's McpToolset.

Install

adk-kosa8 is not on PyPI yet. Until it is, install it from GitHub:

pip install "adk-kosa8 @ git+https://github.com/kosa8ai/adk-kosa8"

Once it is published, this becomes pip install adk-kosa8.

It needs Python 3.11 or newer and installs google-adk[mcp] 2.x and the kosa8 SDK.

Set KOSA8_API_KEY to a kosa8 Cloud API key (create one at app.kosa8.com), or run kosa8 login once. 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).

Quick start: a code executor

from google.adk.agents import LlmAgent
from adk_kosa8 import Kosa8CodeExecutor

root_agent = LlmAgent(
    name="python_coder",
    model="gemini-flash-latest",
    instruction="Solve problems by writing Python in ```python blocks. Answer from the output.",
    code_executor=Kosa8CodeExecutor(),
)

Run it with adk web, adk run or a Runner as usual. By default each ADK session gets one sandbox (the python template). The sandbox is created on the session's first code block and reused for later blocks, so files the code writes are still there next time. Call close() on the executor when you are done to delete its sandboxes. Each sandbox also has a one-hour lifetime (ttl_s), after which kosa8 deletes it anyway.

Options

Option Default
api_key KOSA8_API_KEY, then ~/.kosa8/cloud.json kosa8 Cloud API key
template "python" kosa8 template (needs python3)
size template's vCPU x GiB: "0.25x0.5" … "16x32"
region chosen by kosa8 e.g. "us-ash1"
allow_hosts org policy only these hosts ([]: no network)
egress org policy a full kosa8 egress policy (internet, allow, deny, presets)
sandbox_scope "session" "session", "executor" (one shared sandbox) or "call" (a new sandbox per code block, deleted after)
stateful False keep Python variables between blocks (see below)
timeout_seconds 300 (80 when stateful) the time limit for one code block
ttl_s 3600 lifetime of each sandbox (None: none)
sleep_after_s kosa8's idle seconds before a sandbox sleeps (it wakes on the next block)
env, labels none environment variables for the code, and kosa8 labels
input_dir, output_dir /workspace/inputs, /workspace/outputs where input files go, and where output files are collected
client made from api_key a kosa8.Kosa8Cloud to share

What comes back

  • stdout, stderr and exit_code. An exception in the code is a traceback in stderr and exit code 1. ADK shows these to the model, and its error_retry_attempts applies.
  • A block that runs past timeout_seconds is stopped in the sandbox. It returns exit code 124, any output so far, and Code execution timed out after N seconds. in stderr.
  • Every file the code writes under output_dir (also in $ADK_OUTPUT_DIR) is returned as an output file, and ADK saves it as an artifact. Input files from CodeExecutorContext.add_input_files() are written to input_dir ($ADK_INPUT_DIR). Both folders are emptied before each block. At most 100 files and 32 MiB are returned per block.
  • Problems with kosa8 itself raise kosa8 exceptions rather than returning output to the model: a bad key (Kosa8AuthError), no plan or credit (Kosa8PaymentRequiredError, with upgrade_url) or a rate limit (Kosa8RateLimitError). If a session's sandbox was deleted, for example by its ttl_s, the executor starts a new one and runs the block again.

Stateful execution

Kosa8CodeExecutor(stateful=True)

With stateful=True, variables, imports and functions stay from one code block to the next, as in a notebook. Each block runs in kosa8's code interpreter in a persistent sandbox, with one context per ADK session. The value of a block's last expression is added to stdout, and charts it draws come back as PNG output files. A cell takes at most 80 seconds. When the time limit stops a cell, the context keeps what the cell had set up to that point.

Lock the network to one host

Kosa8CodeExecutor(allow_hosts=["pypi.org"])

The sandbox then reaches pypi.org and nothing else. A request to another host fails at DNS, and an address the code already knows gets nowhere. kosa8 enforces the policy on the host, outside the sandbox, and nothing inside the sandbox can change it. Entries can be exact names, *.domain wildcards, IPv4 addresses or CIDRs. With no policy set, a sandbox gets your organization's policy. That is kosa8's default allow-list (package registries, GitHub, Hugging Face and the main AI APIs) unless your organization changed it. See egress controls.

kosa8 tools over MCP

from google.adk.agents import LlmAgent
from adk_kosa8 import SANDBOX_TOOLS, kosa8_mcp_toolset

root_agent = LlmAgent(
    name="kosa8_tools",
    model="gemini-flash-latest",
    instruction="Run code with the kosa8 sandbox tools. Delete every sandbox you create.",
    tools=[kosa8_mcp_toolset(tool_filter=SANDBOX_TOOLS)],
)

kosa8_mcp_toolset(api_key=None, tool_filter=None, ...) connects to https://api.kosa8.com/mcp over Streamable HTTP, with the key as a Bearer token. SANDBOX_TOOLS is run, templates_list, sandbox_create, sandbox_get, sandbox_list, sandbox_exec, sandbox_exec_status, file_read, file_write, file_list and sandbox_delete. Leave tool_filter out to get every tool the server lists, including GitHub, previews, snapshots and usage. Other keyword arguments go to McpToolset, for example require_confirmation=True to ask the user before each tool call.

Use the code executor when the model writes code for you to run. Use the toolset when the model should manage sandboxes itself: start one, run shell commands, read and write files, and delete it.

Examples

examples/ holds three agents for adk web examples, plus a runner:

  • python_coder: writes Python and runs it with Kosa8CodeExecutor.
  • egress_locked: the sandbox can reach pypi.org only, so a request to example.com is blocked.
  • mcp_tools: kosa8's MCP sandbox tools.
export KOSA8_API_KEY=k8c_live_...  GOOGLE_API_KEY=...   # or ADK_MODEL=anthropic/claude-haiku-4-5 with ANTHROPIC_API_KEY
python examples/run.py egress_locked "Fetch https://pypi.org/simple/ and https://example.com and report the status of each."
python examples/executor_only.py     # the executor on its own, no model needed

Security notes

  • The code runs in a sandbox, not on your machine. Each kosa8 Cloud sandbox is a microVM with its own Linux kernel on a kosa8 host. One exception: when kosa8's hosts are full, a plain sandbox may run on kosa8's overflow capacity (Cloudflare Containers, same API), which is not a kosa8 microVM. Persistent sandbox (stateful=True), egress-policy (allow_hosts, egress) and named-region (region=) sandboxes always wait for a kosa8 host. See kosa8 Cloud.
  • Limit what the code can reach. Model-written code can be steered by what the model reads. kosa8 limits what that code can do, through the sandbox, its egress policy and its lifetime. kosa8 does not stop prompt injection itself. Use allow_hosts for code that needs no general internet access.
  • Keep keys out of the sandbox. Do not put API keys in env. Store them as kosa8 secrets: the sandbox then holds a placeholder, and kosa8 adds the real key on the way out, only to the named host.
  • Clean up. Call close() (or use with Kosa8CodeExecutor(...) as ex:) to delete sandboxes. The ttl_s lifetime is the backstop if a process dies first.
  • Compliance. kosa8's SOC 2 Type II audit is in progress, with the report expected in January 2027. kosa8 has no SOC 2 report or external pen test yet. See kosa8.com/trust.

Development

uv venv && uv pip install -e . pytest pytest-asyncio ruff mypy
pytest                       # unit tests against a local fake kosa8 API (no network)
ruff check . && ruff format --check . && mypy
KOSA8_API_KEY=k8c_live_... pytest -m kosa8_live    # the live tier, against kosa8 Cloud

The live tier creates sandboxes (each labelled and given a 15-minute lifetime as a backstop), covers create, running code, files across calls, error passthrough, timeouts, input and output files, stateful variables, an egress allow-list, a whole ADK run with a scripted model, and the MCP tool list. Its last test checks that none of its sandboxes are left.

License

MIT

Metadata

Release files for adk-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 adk-kosa8 0.1.0
File Size Uploaded Provenance Actions
adk_kosa8-0.1.0.tar.gz 25.1 kB Without provenance Details for adk_kosa8-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 40.5 kB

Release files / adk_kosa8-0.1.0.tar.gz

Download URL adk_kosa8-0.1.0.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a50a149d132413a61434c66e048c060c5dbe7cd10dbd2be9306b040d1f6e7c2f
BLAKE2b-256 checksum
How to use checksums
753907219c25c4a7878d84a4e44a8daedc48e764a9f8dfa8e45323103128a2bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

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

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

Security for adk-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