solari-e2b-compat 0.2.1__tar.gz → 0.2.3__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 (22) hide show
  1. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/COMPAT.md +4 -3
  2. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/PKG-INFO +4 -4
  3. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/README.md +3 -3
  4. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/pyproject.toml +1 -1
  5. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/__init__.py +1 -1
  6. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_config.py +7 -2
  7. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_vendor_user.py +11 -0
  8. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/code_interpreter.py +3 -3
  9. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/.gitignore +0 -0
  10. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/LICENSE +0 -0
  11. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/LICENSE-E2B +0 -0
  12. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/NOTICE +0 -0
  13. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_box.py +0 -0
  14. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_commands.py +0 -0
  15. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_filesystem.py +0 -0
  16. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_loop.py +0 -0
  17. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_redact.py +0 -0
  18. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_sandbox.py +0 -0
  19. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_sync.py +0 -0
  20. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/_template.py +0 -0
  21. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/exceptions.py +0 -0
  22. {solari_e2b_compat-0.2.1 → solari_e2b_compat-0.2.3}/solari_e2b/models.py +0 -0
@@ -19,7 +19,7 @@ and the differences that are specific to Python.
19
19
  | E2B | Here |
20
20
  |---|---|
21
21
  | `E2B_API_KEY`, `api_key=` | Only `slr_…` keys are used; see README. |
22
- | `E2B_DOMAIN`, `E2B_API_URL`, `domain=`, `api_url=` | Honoured only when they point at Solari or loopback. |
22
+ | `E2B_DOMAIN`, `E2B_API_URL`, `domain=`, `api_url=` | Honoured only when they point at a Solari API host or loopback. |
23
23
  | `headers=`, `api_headers=`, `proxy=` | NO. |
