opensandbox-code-interpreter 1.1.1__tar.gz → 1.2.0__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-1.1.1 → opensandbox_code_interpreter-1.2.0}/PKG-INFO +9 -18
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/README.md +7 -16
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/pyproject.toml +1 -1
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/adapters/code_adapter.py +9 -14
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/sync/adapters/code_adapter.py +8 -13
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/.gitignore +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/LICENSE +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/__init__.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/adapters/__init__.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/adapters/converter/__init__.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/adapters/converter/code_execution_converter.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/adapters/factory.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/code_interpreter.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/models/__init__.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/models/code.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/models/code_sync.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/py.typed +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/services/__init__.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/services/code.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/sync/__init__.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/sync/adapters/__init__.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/sync/adapters/factory.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/sync/code_interpreter.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/sync/services/__init__.py +0 -0
- {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.0}/src/code_interpreter/sync/services/code.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: opensandbox-code-interpreter
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: OpenSandbox Code Interpreter Python SDK - Advanced code execution with persistent contexts
|
|
5
5
|
Project-URL: Homepage, https://open-sandbox.ai
|
|
6
6
|
Project-URL: Repository, https://github.com/opensandbox-group/OpenSandbox
|
|
@@ -223,24 +223,20 @@ 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<2.0.0,>=1.
|
|
226
|
+
Requires-Dist: opensandbox<2.0.0,>=1.2.0
|
|
227
227
|
Requires-Dist: pydantic<3.0,>=2.4.2
|
|
228
228
|
Description-Content-Type: text/markdown
|
|
229
229
|
|
|
230
230
|
# OpenSandbox Code Interpreter SDK for Python
|
|
231
231
|
|
|
232
232
|
|
|
233
|
-
A Python SDK for executing code in secure, isolated sandboxes. It provides a high-level API for running Python, Java,
|
|
234
|
-
Go, TypeScript, and other languages safely, with support for code execution contexts.
|
|
233
|
+
A Python SDK for executing code in secure, isolated sandboxes. It provides a high-level API for running Python, Java, Go, TypeScript, and other languages safely, with support for code execution contexts.
|
|
235
234
|
|
|
236
235
|
## Prerequisites
|
|
237
236
|
|
|
238
|
-
This SDK requires a Docker image containing the Code Interpreter runtime environment. You must use the
|
|
239
|
-
`opensandbox/code-interpreter` image (or a derivative) which includes pre-installed runtimes for Python, Java, Go,
|
|
240
|
-
Node.js, etc.
|
|
237
|
+
This SDK requires a Docker image containing the Code Interpreter runtime environment. You must use the `opensandbox/code-interpreter` image (or a derivative) which includes pre-installed runtimes for Python, Java, Go, Node.js, etc.
|
|
241
238
|
|
|
242
|
-
For detailed information about supported languages and versions, refer to the
|
|
243
|
-
[Environment Documentation](https://github.com/opensandbox-group/sandbox-images).
|
|
239
|
+
For detailed information about supported languages and versions, refer to the [Environment Documentation](https://github.com/opensandbox-group/sandbox-images).
|
|
244
240
|
|
|
245
241
|
## Installation
|
|
246
242
|
|
|
@@ -258,8 +254,7 @@ uv add opensandbox-code-interpreter
|
|
|
258
254
|
|
|
259
255
|
## Quick Start
|
|
260
256
|
|
|
261
|
-
The following example demonstrates how to create a sandbox with a specific runtime configuration and execute a simple
|
|
262
|
-
script.
|
|
257
|
+
The following example demonstrates how to create a sandbox with a specific runtime configuration and execute a simple script.
|
|
263
258
|
|
|
264
259
|
```python
|
|
265
260
|
import asyncio
|
|
@@ -366,13 +361,11 @@ execution = await sandbox.commands.run("pip install pandas numpy")
|
|
|
366
361
|
|
|
367
362
|
### Docker Image
|
|
368
363
|
|
|
369
|
-
The Code Interpreter SDK relies on a specialized environment. Ensure your sandbox provider has the
|
|
370
|
-
`opensandbox/code-interpreter` image available.
|
|
364
|
+
The Code Interpreter SDK relies on a specialized environment. Ensure your sandbox provider has the `opensandbox/code-interpreter` image available.
|
|
371
365
|
|
|
372
366
|
### Language Version Selection
|
|
373
367
|
|
|
374
|
-
You can specify the desired version of a programming language by setting the corresponding environment variable when
|
|
375
|
-
creating the `Sandbox`.
|
|
368
|
+
You can specify the desired version of a programming language by setting the corresponding environment variable when creating the `Sandbox`.
|
|
376
369
|
|
|
377
370
|
| Language | Environment Variable | Example Value | Default (if unset) |
|
|
378
371
|
| -------- | -------------------- | ------------- | ------------------ |
|
|
@@ -385,9 +378,7 @@ creating the `Sandbox`.
|
|
|
385
378
|
|
|
386
379
|
### 0. Run with `language` (default language context)
|
|
387
380
|
|
|
388
|
-
You can pass `language` directly (recommended: `SupportedLanguage.*`) and skip `create_context`.
|
|
389
|
-
When `context.id` is omitted, **execd will create/reuse a default session for that language**, so
|
|
390
|
-
state can persist across runs:
|
|
381
|
+
You can pass `language` directly (recommended: `SupportedLanguage.*`) and skip `create_context`. When `context.id` is omitted, **execd will create/reuse a default session for that language**, so state can persist across runs:
|
|
391
382
|
|
|
392
383
|
```python
|
|
393
384
|
from code_interpreter import SupportedLanguage
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
# OpenSandbox Code Interpreter SDK for Python
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
A Python SDK for executing code in secure, isolated sandboxes. It provides a high-level API for running Python, Java,
|
|
5
|
-
Go, TypeScript, and other languages safely, with support for code execution contexts.
|
|
4
|
+
A Python SDK for executing code in secure, isolated sandboxes. It provides a high-level API for running Python, Java, Go, TypeScript, and other languages safely, with support for code execution contexts.
|
|
6
5
|
|
|
7
6
|
## Prerequisites
|
|
8
7
|
|
|
9
|
-
This SDK requires a Docker image containing the Code Interpreter runtime environment. You must use the
|
|
10
|
-
`opensandbox/code-interpreter` image (or a derivative) which includes pre-installed runtimes for Python, Java, Go,
|
|
11
|
-
Node.js, etc.
|
|
8
|
+
This SDK requires a Docker image containing the Code Interpreter runtime environment. You must use the `opensandbox/code-interpreter` image (or a derivative) which includes pre-installed runtimes for Python, Java, Go, Node.js, etc.
|
|
12
9
|
|
|
13
|
-
For detailed information about supported languages and versions, refer to the
|
|
14
|
-
[Environment Documentation](https://github.com/opensandbox-group/sandbox-images).
|
|
10
|
+
For detailed information about supported languages and versions, refer to the [Environment Documentation](https://github.com/opensandbox-group/sandbox-images).
|
|
15
11
|
|
|
16
12
|
## Installation
|
|
17
13
|
|
|
@@ -29,8 +25,7 @@ uv add opensandbox-code-interpreter
|
|
|
29
25
|
|
|
30
26
|
## Quick Start
|
|
31
27
|
|
|
32
|
-
The following example demonstrates how to create a sandbox with a specific runtime configuration and execute a simple
|
|
33
|
-
script.
|
|
28
|
+
The following example demonstrates how to create a sandbox with a specific runtime configuration and execute a simple script.
|
|
34
29
|
|
|
35
30
|
```python
|
|
36
31
|
import asyncio
|
|
@@ -137,13 +132,11 @@ execution = await sandbox.commands.run("pip install pandas numpy")
|
|
|
137
132
|
|
|
138
133
|
### Docker Image
|
|
139
134
|
|
|
140
|
-
The Code Interpreter SDK relies on a specialized environment. Ensure your sandbox provider has the
|
|
141
|
-
`opensandbox/code-interpreter` image available.
|
|
135
|
+
The Code Interpreter SDK relies on a specialized environment. Ensure your sandbox provider has the `opensandbox/code-interpreter` image available.
|
|
142
136
|
|
|
143
137
|
### Language Version Selection
|
|
144
138
|
|
|
145
|
-
You can specify the desired version of a programming language by setting the corresponding environment variable when
|
|
146
|
-
creating the `Sandbox`.
|
|
139
|
+
You can specify the desired version of a programming language by setting the corresponding environment variable when creating the `Sandbox`.
|
|
147
140
|
|
|
148
141
|
| Language | Environment Variable | Example Value | Default (if unset) |
|
|
149
142
|
| -------- | -------------------- | ------------- | ------------------ |
|
|
@@ -156,9 +149,7 @@ creating the `Sandbox`.
|
|
|
156
149
|
|
|
157
150
|
### 0. Run with `language` (default language context)
|
|
158
151
|
|
|
159
|
-
You can pass `language` directly (recommended: `SupportedLanguage.*`) and skip `create_context`.
|
|
160
|
-
When `context.id` is omitted, **execd will create/reuse a default session for that language**, so
|
|
161
|
-
state can persist across runs:
|
|
152
|
+
You can pass `language` directly (recommended: `SupportedLanguage.*`) and skip `create_context`. When `context.id` is omitted, **execd will create/reuse a default session for that language**, so state can persist across runs:
|
|
162
153
|
|
|
163
154
|
```python
|
|
164
155
|
from code_interpreter import SupportedLanguage
|
|
@@ -33,15 +33,15 @@ from opensandbox.adapters.converter.execution_event_dispatcher import (
|
|
|
33
33
|
ExecutionEventDispatcher,
|
|
34
34
|
)
|
|
35
35
|
from opensandbox.adapters.converter.response_handler import (
|
|
36
|
-
|
|
36
|
+
build_api_exception_from_httpx,
|
|
37
37
|
handle_api_error,
|
|
38
38
|
require_parsed,
|
|
39
39
|
)
|
|
40
40
|
from opensandbox.config import ConnectionConfig
|
|
41
|
-
from opensandbox.exceptions import InvalidArgumentException
|
|
41
|
+
from opensandbox.exceptions import InvalidArgumentException
|
|
42
42
|
from opensandbox.models.execd import Execution, ExecutionHandlers
|
|
43
43
|
from opensandbox.models.sandboxes import SandboxEndpoint
|
|
44
|
-
from opensandbox.transport import
|
|
44
|
+
from opensandbox.transport import streaming_transport
|
|
45
45
|
|
|
46
46
|
from code_interpreter.adapters.converter.code_execution_converter import (
|
|
47
47
|
CodeExecutionConverter,
|
|
@@ -128,9 +128,8 @@ class CodesAdapter(Codes):
|
|
|
128
128
|
"Accept": "text/event-stream",
|
|
129
129
|
"Cache-Control": "no-cache",
|
|
130
130
|
}
|
|
131
|
-
# SSE bootstraps
|
|
132
|
-
#
|
|
133
|
-
# duplicate execution on a resent SSE POST.
|
|
131
|
+
# SSE bootstraps keep only the wake-timeout retry: a non-idempotent
|
|
132
|
+
# status opt-in would cause duplicate execution on a resent SSE POST.
|
|
134
133
|
sse_transport = (
|
|
135
134
|
self.connection_config.new_owned_transport()
|
|
136
135
|
if self._owns_clients
|
|
@@ -144,7 +143,7 @@ class CodesAdapter(Codes):
|
|
|
144
143
|
write=timeout_seconds,
|
|
145
144
|
pool=None,
|
|
146
145
|
),
|
|
147
|
-
transport=
|
|
146
|
+
transport=streaming_transport(sse_transport),
|
|
148
147
|
)
|
|
149
148
|
|
|
150
149
|
async def _get_client(self):
|
|
@@ -316,6 +315,7 @@ class CodesAdapter(Codes):
|
|
|
316
315
|
result=[],
|
|
317
316
|
error=None,
|
|
318
317
|
)
|
|
318
|
+
execution._is_code_execution = True
|
|
319
319
|
|
|
320
320
|
# Use SSE client for streaming responses (read timeout disabled)
|
|
321
321
|
client = await self._get_sse_client()
|
|
@@ -324,15 +324,10 @@ class CodesAdapter(Codes):
|
|
|
324
324
|
async with client.stream("POST", url, json=api_request) as response:
|
|
325
325
|
if response.status_code != 200:
|
|
326
326
|
await response.aread()
|
|
327
|
-
error_body = response.text
|
|
328
327
|
logger.error(
|
|
329
|
-
f"Failed to run code. Status: {response.status_code}, Body: {
|
|
330
|
-
)
|
|
331
|
-
raise SandboxApiException(
|
|
332
|
-
message=f"Failed to run code. Status code: {response.status_code}, Body: {error_body}",
|
|
333
|
-
status_code=response.status_code,
|
|
334
|
-
request_id=extract_request_id(response.headers),
|
|
328
|
+
f"Failed to run code. Status: {response.status_code}, Body: {response.text}"
|
|
335
329
|
)
|
|
330
|
+
raise build_api_exception_from_httpx(response, "Run code")
|
|
336
331
|
|
|
337
332
|
dispatcher = ExecutionEventDispatcher(execution, handlers)
|
|
338
333
|
|
|
@@ -27,19 +27,19 @@ from opensandbox.adapters.converter.exception_converter import (
|
|
|
27
27
|
ExceptionConverter,
|
|
28
28
|
)
|
|
29
29
|
from opensandbox.adapters.converter.response_handler import (
|
|
30
|
-
|
|
30
|
+
build_api_exception_from_httpx,
|
|
31
31
|
handle_api_error,
|
|
32
32
|
require_parsed,
|
|
33
33
|
)
|
|
34
34
|
from opensandbox.config.connection_sync import ConnectionConfigSync
|
|
35
|
-
from opensandbox.exceptions import InvalidArgumentException
|
|
35
|
+
from opensandbox.exceptions import InvalidArgumentException
|
|
36
36
|
from opensandbox.models.execd import Execution
|
|
37
37
|
from opensandbox.models.execd_sync import ExecutionHandlersSync
|
|
38
38
|
from opensandbox.models.sandboxes import SandboxEndpoint
|
|
39
39
|
from opensandbox.sync.adapters.converter.execution_event_dispatcher import (
|
|
40
40
|
ExecutionEventDispatcherSync,
|
|
41
41
|
)
|
|
42
|
-
from opensandbox.transport import
|
|
42
|
+
from opensandbox.transport import streaming_transport
|
|
43
43
|
|
|
44
44
|
from code_interpreter.models.code_sync import CodeContextSync, SupportedLanguageSync
|
|
45
45
|
from code_interpreter.sync.services.code import CodesSync
|
|
@@ -123,9 +123,8 @@ class CodesAdapterSync(CodesSync):
|
|
|
123
123
|
"Accept": "text/event-stream",
|
|
124
124
|
"Cache-Control": "no-cache",
|
|
125
125
|
}
|
|
126
|
-
# SSE bootstraps
|
|
127
|
-
#
|
|
128
|
-
# duplicate execution on a resent SSE POST.
|
|
126
|
+
# SSE bootstraps keep only the wake-timeout retry: a non-idempotent
|
|
127
|
+
# status opt-in would cause duplicate execution on a resent SSE POST.
|
|
129
128
|
sse_transport = (
|
|
130
129
|
self.connection_config.new_owned_transport()
|
|
131
130
|
if self._owns_clients
|
|
@@ -136,7 +135,7 @@ class CodesAdapterSync(CodesSync):
|
|
|
136
135
|
timeout=httpx.Timeout(
|
|
137
136
|
connect=timeout_seconds, read=None, write=timeout_seconds, pool=None
|
|
138
137
|
),
|
|
139
|
-
transport=
|
|
138
|
+
transport=streaming_transport(sse_transport),
|
|
140
139
|
)
|
|
141
140
|
|
|
142
141
|
def _get_execd_url(self, path: str) -> str:
|
|
@@ -310,17 +309,13 @@ class CodesAdapterSync(CodesSync):
|
|
|
310
309
|
|
|
311
310
|
url = self._get_execd_url(self.RUN_CODE_PATH)
|
|
312
311
|
execution = Execution(id=None, execution_count=None, result=[], error=None)
|
|
312
|
+
execution._is_code_execution = True
|
|
313
313
|
dispatcher = ExecutionEventDispatcherSync(execution, handlers)
|
|
314
314
|
|
|
315
315
|
with self._sse_client.stream("POST", url, json=api_request) as response:
|
|
316
316
|
if response.status_code != 200:
|
|
317
317
|
response.read()
|
|
318
|
-
|
|
319
|
-
raise SandboxApiException(
|
|
320
|
-
message=f"Failed to run code. Status code: {response.status_code}, Body: {error_body}",
|
|
321
|
-
status_code=response.status_code,
|
|
322
|
-
request_id=extract_request_id(response.headers),
|
|
323
|
-
)
|
|
318
|
+
raise build_api_exception_from_httpx(response, "Run code")
|
|
324
319
|
|
|
325
320
|
for line in response.iter_lines():
|
|
326
321
|
if not line or not line.strip():
|
|
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
|
|
File without changes
|
|
File without changes
|