Metadata-Version: 2.5
Name: praisonai-kosa8
Version: 0.1.0
Summary: kosa8 Cloud microVM sandbox backend for PraisonAI
Project-URL: Homepage, https://kosa8.com
Project-URL: Documentation, https://github.com/kosa8ai/praisonai-kosa8#readme
Project-URL: Repository, https://github.com/kosa8ai/praisonai-kosa8
Project-URL: Issues, https://github.com/kosa8ai/praisonai-kosa8/issues
Author: kosa8
License: MIT
License-File: LICENSE
Keywords: agents,code-execution,kosa8,microvm,praisonai,sandbox
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: praisonai-sandbox>=0.1.22
Requires-Dist: praisonaiagents>=1.6.126
Description-Content-Type: text/markdown

# praisonai-kosa8

[kosa8 Cloud](https://kosa8.com) microVM sandboxes as a [PraisonAI](https://github.com/MervinPraison/PraisonAI) sandbox backend.

Installing the package registers `kosa8` in PraisonAI's `praisonai.sandbox` entry-point group. Then `SandboxConfig(sandbox_type="kosa8")` and `Agent(..., tools_run_on="kosa8")` run code and shell tools in a kosa8 Cloud sandbox: a microVM with its own kernel, created on first use and deleted when the sandbox stops.

## Install

```bash
pip install praisonai-kosa8
```

or, with the PraisonAI plugins package:

```bash
pip install "praisonai-plugins[kosa8]"
```

You need a kosa8 Cloud API key. Create one in the kosa8 Cloud dashboard and export it:

```bash
export KOSA8_API_KEY=k8c_live_...
```

kosa8 Cloud is a paid service; plans start at $29/month. See [kosa8.com](https://kosa8.com) for plans.

## Quick start

```python
import asyncio

from praisonaiagents.sandbox import SandboxConfig, SandboxManager


async def main() -> None:
    manager = SandboxManager(SandboxConfig(sandbox_type="kosa8"))
    result = await manager.run_code("print(6 * 7)")
    print(result.stdout)  # 42


asyncio.run(main())
```

`run_code` creates a sandbox, runs the code and deletes the sandbox. To keep one sandbox for several calls, use the manager as a context manager:

```python
async with SandboxManager(SandboxConfig(sandbox_type="kosa8")) as sandbox:
    await sandbox.write_file("data.csv", "a,b\n1,2\n")
    result = await sandbox.run_command("wc -l data.csv")
    print(result.stdout)
```

## Run an agent's tools in kosa8

```python
from praisonaiagents import Agent

agent = Agent(
    instructions="You are a coding assistant.",
    tools_run_on="kosa8",  # shell and file tools run in a kosa8 Cloud sandbox
)
agent.start("Write a Python script that prints the first ten primes and run it.")
```

PraisonAI wraps the sandbox in its one-environment compute adapter: the sandbox is created when the agent first needs it and deleted when the agent shuts down. `tools_run_on=` finds plugin sandboxes through the registry in `praisonai-code`, which the full `praisonai` package installs.

## Network

The sandbox has **no network** unless you allow it. With PraisonAI's defaults (`ResourceLimits.network_enabled=False`, `SecurityPolicy.allow_network=False`) the sandbox is created with the kosa8 egress policy `{"internet": false}`, enforced on the host from the VM's first packet.

```python
from praisonaiagents.sandbox import ResourceLimits, SandboxConfig

# Open network:
SandboxConfig(sandbox_type="kosa8", resource_limits=ResourceLimits(network_enabled=True))

# Only some hosts (a kosa8 egress policy, sent as is):
SandboxConfig(sandbox_type="kosa8", metadata={"kosa8_egress": {"allow": ["pypi.org", "files.pythonhosted.org"]}})
```

The policy is set when the sandbox is created; `limits` passed to a single call do not change it.

## Options

`SandboxConfig` fields that are used:

| Field | Meaning |
|---|---|
| `env` | Environment variables for every command (per-call `env` is merged over it). |
| `working_dir` | Where commands start and relative paths point. Default `/workspace`. |
| `resource_limits.timeout_seconds` | Command timeout, enforced inside the sandbox. A timeout answers `SandboxStatus.TIMEOUT`. |
| `resource_limits.network_enabled`, `security_policy.allow_network` | Either one `True` leaves the network open. |
| `metadata["kosa8_template"]` | Template key (`GET /v1/templates`). Default `python`. |
| `metadata["kosa8_region"]` | Region id, such as `eu-hel1`. Default: the org's. |
| `metadata["kosa8_ttl_s"]` | Seconds until kosa8 Cloud deletes the sandbox even if it is never stopped (60 s to 90 days). Default 3600. |
| `metadata["kosa8_egress"]` | A full kosa8 egress policy: `{internet, allow, deny, presets}`. |

`Kosa8Sandbox(config, ...)` also takes these as keyword arguments (`template`, `region`, `ttl_s`, `sleep_after_s`, `network_enabled`, `egress`), plus `api_key`, `base_url`, and `sandbox_id` to attach to a sandbox you already started (it is then not deleted by `stop()`).

## What runs where

| Method | kosa8 behaviour |
|---|---|
| `execute(code, language)` | `python` (`python3`), `bash`/`sh`, `javascript` (`node`, if the template has it). The code is passed on stdin, so it has no length limit. |
| `run_command(cmd)` | A string runs through the shell (pipes, redirects, `&&`); a list is quoted argument by argument. |
| `execute_file(path, args)` | Uploads the local file and runs it by extension (`.py`, `.sh`, `.js`). |
| `write_file`, `read_file` | Any path; parent directories are created. Files under `/workspace` go through the kosa8 files API, others through exec. `read_file` returns `str` for UTF-8 and `bytes` otherwise. |
| `list_files(path)` | Absolute paths of a directory's entries. |
| `stop()`, `cleanup()` | Delete the sandbox. `reset()` replaces it with a new one. |

API errors come back as a `SandboxResult` with `status=FAILED` and the error. When kosa8 Cloud refuses work for billing (402), `error` is the API's `agent_message`, a sentence to relay to the person.

## Tests

```bash
uv sync --group dev
uv run pytest                                    # unit tests, against a fake API
KOSA8_API_KEY=k8c_live_... uv run pytest tests/integration_tests   # live
```

The live tests create sandboxes with a 10-minute lifetime and delete them.

## Security

kosa8's SOC 2 audit is in progress; there is no SOC 2 report yet. Report security issues to contact@kosa8.com.

## License

MIT
