Repository navigation
Add Kosa8Provider: run environments in kosa8 Cloud sandboxes - #1792
drvt69talati wants to merge 2 commits into
Conversation
A ContainerProvider for kosa8 Cloud microVM sandboxes, behind the optional kosa8 extra. It boots an OCI image, starts the server from openenv.yaml (or cmd=), and opens the port as a kosa8 preview. The preview is token-gated by default and reached through a loopback proxy that adds the token, as HFSandboxProvider does; public=True returns the https preview URL directly. Fake-SDK unit tests pin the kosa8 SDK method names and kwargs, and an opt-in live test runs echo_env on kosa8 Cloud over /ws. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…live test registry.hf.space timed out on pulls from kosa8 hosts; the ghcr image is the same environment and pulls reliably. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3ee33b5. Configure here.
| kwargs["env"] = dict(env) | ||
| if egress is not None: | ||
| kwargs["egress"] = dict(egress) | ||
| return self._cloud.sandboxes.create(**kwargs) |
There was a problem hiding this comment.
Extra kwargs override safety defaults
Medium Severity
create_sandbox unpacks extra after labels, sleep_after_s, and on_timeout, so any matching start_container() kwarg replaces those values. That drops the guaranteed openenv=1 label and can re-enable auto-sleep, which the provider otherwise forbids because a sleeping sandbox tears down a live /ws mid-episode. size and ttl_s are applied after extra and do not have this problem.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 3ee33b5. Configure here.
| if response.status_code == 200: | ||
| return | ||
| except requests.RequestException: | ||
| pass |
There was a problem hiding this comment.
Health checks honor HTTP_PROXY
Medium Severity
wait_for_ready calls requests.get on the private http://127.0.0.1 proxy URL without disabling proxies. With HTTP_PROXY set and NO_PROXY not including loopback, the health probe is sent to the proxy instead of the local server, so readiness fails for a sandbox that is actually up. LocalDockerProvider and KubernetesProvider already bypass proxies for this reason.
Reviewed by Cursor Bugbot for commit 3ee33b5. Configure here.


Summary
Adds
Kosa8Provider, aContainerProviderthat runs an environment server in a kosa8 Cloud sandbox (a microVM with its own kernel). It is an optional extra (pip install openenv[kosa8]) with a lazy SDK import, and follows the Modal and HF providers: boot the image, launch the server fromopenenv.yaml(orcmd=), and return abase_urlthatEnvClientconnects to,/wsincluded.public=True, and the token goes in a headerEnvClientdoes not send, sostart_container()returns a loopback proxy URL that adds the token and forwards HTTP and WebSocket traffic to thehttps/wsspreview. The proxy is adapted fromHFSandboxProvider._LocalAuthProxy(same limitations, redirects rejected). Withpublic=Truethehttps://preview URL is returned directly.1x2), a lifetime (ttl_s, default 1 hour, deleted on expiry) and the labelopenenv=1. It never auto-sleeps, so a live/wsis not dropped mid-episode. The preview token expires with the sandbox (7 days at most).stop_container(),close()and the client's exit delete the sandbox, including after a failed start. A cleanup error never masks the original one.surface_server_logs=True, and then it is redacted and bounded.egress=sets the sandbox's network policy at boot (for example{"internet": False}for default-deny). Left out, the organization's policy applies. Cloud metadata is never reachable from a kosa8 sandbox.openenv.core.containers.runtime.kosa8_provider. Like the other cloud providers, it is not re-exported.Disclosure: I work on kosa8. The same provider is also published as
openenv-kosa8(source), so people can use it before or without this PR.Admission criteria (RFC 002 amendment, #1608)
kosa8_provider.py, plus the extra, docs, an example and tests. No changes toEnvClient, the server protocol or the runtime re-exports.kosa8>=0.12.0,<1(PyPI, MIT, no dependencies, Python >= 3.9). It is imported lazily inside_DefaultKosa8Adapter.https. The private preview is reached overhttps/wss, with plaintext only on the loopback leg.public=True. The token is time-boxed and never logged.egress=sets the rest. The guide documents the egress and metadata posture.shlex-quoted, andcmdcomes only from the orchestrator.drvt69talati, kosa8).Type of Change
Alignment Checklist
Before submitting, verify:
.claude/docs/PRINCIPLES.mdand this PR aligns with our principles.claude/docs/INVARIANTS.mdand no invariants are violated/pre-submit-pr(orbash .claude/hooks/lint.shand tests) and addressed all issuesRFC Status
Test Plan
PYTHONPATH=src:envs uv run pytest tests/test_core/test_kosa8_provider.py: 60 passed, with no kosa8 account needed.openenv.yamldiscovery and quoting,cmdoverrides, private and public previews, preview host and token checks (nothing echoed into errors), and cleanup on every failure path. It also covers stop being idempotent, restart after stop, context-manager exit, andwait_for_readyon healthy and dead servers (with redaction when opted in) and on timeout.kosa8module records the calls_DefaultKosa8Adaptermakes.TestRealSdkShapechecks those method names and kwargs against the installedkosa8SDK withinspect.signature.PYTHONPATH=src:envs uv run pytest tests/test_core/: 686 passed, 22 skipped (Python 3.12,.[kosa8]installed).ruff format --check,ruff checkandusort checkare clean on the changed files.3ee33b5), withghcr.io/openenv/openenv-echo-env:latest, one private case and one public case:/wsupgrade on the preview returns101, and aresetframe gets an observation back./healthand the/wsupgrade return401without the token, and the loopback proxy's own/wsreturns101.reset(), thenstep(CallToolAction("echo_message"))andcall_tool("echo_with_length"), complete throughEchoEnv.169.254.169.254is refused from inside the sandbox. The private case also runs underegress={"internet": False}, andhttps://pypi.orgis refused too.kosa8.Cloud().sandboxes.get(id)raisesKosa8NotFoundError.Claude Code Review
N/A. This PR was written with Claude Code, and the tests and lint above were run on it.
🤖 Generated with Claude Code
Note
Medium Risk
Touches security-sensitive ingress (token proxy, public previews) and remote sandbox lifecycle, but changes are isolated to a new provider module with extensive tests and no core client/protocol edits.
Overview
Adds
Kosa8Provider, a new optional cloudContainerProvider(pip install openenv[kosa8]) that runs OpenEnv server images in kosa8 Cloud microVM sandboxes. It pulls an OCI image, launches the server fromopenenv.yaml(orcmd=), exposes the port as a kosa8 preview, and returns abase_urlcompatible withEnvClient(including provider-owned client lifecycle).Private previews use a local loopback proxy (pattern aligned with
HFSandboxProvider) that injectsX-Kosa8-Preview-Tokenand forwards HTTP/WebSocket tohttps/wssupstream;public=Truereturns the preview URL directly. Sandboxes get TTL, size,egress=policy,openenv=1labeling, no auto-sleep, and cleanup on failure/close. API keys and preview secrets are kept out of sandboxes and error messages by default.Also ships
examples/kosa8_echo_env.py, docs/autodoc entries, thekosa8extra inpyproject.toml, broad unit tests (fake adapter + SDK shape checks), and opt-in live integration tests.Reviewed by Cursor Bugbot for commit 3ee33b5. Bugbot is set up for automated code reviews on this repo. Configure here.