24
24
  | `request_timeout=`, `debug=`, `logger=`, `validate_api_key=`, `retries=`, `http_version=`, `sandbox_url=` | Accepted, ignored (Solari's transport has its own retry policy). Every option that is accepted but ignored is marked "ignored" in this file; any other option either works or throws. |
25
25
  | `timeout=` arguments | Seconds, as in E2B. |
@@ -29,7 +29,7 @@ and the differences that are specific to Python.
29
29
  ## Sandbox
30
30
  | Call | Status | Notes |
31
31
  |---|---|---|
32
- | `Sandbox.create(template, timeout, metadata, envs, lifecycle, volume_mounts, ...)` | OK, live | `template`: `base`, a name from `Template.build`, or a `tpl_…` id. Default `base` (`code-interpreter-v1` in `solari_e2b.code_interpreter`). |
32
+ | `Sandbox.create(template, timeout, metadata, envs, lifecycle, volume_mounts, ...)` | OK, live | `template`: `base`, a name from `Template.build`, or a `tpl_…` id. Default `base` (`code-interpreter-v2` in `solari_e2b.code_interpreter`). |
33
33
  | `timeout` | DIFF | E2B's is a lifetime; Solari's is a rolling idle window that resets on use. Default 300 s as in E2B. The per-plan deadline still bounds total life. |
34
34
  | `lifecycle={'on_timeout': ..., 'auto_resume': ...}` | OK | `{'action': 'pause', 'mode': 'filesystem'}` pauses with RAM too (a superset). |
35
35
  | `volume_mounts={path: 'vol_…' or name}` | DIFF | Solari persistent volumes by id or name. `Volume` objects: NO. |
@@ -78,7 +78,7 @@ and the differences that are specific to Python.
78
78
  | `timeout=` | DIFF | Stops waiting and raises `TimeoutException`; the kernel keeps running the code. No default timeout. |
79
79
  | `create_code_context(cwd, language)` | OK, live | Python only. |
80
80
  | `list_code_contexts`, `remove_code_context`, `restart_code_context` | DIFF, live | Solari cannot list or destroy kernels. `list` returns contexts created by this process; `remove` forgets the context (the kernel stays until the sandbox ends); `restart` clears the context's variables and working directory without restarting the process. |
81
- | Default template | DIFF | `code-interpreter-v1` is built into your org on first `Sandbox.create()` without a template: about 80 seconds, billed as a template build, and two processes that both find it missing each start a build. `build_code_interpreter_template()` (async) / `build_code_interpreter_template_sync()` prebuild it. |
81
+ | Default template | DIFF | `code-interpreter-v2` is built into your org on first `Sandbox.create()` without a template: about 80 seconds, billed as a template build, and two processes that both find it missing each start a build. `build_code_interpreter_template()` (async) / `build_code_interpreter_template_sync()` prebuild it. |
82
82
 
83
83
  ## Templates
84
84
  | Call | Status | Notes |
@@ -105,6 +105,7 @@ asks the gateway for exactly that at create time (`user: "user"`, `cwd: "/home/u
105
105
  sudo). Restores from a snapshot keep the snapshot's own user.
106
106
  - **Gateway that predates `user` / `cwd`** (it answers 400 naming them, or ignores them): the plain create is used and the sandbox runs as **root in
107
107
  `/home/root`**, which is what this package did before. Check `whoami` if code depends on it.
108
+ - **Template or snapshot made before user support** (the server answers 400 naming `user` with "the guest predates user support"): the plain create is used, the sandbox runs as **root**, and one warning says so. Rebuild the template to get the vendor user. The default code-interpreter template is named `code-interpreter-v2`, so upgrading this package builds a fresh one on first `Sandbox.create()`; an older `code-interpreter-v1` in your org is left alone and no longer used.
108
109
  - Shared isolation is commands and code only and takes no `user` / `cwd`; the compat packages never create shared sandboxes. `commands.run(..., user=)` is passed to the guest per call; `user=` on filesystem calls stays NO.
109
110
 
110
111
  ## Snapshots, results and listing (0.2.1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: solari-e2b-compat
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: E2B-compatible Python interface (sandboxes and code interpreter) over Solari Sandboxes. Not affiliated with E2B.
5
5
  Project-URL: Homepage, https://getsolari.com
6
6
  Author: Solari
@@ -58,14 +58,14 @@ Do not call the blocking API from inside such a callback; use `AsyncSandbox` the
58
58
  | | Order |
59
59
  |---|---|
60
60
  | API key | `api_key=` option, `SOLARI_API_KEY`, `E2B_API_KEY`: only an `slr_…` Solari key is ever used. A non-`slr_` value (for example a real E2B key) is skipped with a warning (the key is never printed or sent); with no Solari key the call raises |
61
- | Base URL | `api_url=` / `domain=` option (Solari or loopback only, anything else raises), `SOLARI_BASE_URL`, `E2B_API_URL` / `E2B_DOMAIN` (only if they point at getsolari.com or loopback; otherwise ignored with a warning), default `https://api.getsolari.com` |
61
+ | Base URL | `api_url=` / `domain=` option (Solari or loopback only, anything else raises), `SOLARI_BASE_URL`, `E2B_API_URL` / `E2B_DOMAIN` (only if they point at a Solari API host or loopback; otherwise ignored with a warning), default `https://api.getsolari.com` |
62
62
 
63
63
  An E2B key does not work here: use a Solari API key.
64
64
 
65
65
  ## The code-interpreter template
66
66
 
67
67
  `e2b_code_interpreter` runs in a template with a data-analysis stack (pandas, numpy, scipy, scikit-learn, seaborn,
68
- plotly, ...). Solari builds the equivalent, `code-interpreter-v1`, into your org the first time `Sandbox.create()` is
68
+ plotly, ...). Solari builds the equivalent, `code-interpreter-v2`, into your org the first time `Sandbox.create()` is
69
69
  called without a template (about 80 seconds, once). To do it ahead of time:
70
70
 
71
71
  ```python
@@ -86,5 +86,5 @@ numba, gensim) are not included.
86
86
  ## Tests
87
87
 
88
88
  - `python -m pytest`: offline unit tests, a fake gateway.
89
- - `SOLARI_API_KEY=… SOLARI_BASE_URL=https://api-sta.getsolari.com python -m pytest -m live tests/test_live_staging.py`:
89
+ - `SOLARI_API_KEY=… SOLARI_BASE_URL=<a non-production gateway URL> python -m pytest -m live tests/test_live_staging.py`:
90
90
  live tests against staging. They create their own sandboxes, snapshots and templates and delete only those.
@@ -39,14 +39,14 @@ Do not call the blocking API from inside such a callback; use `AsyncSandbox` the
39
39
  | | Order |
40
40
  |---|---|
41
41
  | API key | `api_key=` option, `SOLARI_API_KEY`, `E2B_API_KEY`: only an `slr_…` Solari key is ever used. A non-`slr_` value (for example a real E2B key) is skipped with a warning (the key is never printed or sent); with no Solari key the call raises |
42
- | Base URL | `api_url=` / `domain=` option (Solari or loopback only, anything else raises), `SOLARI_BASE_URL`, `E2B_API_URL` / `E2B_DOMAIN` (only if they point at getsolari.com or loopback; otherwise ignored with a warning), default `https://api.getsolari.com` |
42
+ | Base URL | `api_url=` / `domain=` option (Solari or loopback only, anything else raises), `SOLARI_BASE_URL`, `E2B_API_URL` / `E2B_DOMAIN` (only if they point at a Solari API host or loopback; otherwise ignored with a warning), default `https://api.getsolari.com` |
43
43
 
44
44
  An E2B key does not work here: use a Solari API key.
45
45
 
46
46
  ## The code-interpreter template
47
47
 
48
48
  `e2b_code_interpreter` runs in a template with a data-analysis stack (pandas, numpy, scipy, scikit-learn, seaborn,
49
- plotly, ...). Solari builds the equivalent, `code-interpreter-v1`, into your org the first time `Sandbox.create()` is
49
+ plotly, ...). Solari builds the equivalent, `code-interpreter-v2`, into your org the first time `Sandbox.create()` is
50
50
  called without a template (about 80 seconds, once). To do it ahead of time:
