diff --git a/skills/hyperlight-codeact/SKILL.md b/skills/hyperlight-codeact/SKILL.md index 72234a7..dd401e3 100644 --- a/skills/hyperlight-codeact/SKILL.md +++ b/skills/hyperlight-codeact/SKILL.md @@ -49,11 +49,11 @@ Sandboxed code can only reach the outside world through `call_tool()` bridges. ## Quick start ```bash -# 1. Discover tools (matches Copilot CLI tool names) +# 1. Discover tools (works without any packages installed) python3 scripts/codeact.py --discover -# 2. Run code with auto-discovered tools -python3 scripts/codeact.py --auto --workspace . --code ' +# 2. Run code (uv auto-installs hyperlight-sandbox into an ephemeral env) +uv run --with 'hyperlight-sandbox[wasm,python_guest]' python3 scripts/codeact.py --auto --workspace . --code ' content = call_tool("view", path="README.md") print(f"README has {len(content.splitlines())} lines") ' @@ -100,15 +100,20 @@ content = call_tool('view', path=call_tool('glob', pattern='config.json')[0]) ### Step 3 -- Execute +Use `uv run --with` to auto-install the dependency: + ```bash # Auto-discover + workspace scoping (recommended) -python3 scripts/codeact.py --auto --workspace . --code '...' +uv run --with 'hyperlight-sandbox[wasm,python_guest]' python3 scripts/codeact.py --auto --workspace . --code '...' # With saved manifest -python3 scripts/codeact.py --manifest tools.json --code-file script.py +uv run --with 'hyperlight-sandbox[wasm,python_guest]' python3 scripts/codeact.py --manifest tools.json --code-file script.py +``` -# Via stdin -echo '{"tools": [...], "code": "..."}' | python3 scripts/codeact.py --stdin +If `hyperlight-sandbox` is already installed, plain `python3` works too: + +```bash +python3 scripts/codeact.py --auto --workspace . --code '...' ``` Output is always JSON: `{"stdout": "...", "stderr": "...", "exit_code": 0, "success": true}` @@ -130,4 +135,5 @@ Main executor. Key flags: ## Prerequisites - Python 3.10+ -- `hyperlight-sandbox[wasm,python_guest]` or build via `just python-build` +- `uv` (recommended — auto-installs `hyperlight-sandbox` with no side effects) +- Or: `pip install 'hyperlight-sandbox[wasm,python_guest]'` diff --git a/skills/hyperlight-codeact/scripts/codeact.py b/skills/hyperlight-codeact/scripts/codeact.py index d54161c..5f81db5 100644 --- a/skills/hyperlight-codeact/scripts/codeact.py +++ b/skills/hyperlight-codeact/scripts/codeact.py @@ -499,7 +499,20 @@ def main() -> None: return # ---- execution ---- - from hyperlight_sandbox import Sandbox + try: + from hyperlight_sandbox import Sandbox + except ImportError: + print(json.dumps({ + "stdout": "", + "stderr": ( + "hyperlight-sandbox is not installed.\n" + "Run this script with: uv run --with 'hyperlight-sandbox[wasm,python_guest]' python3 scripts/codeact.py ...\n" + "Or install manually: pip install 'hyperlight-sandbox[wasm,python_guest]'" + ), + "exit_code": 1, + "success": False, + }, indent=2)) + sys.exit(1) global _WORKSPACE_ROOT if args.workspace: diff --git a/skills/monty-codeact/SKILL.md b/skills/monty-codeact/SKILL.md index 11c7e6d..8db7ef9 100644 --- a/skills/monty-codeact/SKILL.md +++ b/skills/monty-codeact/SKILL.md @@ -65,7 +65,11 @@ or need full Python (classes, third-party libs). ## Quick start ```bash -python3 scripts/codeact.py --auto --workspace . --code ' +# Discovery works without any packages installed +python3 scripts/codeact.py --discover + +# Execute code (uv auto-installs pydantic-monty into an ephemeral env) +uv run --with pydantic-monty python3 scripts/codeact.py --auto --workspace . --code ' files = glob(pattern="**/*.py", paths="src") print("Found " + str(len(files)) + " Python files") for f in files[:3]: @@ -113,10 +117,17 @@ but it must be imported explicitly). ### Step 3 -- Execute +Use `uv run --with pydantic-monty` to auto-install the dependency: + +```bash +uv run --with pydantic-monty python3 scripts/codeact.py --auto --workspace . --code '...' +uv run --with pydantic-monty python3 scripts/codeact.py --manifest tools.json --code-file script.py +``` + +If `pydantic-monty` is already installed, plain `python3` works too: + ```bash python3 scripts/codeact.py --auto --workspace . --code '...' -python3 scripts/codeact.py --manifest tools.json --code-file script.py -echo '{"tools": [...], "code": "..."}' | python3 scripts/codeact.py --stdin ``` Output is JSON: @@ -140,4 +151,5 @@ Key flags: ## Prerequisites - Python 3.10+ -- `pip install pydantic-monty` (~4.5MB, no other dependencies) +- `uv` (recommended — auto-installs `pydantic-monty` with no side effects) +- Or: `pip install pydantic-monty` (~4.5MB, no other dependencies) diff --git a/skills/monty-codeact/scripts/codeact.py b/skills/monty-codeact/scripts/codeact.py index fb2337a..c107cb9 100644 --- a/skills/monty-codeact/scripts/codeact.py +++ b/skills/monty-codeact/scripts/codeact.py @@ -453,7 +453,20 @@ def main() -> None: return # ---- execution ---- - import pydantic_monty + try: + import pydantic_monty + except ImportError: + print(json.dumps({ + "stdout": "", + "stderr": ( + "pydantic-monty is not installed.\n" + "Run this script with: uv run --with pydantic-monty python3 scripts/codeact.py ...\n" + "Or install manually: pip install pydantic-monty" + ), + "return_value": None, + "success": False, + }, indent=2)) + sys.exit(1) global _WORKSPACE_ROOT if args.workspace: