AnthropicallyHuggingFaces commited on
Commit
841bffd
·
verified ·
1 Parent(s): 7678749

Add E2B client

Browse files
Files changed (1) hide show
  1. clients/python/e2b.py +32 -0
clients/python/e2b.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """E2B client - sandboxed code execution + filesystem (HTTPS API surface)."""
2
+ import os
3
+ import requests
4
+
5
+ BASE = os.getenv("E2B_API_BASE", "https://api.e2b.dev")
6
+ KEY = os.getenv("E2B_API_KEY")
7
+
8
+
9
+ def _h():
10
+ if not KEY:
11
+ raise RuntimeError("E2B_API_KEY not set")
12
+ return {"X-API-Key": KEY, "Content-Type": "application/json"}
13
+
14
+
15
+ def create_sandbox(template="base", **kwargs):
16
+ return requests.post(f"{BASE}/v1/sandboxes", headers=_h(), json={"template": template, **kwargs}, timeout=120).json()
17
+
18
+
19
+ def get_sandbox(sandbox_id: str):
20
+ return requests.get(f"{BASE}/v1/sandboxes/{sandbox_id}", headers=_h(), timeout=60).json()
21
+
22
+
23
+ def list_sandboxes():
24
+ return requests.get(f"{BASE}/v1/sandboxes", headers=_h(), timeout=60).json()
25
+
26
+
27
+ def kill_sandbox(sandbox_id: str):
28
+ return requests.delete(f"{BASE}/v1/sandboxes/{sandbox_id}", headers=_h(), timeout=60).json()
29
+
30
+
31
+ def run_code(sandbox_id: str, code: str, language="python"):
32
+ return requests.post(f"{BASE}/v1/sandboxes/{sandbox_id}/runs", headers=_h(), json={"code": code, "language": language}, timeout=120).json()