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
65 changes: 65 additions & 0 deletions examples/wandb_sandbox_echo_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Run the hosted OpenEnv Echo Space on W&B Serverless Sandboxes.

Usage:
wandb login
# or: export WANDB_API_KEY=...

PYTHONPATH=src uv run --extra wandb \
--with "git+https://huggingface.co/spaces/openenv/echo_env" \
python examples/wandb_sandbox_echo_env.py
"""

from __future__ import annotations

import asyncio

from echo_env import EchoEnv # type: ignore[import-not-found]
from openenv.core.containers.runtime.wandb_sandbox_provider import ( # type: ignore[import-not-found]
WandbSandboxProvider,
)


ECHO_ENV_IMAGE = "registry.hf.space/openenv-echo-env:latest"
SERVER_CMD = (
"cd /app/env && /app/.venv/bin/python -m uvicorn "
"server.app:app --host 0.0.0.0 --port 8000"
)


async def main() -> None:
WandbSandboxProvider.preflight()
provider = WandbSandboxProvider(
ingress_mode="public",
egress_mode="internet",
max_lifetime_seconds=3600,
max_timeout_seconds=300,
tags=["openenv-wandb-echo-example"],
)

env = None
try:
env = await EchoEnv.from_docker_image(
ECHO_ENV_IMAGE,
provider=provider,
cmd=SERVER_CMD,
)
except Exception:
provider.stop_container()
raise

async with env:
await env.reset()
tools = await env.list_tools()
print(f"tools={[tool.name for tool in tools]}")

result = await env.call_tool(
"echo_message",
message="hello from W&B Sandboxes",
)
print(f"echo_message={result}")

print("cleanup=sandbox stopped and deleted")


if __name__ == "__main__":
asyncio.run(main())
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ aca = [
"azure-containerapps-sandbox>=0.1.0b2,<0.2.0",
"azure-identity>=1.23.0",
]
cwsandbox = [
"cwsandbox>=0.23.3; python_version >= '3.11'",
]
wandb = [
"wandb>=0.27; python_version >= '3.11'",
"cwsandbox>=0.23.3; python_version >= '3.11'",
]
modal = [
"modal>=1.4.0",
"pyyaml>=6.0",
Expand Down
Loading
Loading