opensandbox-code-interpreter 0.1.2__tar.gz → 0.1.2.dev0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/.gitignore +0 -11
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/PKG-INFO +7 -15
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/README.md +2 -10
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/pyproject.toml +4 -4
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/adapters/code_adapter.py +1 -21
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/sync/adapters/code_adapter.py +9 -50
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/LICENSE +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/__init__.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/adapters/__init__.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/adapters/converter/__init__.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/adapters/converter/code_execution_converter.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/adapters/factory.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/code_interpreter.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/models/__init__.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/models/code.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/models/code_sync.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/py.typed +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/services/__init__.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/services/code.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/sync/__init__.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/sync/adapters/__init__.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/sync/adapters/factory.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/sync/code_interpreter.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/sync/services/__init__.py +0 -0
- {opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/src/code_interpreter/sync/services/code.py +0 -0
|
@@ -133,8 +133,6 @@ dist
|
|
|
133
133
|
# Gatsby files
|
|
134
134
|
.cache/
|
|
135
135
|
public
|
|
136
|
-
!docs/public/
|
|
137
|
-
!docs/public/CNAME
|
|
138
136
|
|
|
139
137
|
# Serverless directories
|
|
140
138
|
.serverless/
|
|
@@ -224,9 +222,6 @@ secrets/
|
|
|
224
222
|
|
|
225
223
|
# Generated API documentation
|
|
226
224
|
docs/generated/
|
|
227
|
-
docs/.vitepress/generated/
|
|
228
|
-
docs/.vitepress/dist/
|
|
229
|
-
docs/.vitepress/cache/
|
|
230
225
|
apidocs/
|
|
231
226
|
|
|
232
227
|
# Test results
|
|
@@ -268,9 +263,3 @@ nbdist/
|
|
|
268
263
|
# Generated files
|
|
269
264
|
generated/
|
|
270
265
|
**/generated/**
|
|
271
|
-
|
|
272
|
-
# gVisor runtime binaries (downloaded dynamically)
|
|
273
|
-
kubernetes/test/kind/gvisor/runsc
|
|
274
|
-
kubernetes/test/kind/gvisor/containerd-shim-runsc-v1
|
|
275
|
-
bin/
|
|
276
|
-
obj/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opensandbox-code-interpreter
|
|
3
|
-
Version: 0.1.2
|
|
3
|
+
Version: 0.1.2.dev0
|
|
4
4
|
Summary: OpenSandbox Code Interpreter Python SDK - Advanced code execution with persistent contexts
|
|
5
|
-
Project-URL: Homepage, https://
|
|
5
|
+
Project-URL: Homepage, https://github.com/alibaba/OpenSandbox
|
|
6
6
|
Project-URL: Repository, https://github.com/alibaba/OpenSandbox
|
|
7
|
-
Project-URL: Documentation, https://
|
|
7
|
+
Project-URL: Documentation, https://docs.opensandbox.io
|
|
8
8
|
Project-URL: Issues, https://github.com/alibaba/OpenSandbox/issues
|
|
9
9
|
Author-email: OpenSandbox Team <ninan.nn@alibaba-inc.com>
|
|
10
10
|
License: Apache License
|
|
@@ -223,8 +223,8 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
223
223
|
Classifier: Topic :: Software Development :: Libraries
|
|
224
224
|
Classifier: Typing :: Typed
|
|
225
225
|
Requires-Python: >=3.10
|
|
226
|
-
Requires-Dist: opensandbox<0.2.0,>=0.1.
|
|
227
|
-
Requires-Dist: pydantic<3.0,>=2.
|
|
226
|
+
Requires-Dist: opensandbox<0.2.0,>=0.1.1
|
|
227
|
+
Requires-Dist: pydantic<3.0,>=2.0.0
|
|
228
228
|
Description-Content-Type: text/markdown
|
|
229
229
|
|
|
230
230
|
# OpenSandbox Code Interpreter SDK for Python
|
|
@@ -281,7 +281,7 @@ async def main() -> None:
|
|
|
281
281
|
|
|
282
282
|
# 2. Create a Sandbox with the code-interpreter image + runtime versions
|
|
283
283
|
sandbox = await Sandbox.create(
|
|
284
|
-
"opensandbox/code-interpreter:
|
|
284
|
+
"opensandbox/code-interpreter:latest",
|
|
285
285
|
connection_config=config,
|
|
286
286
|
entrypoint=["/opt/opensandbox/code-interpreter.sh"],
|
|
287
287
|
env={
|
|
@@ -342,7 +342,7 @@ config = ConnectionConfigSync(
|
|
|
342
342
|
)
|
|
343
343
|
|
|
344
344
|
sandbox = SandboxSync.create(
|
|
345
|
-
"opensandbox/code-interpreter:
|
|
345
|
+
"opensandbox/code-interpreter:latest",
|
|
346
346
|
connection_config=config,
|
|
347
347
|
entrypoint=["/opt/opensandbox/code-interpreter.sh"],
|
|
348
348
|
env={"PYTHON_VERSION": "3.11"},
|
|
@@ -355,14 +355,6 @@ with sandbox:
|
|
|
355
355
|
sandbox.kill()
|
|
356
356
|
```
|
|
357
357
|
|
|
358
|
-
### Installing Python packages at runtime
|
|
359
|
-
|
|
360
|
-
You can install packages directly via `sandbox.commands.run(...)`:
|
|
361
|
-
|
|
362
|
-
```python
|
|
363
|
-
execution = await sandbox.commands.run("pip install pandas numpy")
|
|
364
|
-
```
|
|
365
|
-
|
|
366
358
|
## Runtime Configuration
|
|
367
359
|
|
|
368
360
|
### Docker Image
|
|
@@ -52,7 +52,7 @@ async def main() -> None:
|
|
|
52
52
|
|
|
53
53
|
# 2. Create a Sandbox with the code-interpreter image + runtime versions
|
|
54
54
|
sandbox = await Sandbox.create(
|
|
55
|
-
"opensandbox/code-interpreter:
|
|
55
|
+
"opensandbox/code-interpreter:latest",
|
|
56
56
|
connection_config=config,
|
|
57
57
|
entrypoint=["/opt/opensandbox/code-interpreter.sh"],
|
|
58
58
|
env={
|
|
@@ -113,7 +113,7 @@ config = ConnectionConfigSync(
|
|
|
113
113
|
)
|
|
114
114
|
|
|
115
115
|
sandbox = SandboxSync.create(
|
|
116
|
-
"opensandbox/code-interpreter:
|
|
116
|
+
"opensandbox/code-interpreter:latest",
|
|
117
117
|
connection_config=config,
|
|
118
118
|
entrypoint=["/opt/opensandbox/code-interpreter.sh"],
|
|
119
119
|
env={"PYTHON_VERSION": "3.11"},
|
|
@@ -126,14 +126,6 @@ with sandbox:
|
|
|
126
126
|
sandbox.kill()
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
-
### Installing Python packages at runtime
|
|
130
|
-
|
|
131
|
-
You can install packages directly via `sandbox.commands.run(...)`:
|
|
132
|
-
|
|
133
|
-
```python
|
|
134
|
-
execution = await sandbox.commands.run("pip install pandas numpy")
|
|
135
|
-
```
|
|
136
|
-
|
|
137
129
|
## Runtime Configuration
|
|
138
130
|
|
|
139
131
|
### Docker Image
|
{opensandbox_code_interpreter-0.1.2 → opensandbox_code_interpreter-0.1.2.dev0}/pyproject.toml
RENAMED
|
@@ -42,14 +42,14 @@ classifiers = [
|
|
|
42
42
|
"Typing :: Typed",
|
|
43
43
|
]
|
|
44
44
|
dependencies = [
|
|
45
|
-
"pydantic>=2.
|
|
46
|
-
"opensandbox>=0.1.
|
|
45
|
+
"pydantic>=2.0.0,<3.0",
|
|
46
|
+
"opensandbox>=0.1.1,<0.2.0",
|
|
47
47
|
]
|
|
48
48
|
|
|
49
49
|
[project.urls]
|
|
50
|
-
Homepage = "https://
|
|
50
|
+
Homepage = "https://github.com/alibaba/OpenSandbox"
|
|
51
51
|
Repository = "https://github.com/alibaba/OpenSandbox"
|
|
52
|
-
Documentation = "https://
|
|
52
|
+
Documentation = "https://docs.opensandbox.io"
|
|
53
53
|
Issues = "https://github.com/alibaba/OpenSandbox/issues"
|
|
54
54
|
|
|
55
55
|
[tool.hatch.version]
|
|
@@ -22,7 +22,6 @@ API clients and handling SSE streaming for real-time code execution.
|
|
|
22
22
|
|
|
23
23
|
import json
|
|
24
24
|
import logging
|
|
25
|
-
import time
|
|
26
25
|
|
|
27
26
|
import httpx
|
|
28
27
|
from opensandbox.adapters.converter.event_node import EventNode
|
|
@@ -33,7 +32,6 @@ from opensandbox.adapters.converter.execution_event_dispatcher import (
|
|
|
33
32
|
ExecutionEventDispatcher,
|
|
34
33
|
)
|
|
35
34
|
from opensandbox.adapters.converter.response_handler import (
|
|
36
|
-
extract_request_id,
|
|
37
35
|
handle_api_error,
|
|
38
36
|
require_parsed,
|
|
39
37
|
)
|
|
@@ -51,22 +49,6 @@ from code_interpreter.services.code import Codes
|
|
|
51
49
|
logger = logging.getLogger(__name__)
|
|
52
50
|
|
|
53
51
|
|
|
54
|
-
def _normalize_sse_event(event_dict: dict) -> dict:
|
|
55
|
-
if "type" in event_dict and "timestamp" in event_dict:
|
|
56
|
-
return event_dict
|
|
57
|
-
if "code" in event_dict and "message" in event_dict:
|
|
58
|
-
return {
|
|
59
|
-
"type": "error",
|
|
60
|
-
"timestamp": int(time.time() * 1000),
|
|
61
|
-
"error": {
|
|
62
|
-
"ename": str(event_dict["code"]),
|
|
63
|
-
"evalue": str(event_dict["message"]),
|
|
64
|
-
"traceback": [],
|
|
65
|
-
},
|
|
66
|
-
}
|
|
67
|
-
return event_dict
|
|
68
|
-
|
|
69
|
-
|
|
70
52
|
class CodesAdapter(Codes):
|
|
71
53
|
"""
|
|
72
54
|
Adapter implementation for code execution service.
|
|
@@ -106,7 +88,6 @@ class CodesAdapter(Codes):
|
|
|
106
88
|
headers = {
|
|
107
89
|
"User-Agent": self.connection_config.user_agent,
|
|
108
90
|
**self.connection_config.headers,
|
|
109
|
-
**self.execd_endpoint.headers,
|
|
110
91
|
}
|
|
111
92
|
|
|
112
93
|
# Execd API does not require authentication
|
|
@@ -306,7 +287,6 @@ class CodesAdapter(Codes):
|
|
|
306
287
|
raise SandboxApiException(
|
|
307
288
|
message=f"Failed to run code. Status code: {response.status_code}",
|
|
308
289
|
status_code=response.status_code,
|
|
309
|
-
request_id=extract_request_id(response.headers),
|
|
310
290
|
)
|
|
311
291
|
|
|
312
292
|
dispatcher = ExecutionEventDispatcher(execution, handlers)
|
|
@@ -321,7 +301,7 @@ class CodesAdapter(Codes):
|
|
|
321
301
|
data = data[5:].strip()
|
|
322
302
|
|
|
323
303
|
try:
|
|
324
|
-
event_dict =
|
|
304
|
+
event_dict = json.loads(data)
|
|
325
305
|
event_node = EventNode(**event_dict)
|
|
326
306
|
await dispatcher.dispatch(event_node)
|
|
327
307
|
except json.JSONDecodeError:
|
|
@@ -19,7 +19,6 @@ Synchronous adapter for code execution service (including SSE streaming).
|
|
|
19
19
|
|
|
20
20
|
import json
|
|
21
21
|
import logging
|
|
22
|
-
import time
|
|
23
22
|
|
|
24
23
|
import httpx
|
|
25
24
|
from opensandbox.adapters.converter.event_node import EventNode
|
|
@@ -27,7 +26,6 @@ from opensandbox.adapters.converter.exception_converter import (
|
|
|
27
26
|
ExceptionConverter,
|
|
28
27
|
)
|
|
29
28
|
from opensandbox.adapters.converter.response_handler import (
|
|
30
|
-
extract_request_id,
|
|
31
29
|
handle_api_error,
|
|
32
30
|
require_parsed,
|
|
33
31
|
)
|
|
@@ -46,22 +44,6 @@ from code_interpreter.sync.services.code import CodesSync
|
|
|
46
44
|
logger = logging.getLogger(__name__)
|
|
47
45
|
|
|
48
46
|
|
|
49
|
-
def _normalize_sse_event(event_dict: dict) -> dict:
|
|
50
|
-
if "type" in event_dict and "timestamp" in event_dict:
|
|
51
|
-
return event_dict
|
|
52
|
-
if "code" in event_dict and "message" in event_dict:
|
|
53
|
-
return {
|
|
54
|
-
"type": "error",
|
|
55
|
-
"timestamp": int(time.time() * 1000),
|
|
56
|
-
"error": {
|
|
57
|
-
"ename": str(event_dict["code"]),
|
|
58
|
-
"evalue": str(event_dict["message"]),
|
|
59
|
-
"traceback": [],
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
return event_dict
|
|
63
|
-
|
|
64
|
-
|
|
65
47
|
class CodesAdapterSync(CodesSync):
|
|
66
48
|
"""
|
|
67
49
|
Synchronous adapter for code execution service.
|
|
@@ -81,9 +63,7 @@ class CodesAdapterSync(CodesSync):
|
|
|
81
63
|
RUN_CODE_PATH = "/code"
|
|
82
64
|
CREATE_CONTEXT_PATH = "/code/context"
|
|
83
65
|
|
|
84
|
-
def __init__(
|
|
85
|
-
self, execd_endpoint: SandboxEndpoint, connection_config: ConnectionConfigSync
|
|
86
|
-
) -> None:
|
|
66
|
+
def __init__(self, execd_endpoint: SandboxEndpoint, connection_config: ConnectionConfigSync) -> None:
|
|
87
67
|
"""
|
|
88
68
|
Initialize the code service adapter (sync).
|
|
89
69
|
|
|
@@ -98,11 +78,7 @@ class CodesAdapterSync(CodesSync):
|
|
|
98
78
|
base_url = f"{self.connection_config.protocol}://{self.execd_endpoint.endpoint}"
|
|
99
79
|
timeout_seconds = self.connection_config.request_timeout.total_seconds()
|
|
100
80
|
timeout = httpx.Timeout(timeout_seconds)
|
|
101
|
-
headers = {
|
|
102
|
-
"User-Agent": self.connection_config.user_agent,
|
|
103
|
-
**self.connection_config.headers,
|
|
104
|
-
**(self.execd_endpoint.headers or {}),
|
|
105
|
-
}
|
|
81
|
+
headers = {"User-Agent": self.connection_config.user_agent, **self.connection_config.headers}
|
|
106
82
|
|
|
107
83
|
self._client = Client(base_url=base_url, timeout=timeout)
|
|
108
84
|
self._httpx_client = httpx.Client(
|
|
@@ -113,24 +89,16 @@ class CodesAdapterSync(CodesSync):
|
|
|
113
89
|
)
|
|
114
90
|
self._client.set_httpx_client(self._httpx_client)
|
|
115
91
|
|
|
116
|
-
sse_headers = {
|
|
117
|
-
**headers,
|
|
118
|
-
"Accept": "text/event-stream",
|
|
119
|
-
"Cache-Control": "no-cache",
|
|
120
|
-
}
|
|
92
|
+
sse_headers = {**headers, "Accept": "text/event-stream", "Cache-Control": "no-cache"}
|
|
121
93
|
self._sse_client = httpx.Client(
|
|
122
94
|
headers=sse_headers,
|
|
123
|
-
timeout=httpx.Timeout(
|
|
124
|
-
connect=timeout_seconds, read=None, write=timeout_seconds, pool=None
|
|
125
|
-
),
|
|
95
|
+
timeout=httpx.Timeout(connect=timeout_seconds, read=None, write=timeout_seconds, pool=None),
|
|
126
96
|
transport=self.connection_config.transport,
|
|
127
97
|
)
|
|
128
98
|
|
|
129
99
|
def _get_execd_url(self, path: str) -> str:
|
|
130
100
|
"""Build URL for execd endpoint."""
|
|
131
|
-
return
|
|
132
|
-
f"{self.connection_config.protocol}://{self.execd_endpoint.endpoint}{path}"
|
|
133
|
-
)
|
|
101
|
+
return f"{self.connection_config.protocol}://{self.execd_endpoint.endpoint}{path}"
|
|
134
102
|
|
|
135
103
|
def create_context(self, language: str) -> CodeContextSync:
|
|
136
104
|
"""
|
|
@@ -257,11 +225,7 @@ class CodesAdapterSync(CodesSync):
|
|
|
257
225
|
raise InvalidArgumentException("Code cannot be empty")
|
|
258
226
|
|
|
259
227
|
try:
|
|
260
|
-
if
|
|
261
|
-
context is not None
|
|
262
|
-
and language is not None
|
|
263
|
-
and context.language != language
|
|
264
|
-
):
|
|
228
|
+
if context is not None and language is not None and context.language != language:
|
|
265
229
|
raise InvalidArgumentException(
|
|
266
230
|
f"language '{language}' must match context.language '{context.language}'"
|
|
267
231
|
)
|
|
@@ -269,9 +233,7 @@ class CodesAdapterSync(CodesSync):
|
|
|
269
233
|
if context is None:
|
|
270
234
|
# Default context: language default context (server-side behavior).
|
|
271
235
|
# When context.id is omitted, execd will create/reuse a default session per language.
|
|
272
|
-
context = CodeContextSync(
|
|
273
|
-
language=language or SupportedLanguageSync.PYTHON
|
|
274
|
-
)
|
|
236
|
+
context = CodeContextSync(language=language or SupportedLanguageSync.PYTHON)
|
|
275
237
|
api_request = {
|
|
276
238
|
"code": code,
|
|
277
239
|
"context": {
|
|
@@ -290,7 +252,6 @@ class CodesAdapterSync(CodesSync):
|
|
|
290
252
|
raise SandboxApiException(
|
|
291
253
|
message=f"Failed to run code. Status code: {response.status_code}",
|
|
292
254
|
status_code=response.status_code,
|
|
293
|
-
request_id=extract_request_id(response.headers),
|
|
294
255
|
)
|
|
295
256
|
|
|
296
257
|
for line in response.iter_lines():
|
|
@@ -300,7 +261,7 @@ class CodesAdapterSync(CodesSync):
|
|
|
300
261
|
if data.startswith("data:"):
|
|
301
262
|
data = data[5:].strip()
|
|
302
263
|
try:
|
|
303
|
-
event_dict =
|
|
264
|
+
event_dict = json.loads(data)
|
|
304
265
|
event_node = EventNode(**event_dict)
|
|
305
266
|
dispatcher.dispatch(event_node)
|
|
306
267
|
except json.JSONDecodeError:
|
|
@@ -325,9 +286,7 @@ class CodesAdapterSync(CodesSync):
|
|
|
325
286
|
try:
|
|
326
287
|
from opensandbox.api.execd.api.code_interpreting import interrupt_code
|
|
327
288
|
|
|
328
|
-
response_obj = interrupt_code.sync_detailed(
|
|
329
|
-
client=self._client, id=execution_id
|
|
330
|
-
)
|
|
289
|
+
response_obj = interrupt_code.sync_detailed(client=self._client, id=execution_id)
|
|
331
290
|
handle_api_error(response_obj, "Interrupt code execution")
|
|
332
291
|
except Exception as e:
|
|
333
292
|
logger.error("Failed to interrupt code execution", exc_info=e)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|