Files
OpenShell/e2e/python/test_sandbox_api.py
T
Drew Newberry d2f3ca71d4 feat(sandbox): add callable python exec API and refresh e2e coverage (!19)
Closes #13

## Summary
- add Python sandbox execution APIs for command and callable workflows
- consolidate sandbox policy fixtures and expand e2e test coverage for policy and Python exec paths
- update CI/build config and images for sandbox e2e execution dependencies

## Test Plan
- mise run pre-commit
2026-02-12 23:30:24 -08:00

52 lines
1.4 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Callable
from navigator import Sandbox, SandboxClient
def test_sandbox_api_crud_and_exec(
sandbox: Callable[..., Sandbox],
sandbox_client: SandboxClient,
) -> None:
class _FileOps:
def write(self, path: str, content: str) -> None:
from pathlib import Path
Path(path).write_text(content)
def read(self, path: str) -> str:
from pathlib import Path
return Path(path).read_text()
with sandbox(delete_on_exit=True) as sb:
assert sb.id
assert sb.sandbox.name.startswith("sandbox-")
fetched = sandbox_client.get(sb.id)
assert fetched.id == sb.id
ids = set(sandbox_client.list_ids(limit=100))
assert sb.id in ids
result = sb.exec(["python", "-c", "print('sandbox-ok')"])
assert result.exit_code == 0
assert "sandbox-ok" in result.stdout
file_ops = _FileOps()
create_file = sb.exec_python(
file_ops.write,
args=("/sandbox/exec-persistence.txt", "ok"),
)
assert create_file.exit_code == 0
verify_file = sb.exec_python(
file_ops.read, args=("/sandbox/exec-persistence.txt",)
)
assert verify_file.exit_code == 0
assert verify_file.stdout.strip() == "ok"