51
51
 
52
52
  ```python
@@ -67,5 +67,5 @@ numba, gensim) are not included.
67
67
  ## Tests
68
68
 
69
69
  - `python -m pytest`: offline unit tests, a fake gateway.
70
- - `SOLARI_API_KEY=… SOLARI_BASE_URL=https://api-sta.getsolari.com python -m pytest -m live tests/test_live_staging.py`:
70
+ - `SOLARI_API_KEY=… SOLARI_BASE_URL=<a non-production gateway URL> python -m pytest -m live tests/test_live_staging.py`:
71
71
  live tests against staging. They create their own sandboxes, snapshots and templates and delete only those.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "solari-e2b-compat"
7
- version = "0.2.1"
7
+ version = "0.2.3"
8
8
  description = "E2B-compatible Python interface (sandboxes and code interpreter) over Solari Sandboxes. Not affiliated with E2B."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -36,4 +36,4 @@ from .models import * # noqa: F401,F403
36
36
  Volume = _Unsupported("Volume")
37
37
  Secret = _Unsupported("Secret")
38
38
 
39
- __version__ = "0.2.1"
39
+ __version__ = "0.2.3"
@@ -6,6 +6,7 @@ from __future__ import annotations
6
6
  import asyncio
7
7
  import logging
8
8
  import os
9
+ import re
9
10
  from dataclasses import dataclass
10
11
  from typing import Any, Callable, Dict, Optional, Tuple
11
12
  from urllib.parse import urlparse
