Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions docs/source/guides/runtime-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ is a one-line change.
| `ModalProvider` | Modal sandboxes | `pip install openenv[modal]` | ✅ |
| `NovitaSandboxProvider` | Novita AI sandboxes | `pip install openenv[novita]` | ✅ |
| `HFSandboxProvider` | Hugging Face sandboxes (billed as HF Jobs) | core | ✅ |
| `Kosa8Provider` | kosa8 Cloud microVM sandboxes | `pip install openenv[kosa8]` | ✅ |
| `KubernetesProvider` | Kubernetes cluster | `pip install openenv[kubernetes]` | ✅ |

Cloud-provider SDKs are optional extras, imported lazily, so installing core
Expand Down Expand Up @@ -91,8 +92,8 @@ async with MyEnv(provider=provider) as env:
...
```

`ModalProvider`, `DaytonaProvider`, `ACASandboxProvider`, and `HFSandboxProvider`
support this provider-owned flow. Providers that require an explicit image at
`ModalProvider`, `DaytonaProvider`, `ACASandboxProvider`, `HFSandboxProvider`
and `Kosa8Provider` support this provider-owned flow. Providers that require an explicit image at
`start_container()` time, such as `LocalDockerProvider` and
`DockerSwarmProvider`, should still be started manually and passed in with the
returned `base_url`:
Expand Down Expand Up @@ -234,6 +235,68 @@ in one process share a sandbox pool, which shuts down after 10 idle minutes.

Full example: [`examples/hf_sandbox_coding_env.py`](https://github.com/openenv/OpenEnv/blob/main/examples/hf_sandbox_coding_env.py).

### Kosa8Provider

Runs the server in a [kosa8 Cloud](https://kosa8.com) sandbox, a microVM with
its own kernel. Install with `pip install openenv[kosa8]`. Requires a kosa8
Cloud API key in `KOSA8_API_KEY` (or `kosa8 login`); sign-up is open at
[app.kosa8.com](https://app.kosa8.com). The key stays in the orchestrator
process and never enters the sandbox.

```python
from echo_env import EchoEnv
from openenv.core.containers.runtime.kosa8_provider import Kosa8Provider

provider = Kosa8Provider(image="ghcr.io/openenv/openenv-echo-env:latest")
base_url = provider.start_container()
provider.wait_for_ready(base_url)

# The client stops the provider, deleting the sandbox, when the block ends.
with EchoEnv(base_url=base_url, provider=provider).sync() as env:
env.reset()
print(env.call_tool("echo_message", message="Hello!"))
```

**Source.** `image` is an OCI registry image, which kosa8 Cloud pulls and
boots as the sandbox's root filesystem. Images built by `openenv build`, such
as the one above, and Hugging Face Space images
(`registry.hf.space/<owner>-<space>:latest`) work as they are. The image's
`CMD` is not run: the provider builds the server command from `openenv.yaml`
(`/app/env/openenv.yaml`, or the first one under `/app`), or takes `cmd=`.
Dockerfiles are not built by the provider; build and push the image first.

**Ingress.** The server port (8000 unless `port=` says otherwise) is opened as
a kosa8 preview, an `https://` URL that proxies the `/ws` WebSocket upgrade. A
preview is private by default: it needs a token header that `EnvClient` does
not send, so `start_container()` returns a loopback proxy URL
(`http://127.0.0.1:<port>`) that adds the token and forwards HTTP and
WebSocket traffic to the `https`/`wss` preview, as `HFSandboxProvider` does.
`public=True` opens a public preview and returns its `https://` URL directly;
anyone who holds that URL can drive the environment.

**Lifetime.** Each sandbox gets `ttl_s` (default one hour). kosa8 deletes the
sandbox when it runs out, and the preview token expires at the same time (at
most after seven days), so the `base_url` is valid until `stop_container()`
or the end of `ttl_s`, whichever comes first. The sandbox never auto-sleeps,
since a sleeping sandbox would drop a live `/ws` transport mid-episode.
`stop_container()`, `close()` and leaving the client's `with` block delete
the sandbox, including after a failed start. Every sandbox carries the label
`openenv=1`.

**Network and limits.** `egress=` sets the sandbox's network policy at boot,
for example `{"internet": False}` for default-deny or
`{"internet": False, "allow": ["pypi.org"]}`; left out, the organization's
policy applies. Cloud metadata endpoints (`169.254.169.254`) are not
reachable from kosa8 sandboxes. `size=` (default `1x2`: 1 vCPU, 2 GiB) caps
CPU and memory. Server output is withheld from errors unless
`surface_server_logs=True`. Other keyword arguments to `start_container()`
(such as `region` or `disk_gb`) go to `kosa8.Cloud().sandboxes.create`.

**Owner.** SDK breakage in this provider is owned by @drvt69talati
([kosa8](https://github.com/kosa8ai)).

Full example: [`examples/kosa8_echo_env.py`](https://github.com/openenv/OpenEnv/blob/main/examples/kosa8_echo_env.py).

### KubernetesProvider

Runs one environment as one Pod and one Service in an existing namespace.
Expand Down
2 changes: 2 additions & 0 deletions docs/source/reference/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,6 @@ See [Evaluating with Environments](../tutorials/evaluation-inspect) for a worked

[[autodoc]] openenv.core.containers.runtime.hf_sandbox_provider.HFSandboxProvider

[[autodoc]] openenv.core.containers.runtime.kosa8_provider.Kosa8Provider

[[autodoc]] openenv.core.containers.runtime.kubernetes_provider.KubernetesProvider
44 changes: 44 additions & 0 deletions examples/kosa8_echo_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""Hello-world example running the Echo environment on kosa8 Cloud.

Boots the echo-env image in a kosa8 Cloud sandbox (a microVM) via
``Kosa8Provider``, then talks to it through ``EchoEnv``. The server port is a
private kosa8 preview; the provider returns a loopback URL that adds the
preview token and forwards HTTP and WebSocket traffic over https/wss.

Usage:
pip install "openenv[kosa8]"
export KOSA8_API_KEY=k8_... (or run `kosa8 login`)
PYTHONPATH=src:envs uv run python examples/kosa8_echo_env.py
"""

import logging

from echo_env import EchoEnv
from openenv.core.containers.runtime.kosa8_provider import Kosa8Provider

logger = logging.getLogger(__name__)


def main() -> int:
logging.basicConfig(level=logging.INFO, format="%(message)s")

provider = Kosa8Provider(
image="ghcr.io/openenv/openenv-echo-env:latest",
ttl_s=900,
egress={"internet": False},
)
base_url = provider.start_container()
provider.wait_for_ready(base_url, timeout_s=180)
# The client stops the provider (deleting the sandbox) when the block ends.
with EchoEnv(base_url=base_url, provider=provider).sync() as env:
env.reset()
logger.info("Tools: %s", [t.name for t in env.list_tools()])
logger.info(
"echo_message -> %s", env.call_tool("echo_message", message="Hello!")
)
return 0


if __name__ == "__main__":
raise SystemExit(main())
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ kubernetes = [
novita = [
"novita-sandbox>=2.1.1",
]
kosa8 = [
"kosa8>=0.12.0,<1",
]
inspect = [
"inspect-ai>=0.3.0",
]
Expand Down
Loading