Spaces:
Configuration error
Configuration error
Download clients/python/e2b.py from AnthropicallyHuggingFaces/ai-platform-toolbox: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/resolve/main/clients/python/e2b.py
- Command line
-
hf download hf://spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/clients/python/e2b.py
-
curl -L -o e2b.py https://huggingface.co/spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/resolve/main/clients/python/e2b.py
1.08 kB
| """E2B client - sandboxed code execution + filesystem (HTTPS API surface).""" | |
| import os | |
| import requests | |
| BASE = os.getenv("E2B_API_BASE", "https://api.e2b.dev") | |
| KEY = os.getenv("E2B_API_KEY") | |
| def _h(): | |
| if not KEY: | |
| raise RuntimeError("E2B_API_KEY not set") | |
| return {"X-API-Key": KEY, "Content-Type": "application/json"} | |
| def create_sandbox(template="base", **kwargs): | |
| return requests.post(f"{BASE}/v1/sandboxes", headers=_h(), json={"template": template, **kwargs}, timeout=120).json() | |
| def get_sandbox(sandbox_id: str): | |
| return requests.get(f"{BASE}/v1/sandboxes/{sandbox_id}", headers=_h(), timeout=60).json() | |
| def list_sandboxes(): | |
| return requests.get(f"{BASE}/v1/sandboxes", headers=_h(), timeout=60).json() | |
| def kill_sandbox(sandbox_id: str): | |
| return requests.delete(f"{BASE}/v1/sandboxes/{sandbox_id}", headers=_h(), timeout=60).json() | |
| def run_code(sandbox_id: str, code: str, language="python"): | |
| return requests.post(f"{BASE}/v1/sandboxes/{sandbox_id}/runs", headers=_h(), json={"code": code, "language": language}, timeout=120).json() | |