@@ -32,14 +33,18 @@ IGNORED_OPTS = frozenset({"request_timeout", "debug", "logger", "validate_api_ke
32
33
  _HTTP_FACTORY: Optional[Callable[[], httpx.AsyncClient]] = None
33
34
 
34
35
 
36
+ #: The only Solari hosts that may receive a key (the API gateways). Not every *.getsolari.com host: preview hosts (<label>-<port>.preview.getsolari.com) serve customer code.
37
+ SOLARI_API_HOST = re.compile(r"api(-sta(-gcp)?)?\.getsolari\.com")
38
+
39
+
35
40
  def is_solari_base_url(raw: str) -> bool:
36
- """https on getsolari.com or a subdomain, or loopback over http(s)."""
41
+ """https on a Solari API host, or loopback over http(s)."""
37
42
  try:
38
43
  u = urlparse(raw)
39
44
  host = (u.hostname or "").lower().rstrip(".")
40
45
  except ValueError:
41
46
  return False
42
- if u.scheme == "https" and (host == "getsolari.com" or host.endswith(".getsolari.com")):
47
+ if u.scheme == "https" and SOLARI_API_HOST.fullmatch(host) is not None:
43
48
  return True
44
49
  return u.scheme in ("http", "https") and (host in ("localhost", "::1") or host.replace(".", "").isdigit() and host.startswith("127."))
45
50
 
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import re
6
+ import warnings
6
7
  from typing import Any
7
8
 
8
9
  from solari_core.errors import GatewayError
@@ -15,6 +16,15 @@ def _refuses_user_fields(e: BaseException) -> bool:
15
16
  return isinstance(e, GatewayError) and e.status == 400 and re.search(r"\b(user|cwd)\b", repr(getattr(e, "body", None)), re.I) is not None
16
17
 
17
18
 
19
+ def _warn_root() -> None:
20
+ warnings.warn(
21
+ "solari-e2b-compat: the server or this template's image predates user support, so the sandbox runs as root instead of 'user'. "
22
+ "Rebuild templates and snapshots made before user support shipped to get the vendor user.",
23
+ RuntimeWarning,
24
+ stacklevel=4,
25
+ )
26
+
27
+
18
28
  async def create_as_vendor_user(solari: Any, **opts: Any) -> Any:
19
29
  """``solari.create(**opts)`` with ``user`` / ``cwd`` set to E2b's defaults. A gateway that predates them (it answers 400
20
30
  naming them) gets the plain create, and the sandbox runs as root there (COMPAT.md). Restores from a snapshot keep the
@@ -26,4 +36,5 @@ async def create_as_vendor_user(solari: Any, **opts: Any) -> Any:
26
36
  except GatewayError as e:
27
37
  if not _refuses_user_fields(e):
28
38
  raise
39
+ _warn_root()
29
40
  return await solari.create(**opts)
@@ -1,6 +1,6 @@
1
1
  """``e2b_code_interpreter`` on Solari: ``Sandbox`` / ``AsyncSandbox`` with ``run_code`` and code contexts. Python runs in
2
2
  Solari's persistent kernel (rich results, structured charts). ``bash`` runs as a one-shot command. Other languages raise
3
- (the guest ships a Python kernel only). The default template, ``code-interpreter-v1``, is built into your org on first use."""
3
+ (the guest ships a Python kernel only). The default template, ``code-interpreter-v2``, is built into your org on first use."""
4
4
 
5
5
  from __future__ import annotations
6
6
 
@@ -25,7 +25,7 @@ from .exceptions import CommandExitException, InvalidArgumentException, SandboxE
25
25
 
26
26
  log = logging.getLogger("solari_e2b")
27
27
 
28
- CODE_INTERPRETER_TEMPLATE = "code-interpreter-v1"
28
+ CODE_INTERPRETER_TEMPLATE = "code-interpreter-v2"
29
29
 
30
30
  #: The data-analysis stack of E2B's default code-interpreter image, minus the very large audio/NLP/vision wheels.
31
31
  CODE_INTERPRETER_PACKAGES = [
@@ -305,7 +305,7 @@ _building: Dict[Any, "asyncio.Future[str]"] = {}
305
305
 
306
306
 
307
307
  async def build_code_interpreter_template(on_log: Optional[Callable[[str], None]] = None, **opts: Any) -> str:
308
- """Build ``code-interpreter-v1`` into your org (about 80 seconds, once). ``Sandbox.create()`` calls this when it is missing."""
308
+ """Build ``code-interpreter-v2`` into your org (about 80 seconds, once). ``Sandbox.create()`` calls this when it is missing."""
309
309
  conn = resolve_conn(**split_opts(opts)[0])
310
310
  key = (conn.api_key, conn.base_url)
311
311
  fut = _building.get(key)