Metadata-Version: 2.5
Name: agent-framework-kosa8
Version: 0.1.0
Summary: kosa8 Cloud microVM sandboxes for Microsoft Agent Framework: a ShellExecutor plus shell, Python and file tools
Project-URL: Homepage, https://kosa8.com
Project-URL: Documentation, https://github.com/kosa8ai/agent-framework-kosa8#readme
Project-URL: Repository, https://github.com/kosa8ai/agent-framework-kosa8
Project-URL: Issues, https://github.com/kosa8ai/agent-framework-kosa8/issues
Author: kosa8
License: MIT
License-File: LICENSE
Keywords: agent-framework,agents,kosa8,microsoft-agent-framework,microvm,sandbox,shell
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: <4.0,>=3.11
Requires-Dist: agent-framework-core<2,>=1.19.0
Requires-Dist: agent-framework-tools<2,>=1.0.0b261112
Requires-Dist: kosa8<1,>=0.12.0
Description-Content-Type: text/markdown

# agent-framework-kosa8

**[kosa8](https://kosa8.com): Zero Trust cybersecurity infrastructure for AI agents.** Every agent sealed in its own microVM. Every action verified and recorded.

Run a [Microsoft Agent Framework](https://github.com/microsoft/agent-framework) agent's shell commands, Python code and file edits in a [kosa8 Cloud](https://kosa8.com) microVM sandbox instead of on your machine.

`Kosa8ShellTool` implements Agent Framework's `ShellExecutor` protocol (from `agent-framework-tools`, the package behind `LocalShellTool` and `DockerShellTool`) on a kosa8 sandbox. Its `as_function()` returns the same kind of `kind="shell"` `FunctionTool` the built-in shell tools do, so it drops in wherever they go. Tested against `agent-framework-core` 1.26.0 and `agent-framework-tools` 1.0.0b261112 (Python).

## Install

```bash
pip install agent-framework-kosa8
```

`agent-framework-tools` is still a beta on PyPI; this package asks for it by version, so `pip` installs it without `--pre`.

Set `KOSA8_API_KEY` to a kosa8 Cloud API key (create one at [app.kosa8.com](https://app.kosa8.com), or run `kosa8 login`). The Starter plan is free, no card. Plans are at [kosa8.com/pricing](https://kosa8.com/pricing/).

## Example

```python
import asyncio

from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
from agent_framework_kosa8 import Kosa8ShellTool


async def main() -> None:
    client = OpenAIChatClient(model="gpt-5.4-nano")
    async with Kosa8ShellTool(ttl_s=3600) as shell:
        agent = Agent(
            client=client,
            instructions="You work in a Linux sandbox.",
            tools=[client.get_shell_tool(func=shell.as_function())],
        )
        result = await agent.run("Write fizzbuzz.py in /workspace, run it and show the output.")
        print(result.text)


asyncio.run(main())
```

`async with` creates the sandbox and deletes it on the way out. Without it, the sandbox is created on the first command and deleted by `await shell.close()`.

Any chat client works: pass `shell.as_function()` in `tools=[...]` directly when the provider has no `get_shell_tool`.

## More tools on the same sandbox

```python
agent = Agent(client=client, tools=shell.as_tools())
```

| Tool | What it does |
|---|---|
| `run_shell` (`as_function()`) | one command under `sh -c` in `workdir`; returns stdout, stderr and the exit code |
| `execute_python` (`as_code_function()`) | a Python 3 program, run with `python3` in `workdir` |
| `read_file`, `write_file`, `list_files` (`as_file_functions()`) | the kosa8 files API, no shell |

You can also call the sandbox from your own code: `await shell.run("make test")` returns the framework's `ShellResult`; `run_python`, `read_file`, `write_file`, `list_files` and `remove_file` work the same way. `shell.sandbox` is the `kosa8.AsyncCloudSandbox` for anything else kosa8 does (previews, snapshots, checkpoints, sleep).

## Approval

The microVM is the boundary: commands never run on your machine, so the tools default to `approval_mode="never_require"`. Pass `approval_mode="always_require"` to have a person approve each call through the framework's `user_input_requests`. `ShellPolicy` allow and deny lists and the `on_command` audit hook work as in the built-in shell tools; like there, the policy is a pre-filter, not a boundary.

## Options

| Option | Default | |
|---|---|---|
| `sandbox_id` | none | attach to an existing sandbox instead of creating one |
| `template` | `"python"` | kosa8 template (Python 3.12 and a POSIX shell) |
| `image` | none | OCI image, instead of a template |
| `size` | template size | vCPU x GiB: `0.25x0.5`, `0.5x1`, `1x2`, `2x4`, `4x8`, `8x16` or `16x32` |
| `region` | chosen by kosa8 | `us-ash1`, `eu-hel1`, `us` or `eu` |
| `ttl_s` | none | lifetime: kosa8 deletes the sandbox this many seconds after it starts, even if `close()` never runs. Recommended |
| `sleep_after_s` | account setting | idle seconds before the sandbox sleeps; it wakes on its next command |
| `persistent` | off | one long-lived container, so the whole filesystem and background processes last between commands |
| `env` | none | environment for every command, sent with each command and never stored on the sandbox |
| `internet` | on | `False` turns off the open internet |
| `egress_allow`, `egress_presets` | none | hosts, or named host sets such as `pypi`, the sandbox may reach |
| `secrets` | none | names of org secrets the sandbox holds (set in the kosa8 dashboard or CLI) |
| `labels`, `name` | none | stored on the sandbox |
| `workdir` | `/workspace` | where commands start; relative file paths resolve against it |
| `on_close` | `"delete"` (`"keep"` when attached) | what `close()` does: `"delete"`, `"sleep"` or `"keep"` |
| `policy` | allow all | a `ShellPolicy` checked before each command |
| `timeout` | 30 s | per-command timeout, enforced inside the sandbox; `None` disables |
| `max_stdout_bytes`, `max_stderr_bytes` | 64 KiB each | output returned to the model; the head and tail are kept |
| `approval_mode` | `"never_require"` | approval for every vended tool |
| `on_command` | none | audit hook called with each command |
| `api_key`, `base_url`, `cloud` | `KOSA8_API_KEY`, `https://api.kosa8.com` | or pass a ready `kosa8.AsyncCloud` (yours to close) |

## Limits

- Each command runs in a fresh `sh` in `workdir`: files and installed packages persist, `cd` and shell variables do not (like the built-in tools' stateless mode). There is no persistent-shell mode.
- Without `persistent=True`, only `/workspace` is promised to persist between commands.
- A timed-out command returns `timed_out=True` and exit code 124, with its whole process group killed in the sandbox.
- One tool instance is one sandbox: give each conversation or user its own and close it when done.

## How commands run

Each command is started by a small POSIX `sh` wrapper in a process group of its own, with stdin at EOF and its output redirected to files. A watchdog inside the sandbox enforces `timeout`; cancelling the call kills the command too. The client waits in polls of at most 50 s, so a command can run longer than one 90 s kosa8 request, and output comes back base64-encoded, so any bytes survive.

## Tests

```bash
uv run --group dev pytest            # unit tests against a mocked kosa8 API
KOSA8_API_KEY=... uv run --group dev pytest tests/test_live.py   # live tier on kosa8 Cloud
uv run --group dev ruff check .
```

The live tier gives each sandbox a 10-minute `ttl_s` and a label, deletes it, and checks it is gone. It also drives a real Agent Framework `Agent` with a scripted chat client, so no model is called.

## License

MIT. kosa8 is not affiliated with Microsoft.
