opensandbox-code-interpreter 1.1.1__tar.gz → 1.2.1__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.
Files changed (25) hide show
  1. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/.gitignore +4 -0
  2. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/PKG-INFO +9 -18
  3. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/README.md +7 -16
  4. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/pyproject.toml +1 -1
  5. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/adapters/code_adapter.py +9 -15
  6. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/sync/adapters/code_adapter.py +8 -14
  7. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/LICENSE +0 -0
  8. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/__init__.py +0 -0
  9. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/adapters/__init__.py +0 -0
  10. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/adapters/converter/__init__.py +0 -0
  11. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/adapters/converter/code_execution_converter.py +0 -0
  12. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/adapters/factory.py +0 -0
  13. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/code_interpreter.py +0 -0
  14. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/models/__init__.py +0 -0
  15. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/models/code.py +0 -0
  16. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/models/code_sync.py +0 -0
  17. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/py.typed +0 -0
  18. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/services/__init__.py +0 -0
  19. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/services/code.py +0 -0
  20. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/sync/__init__.py +0 -0
  21. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/sync/adapters/__init__.py +0 -0
  22. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/sync/adapters/factory.py +0 -0
  23. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/sync/code_interpreter.py +0 -0
  24. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/sync/services/__init__.py +0 -0
  25. {opensandbox_code_interpreter-1.1.1 → opensandbox_code_interpreter-1.2.1}/src/code_interpreter/sync/services/code.py +0 -0
@@ -294,3 +294,7 @@ obj/
294
294
  # fast-sandbox pinned source checkout (materialized by
295
295
  # manifests/release/build-fast-sandbox.sh from manifests/third-party/fast-sandbox.commit)
296
296
  .fast-sandbox/
297
+
298
+ # Test-only localhost certificate pair for the egress OSEP-0025 resolver stub
299
+ # (fixtures/README.md documents regeneration; these certify nothing).
300
+ !components/egress/tests/resolver/fixtures/*.pem
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: opensandbox-code-interpreter
3
- Version: 1.1.1
3
+ Version: 1.2.1
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.1.1
226
+ Requires-Dist: opensandbox<2.0.0,>=1.2.1
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
@@ -43,7 +43,7 @@ classifiers = [
43
43
  ]
44
44
  dependencies = [
45
45
  "pydantic>=2.4.2,<3.0",
46
- "opensandbox>=1.1.1,<2.0.0",
46
+ "opensandbox>=1.2.1,<2.0.0",
47
47
  ]
48
48
 
49
49
  [project.urls]
@@ -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
- extract_request_id,
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, SandboxApiException
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 unwrap_retry_transport
44
+ from opensandbox.transport import streaming_transport
45
45
 
46
46
  from code_interpreter.adapters.converter.code_execution_converter import (
47
47
  CodeExecutionConverter,
@@ -77,7 +77,6 @@ class CodesAdapter(Codes):
77
77
  """
78
78
 
79
79
  RUN_CODE_PATH = "/code"
80
- CREATE_CONTEXT_PATH = "/code/context"
81
80
 
82
81
  def __init__(
83
82
  self, execd_endpoint: SandboxEndpoint, connection_config: ConnectionConfig
@@ -128,9 +127,8 @@ class CodesAdapter(Codes):
128
127
  "Accept": "text/event-stream",
129
128
  "Cache-Control": "no-cache",
130
129
  }
131
- # SSE bootstraps bypass the retry wrapper: request bodies are
132
- # not replayable and a non-idempotent status opt-in would cause
133
- # duplicate execution on a resent SSE POST.
130
+ # SSE bootstraps keep only the wake-timeout retry: a non-idempotent
131
+ # status opt-in would cause duplicate execution on a resent SSE POST.
134
132
  sse_transport = (
135
133
  self.connection_config.new_owned_transport()
136
134
  if self._owns_clients
@@ -144,7 +142,7 @@ class CodesAdapter(Codes):
144
142
  write=timeout_seconds,
145
143
  pool=None,
146
144
  ),
147
- transport=unwrap_retry_transport(sse_transport),
145
+ transport=streaming_transport(sse_transport),
148
146
  )
149
147
 
150
148
  async def _get_client(self):
@@ -316,6 +314,7 @@ class CodesAdapter(Codes):
316
314
  result=[],
317
315
  error=None,
318
316
  )
317
+ execution._is_code_execution = True
319
318
 
320
319
  # Use SSE client for streaming responses (read timeout disabled)
321
320
  client = await self._get_sse_client()
@@ -324,15 +323,10 @@ class CodesAdapter(Codes):
324
323
  async with client.stream("POST", url, json=api_request) as response:
325
324
  if response.status_code != 200:
326
325
  await response.aread()
327
- error_body = response.text
328
326
  logger.error(
329
- f"Failed to run code. Status: {response.status_code}, Body: {error_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),
327
+ f"Failed to run code. Status: {response.status_code}, Body: {response.text}"
335
328
  )
329
+ raise build_api_exception_from_httpx(response, "Run code")
336
330
 
337
331
  dispatcher = ExecutionEventDispatcher(execution, handlers)
338
332
 
@@ -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
- extract_request_id,
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, SandboxApiException
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 unwrap_retry_transport
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
@@ -80,7 +80,6 @@ class CodesAdapterSync(CodesSync):
80
80
  """
81
81
 
82
82
  RUN_CODE_PATH = "/code"
83
- CREATE_CONTEXT_PATH = "/code/context"
84
83
 
85
84
  def __init__(
86
85
  self, execd_endpoint: SandboxEndpoint, connection_config: ConnectionConfigSync
@@ -123,9 +122,8 @@ class CodesAdapterSync(CodesSync):
123
122
  "Accept": "text/event-stream",
124
123
  "Cache-Control": "no-cache",
125
124
  }
126
- # SSE bootstraps bypass the retry wrapper: request bodies are
127
- # not replayable and a non-idempotent status opt-in would cause
128
- # duplicate execution on a resent SSE POST.
125
+ # SSE bootstraps keep only the wake-timeout retry: a non-idempotent
126
+ # status opt-in would cause duplicate execution on a resent SSE POST.
129
127
  sse_transport = (
130
128
  self.connection_config.new_owned_transport()
131
129
  if self._owns_clients
@@ -136,7 +134,7 @@ class CodesAdapterSync(CodesSync):
136
134
  timeout=httpx.Timeout(
137
135
  connect=timeout_seconds, read=None, write=timeout_seconds, pool=None
138
136
  ),
139
- transport=unwrap_retry_transport(sse_transport),
137
+ transport=streaming_transport(sse_transport),
140
138
  )
141
139
 
142
140
  def _get_execd_url(self, path: str) -> str:
@@ -310,17 +308,13 @@ class CodesAdapterSync(CodesSync):
310
308
 
311
309
  url = self._get_execd_url(self.RUN_CODE_PATH)
312
310
  execution = Execution(id=None, execution_count=None, result=[], error=None)
311
+ execution._is_code_execution = True
313
312
  dispatcher = ExecutionEventDispatcherSync(execution, handlers)
314
313
 
315
314
  with self._sse_client.stream("POST", url, json=api_request) as response:
316
315
  if response.status_code != 200:
317
316
  response.read()
318
- error_body = response.text
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
- )
317
+ raise build_api_exception_from_httpx(response, "Run code")
324
318
 
325
319
  for line in response.iter_lines():
326
320
  if not line or not line.strip():