AnthropicallyHuggingFaces's picture
Add E2B client
841bffd verified
Raw History Blame Contribute Delete
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()