Skip to content

Add Kosa8Provider: run environments in kosa8 Cloud sandboxes - #1792

Open
drvt69talati wants to merge 2 commits into
openenv:mainfrom
drvt69talati:kosa8-provider
Open

drvt69talati wants to merge 2 commits into
openenv:mainfrom
drvt69talati:kosa8-provider

Conversation

@drvt69talati

@drvt69talati drvt69talati commented Dec 2, 2026 •

Copy link
Copy Markdown

Summary

Adds Kosa8Provider, a ContainerProvider that 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 from openenv.yaml (or cmd=), and return a base_url that EnvClient connects to, /ws included.

  • Private by default. The server port is opened as a kosa8 preview. A preview is token-gated unless public=True, and the token goes in a header EnvClient does not send, so start_container() returns a loopback proxy URL that adds the token and forwards HTTP and WebSocket traffic to the https/wss preview. The proxy is adapted from HFSandboxProvider._LocalAuthProxy (same limitations, redirects rejected). With public=True the https:// preview URL is returned directly.
  • Bounded. Each sandbox gets a size (default 1x2), a lifetime (ttl_s, default 1 hour, deleted on expiry) and the label openenv=1. It never auto-sleeps, so a live /ws is not dropped mid-episode. The preview token expires with the sandbox (7 days at most).
  • Cleanup. stop_container(), close() and the client's exit delete the sandbox, including after a failed start. A cleanup error never masks the original one.
  • Secrets. The kosa8 API key stays in the orchestrator process and never enters the sandbox. The token and the public URL never appear in errors or logs. Server output is withheld from errors unless surface_server_logs=True, and then it is redacted and bounded.
  • Network. 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.
  • Import it from 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)

  1. One module. Only kosa8_provider.py, plus the extra, docs, an example and tests. No changes to EnvClient, the server protocol or the runtime re-exports.
  2. Extra. kosa8>=0.12.0,<1 (PyPI, MIT, no dependencies, Python >= 3.9). It is imported lazily inside _DefaultKosa8Adapter.
  3. Backend. kosa8 Cloud is a hosted service with open sign-up at app.kosa8.com.
  4. S1 to S6.
    • S1: the public preview is https. The private preview is reached over https/wss, with plaintext only on the loopback leg.
    • S2: public ingress only with public=True. The token is time-boxed and never logged.
    • S3: metadata is denied (live result below), and egress= sets the rest. The guide documents the egress and metadata posture.
    • S4: covered in Secrets above.
    • S5: the discovered path and app are shlex-quoted, and cmd comes only from the orchestrator.
    • S6: size and lifetime as described in Bounded above.
  5. Evidence. See the test plan below.
  6. Owner. Named in the guide section (drvt69talati, kosa8).
  7. Same backend. No other provider reaches kosa8.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • New environment
  • Refactoring

Alignment Checklist

Before submitting, verify:

  • I have read .claude/docs/PRINCIPLES.md and this PR aligns with our principles
  • I have checked .claude/docs/INVARIANTS.md and no invariants are violated
  • I have run /pre-submit-pr (or bash .claude/hooks/lint.sh and tests) and addressed all issues

RFC Status

Test Plan

  • PYTHONPATH=src:envs uv run pytest tests/test_core/test_kosa8_provider.py: 60 passed, with no kosa8 account needed.
    • A duck-typed fake adapter covers: create arguments and defaults, port checks, openenv.yaml discovery and quoting, cmd overrides, 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, and wait_for_ready on healthy and dead servers (with redaction when opted in) and on timeout.
    • A fake kosa8 module records the calls _DefaultKosa8Adapter makes.
    • TestRealSdkShape checks those method names and kwargs against the installed kosa8 SDK with inspect.signature.
    • The loopback proxy is tested for token injection, hop-by-hop header stripping and redirect rejection.
  • PYTHONPATH=src:envs uv run pytest tests/test_core/: 686 passed, 22 skipped (Python 3.12, .[kosa8] installed).
  • ruff format --check, ruff check and usort check are clean on the changed files.
  • Live round trip on kosa8 Cloud at the PR head (3ee33b5), with ghcr.io/openenv/openenv-echo-env:latest, one private case and one public case:
    OPENENV_KOSA8_INTEGRATION=1 KOSA8_API_KEY=... PYTHONPATH=src:envs \
      uv run pytest -m integration tests/test_core/test_kosa8_provider_integration.py -v
    test_kosa8_round_trip[private] PASSED   (36.0 s)
    test_kosa8_round_trip[public]  PASSED   (26.6 s)
    
    Each case checks the following:
    • The /ws upgrade on the preview returns 101, and a reset frame gets an observation back.
    • In the private case, both /health and the /ws upgrade return 401 without the token, and the loopback proxy's own /ws returns 101.
    • reset(), then step(CallToolAction("echo_message")) and call_tool("echo_with_length"), complete through EchoEnv.
    • 169.254.169.254 is refused from inside the sandbox. The private case also runs under egress={"internet": False}, and https://pypi.org is refused too.
    • After the client closes, the sandbox is gone: kosa8.Cloud().sandboxes.get(id) raises Kosa8NotFoundError.

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 cloud ContainerProvider (pip install openenv[kosa8]) that runs OpenEnv server images in kosa8 Cloud microVM sandboxes. It pulls an OCI image, launches the server from openenv.yaml (or cmd=), exposes the port as a kosa8 preview, and returns a base_url compatible with EnvClient (including provider-owned client lifecycle).

Private previews use a local loopback proxy (pattern aligned with HFSandboxProvider) that injects X-Kosa8-Preview-Token and forwards HTTP/WebSocket to https/wss upstream; public=True returns the preview URL directly. Sandboxes get TTL, size, egress= policy, openenv=1 labeling, 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, the kosa8 extra in pyproject.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.

drvt69talati and others added 2 commits December 2, 2026 15:03
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>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3ee33b5. Configure here.

if response.status_code == 200:
return
except requests.RequestException:
pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3ee33b5. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant