boxfab-code-interpreter 0.1.0a1__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.
@@ -0,0 +1,10 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 FOUNDRYLABS, INC.
4
+ Copyright (c) 2026 ContextFab, Inc.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.4
2
+ Name: boxfab-code-interpreter
3
+ Version: 0.1.0a1
4
+ Summary: BoxFab Code Interpreter: run AI-generated code in BoxFab sandboxes, Jupyter-style
5
+ Author: ContextFab, Inc.
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: boxfab>=0.1.0a3,<0.2
15
+ Requires-Dist: httpx>=0.20.0,<1.0.0
16
+ Requires-Dist: attrs>=21.3.0
17
+ Requires-Python: >=3.11
18
+ Project-URL: Repository, https://github.com/boxfab/python-sdk
19
+ Description-Content-Type: text/markdown
20
+
21
+ # BoxFab Code Interpreter (Python)
22
+
23
+ Run AI-generated code in isolated [BoxFab](https://boxfab.io) sandboxes, Jupyter-style:
24
+ Python, JavaScript, TypeScript, R, Java and Bash, with results such as text, tables and charts
25
+ returned as data.
26
+
27
+ ## Getting started
28
+
29
+ ### 1. Install the SDK
30
+
31
+ ```bash
32
+ pip install boxfab-code-interpreter
33
+ ```
34
+
35
+ ### 2. Get a BoxFab API key
36
+
37
+ Get a key from the [BoxFab dashboard](https://dashboard.boxfab.io) and set it as `BOXFAB_API_KEY`.
38
+ The SDK reads only `BOXFAB_*` variables.
39
+
40
+ ### 3. Execute code with code interpreter inside Sandbox
41
+
42
+ ```py
43
+ from boxfab_code_interpreter import Sandbox
44
+
45
+ with Sandbox.create() as sandbox:
46
+ sandbox.run_code("x = 1")
47
+ execution = sandbox.run_code("x+=1; x")
48
+ print(execution.text) # outputs 2
49
+ ```
50
+
51
+ ### 4. Bind the configuration to a client
52
+
53
+ The top-level `Sandbox` and `AsyncSandbox` exports read their configuration from the environment variables. To use an explicit configuration — e.g. several API keys or domains in one process — create a `BoxFab` client and use the resource classes it exposes:
54
+
55
+ ```py
56
+ from boxfab_code_interpreter import BoxFab
57
+
58
+ client = BoxFab(api_key="e2b_***", domain="boxfab.io")
59
+
60
+ with client.Sandbox.create() as sandbox:
61
+ execution = sandbox.run_code("x = 1; x += 1; x")
62
+
63
+ # The async variant is exposed as well.
64
+ async_sandbox = await client.AsyncSandbox.create()
65
+
66
+ # The core resources are bound to the client's configuration as well.
67
+ volume = client.Volume.create("my-volume")
68
+ exists = client.Template.exists("my-template")
69
+ secret = client.Secret.create("openai-api-key", "sk-***")
70
+
71
+ # The classes can be assigned and used like the top-level ones.
72
+ Sandbox = client.Sandbox
73
+ paginator = Sandbox.list()
74
+ ```
75
+
76
+ Per-call params still take precedence over the client's params, and clients are isolated from each other and from the env-configured top-level exports.
77
+
78
+ ## Under the hood
79
+
80
+ Sandboxes are created from the `code-interpreter-v1` template, which BoxFab provides to every team:
81
+ a Jupyter server with common data-science packages. BoxFab sandboxes are
82
+ [Firecracker](https://firecracker-microvm.github.io/) microVMs, run on the open-source
83
+ [E2B](https://github.com/e2b-dev/infra) sandbox infrastructure. This package is derived from the
84
+ open-source E2B Code Interpreter SDK;
85
+ [UPSTREAM.md](https://github.com/boxfab/python-sdk/blob/main/UPSTREAM.md) lists every change.
86
+
87
+ **Using the E2B Code Interpreter SDKs.** BoxFab serves the same API and provides the
88
+ `code-interpreter-v1` template, so the E2B Code Interpreter SDKs work with it as well. Set both
89
+ variables, the domain first:
90
+
91
+ ```bash
92
+ export E2B_DOMAIN=boxfab.io
93
+ export E2B_API_KEY="<your BoxFab API key>"
94
+ ```
95
+
96
+ Without `E2B_DOMAIN`, the E2B SDKs send requests, including the key, to E2B's own service.
97
+
98
+ Tested against BoxFab with `e2b-code-interpreter` 2.11.6 (Python) and `@e2b/code-interpreter` 2.9.0
99
+ (JavaScript).
100
+
101
+ ## License
102
+
103
+ MIT, as the E2B Code Interpreter SDK it is derived from; see [LICENSE](LICENSE).
104
+
105
+ BoxFab is a product of ContextFab, Inc.
@@ -0,0 +1,85 @@
1
+ # BoxFab Code Interpreter (Python)
2
+
3
+ Run AI-generated code in isolated [BoxFab](https://boxfab.io) sandboxes, Jupyter-style:
4
+ Python, JavaScript, TypeScript, R, Java and Bash, with results such as text, tables and charts
5
+ returned as data.
6
+
7
+ ## Getting started
8
+
9
+ ### 1. Install the SDK
10
+
11
+ ```bash
12
+ pip install boxfab-code-interpreter
13
+ ```
14
+
15
+ ### 2. Get a BoxFab API key
16
+
17
+ Get a key from the [BoxFab dashboard](https://dashboard.boxfab.io) and set it as `BOXFAB_API_KEY`.
18
+ The SDK reads only `BOXFAB_*` variables.
19
+
20
+ ### 3. Execute code with code interpreter inside Sandbox
21
+
22
+ ```py
23
+ from boxfab_code_interpreter import Sandbox
24
+
25
+ with Sandbox.create() as sandbox:
26
+ sandbox.run_code("x = 1")
27
+ execution = sandbox.run_code("x+=1; x")
28
+ print(execution.text) # outputs 2
29
+ ```
30
+
31
+ ### 4. Bind the configuration to a client
32
+
33
+ The top-level `Sandbox` and `AsyncSandbox` exports read their configuration from the environment variables. To use an explicit configuration — e.g. several API keys or domains in one process — create a `BoxFab` client and use the resource classes it exposes:
34
+
35
+ ```py
36
+ from boxfab_code_interpreter import BoxFab
37
+
38
+ client = BoxFab(api_key="e2b_***", domain="boxfab.io")
39
+
40
+ with client.Sandbox.create() as sandbox:
41
+ execution = sandbox.run_code("x = 1; x += 1; x")
42
+
43
+ # The async variant is exposed as well.
44
+ async_sandbox = await client.AsyncSandbox.create()
45
+
46
+ # The core resources are bound to the client's configuration as well.
47
+ volume = client.Volume.create("my-volume")
48
+ exists = client.Template.exists("my-template")
49
+ secret = client.Secret.create("openai-api-key", "sk-***")
50
+
51
+ # The classes can be assigned and used like the top-level ones.
52
+ Sandbox = client.Sandbox
53
+ paginator = Sandbox.list()
54
+ ```
55
+
56
+ Per-call params still take precedence over the client's params, and clients are isolated from each other and from the env-configured top-level exports.
57
+
58
+ ## Under the hood
59
+
60
+ Sandboxes are created from the `code-interpreter-v1` template, which BoxFab provides to every team:
61
+ a Jupyter server with common data-science packages. BoxFab sandboxes are
62
+ [Firecracker](https://firecracker-microvm.github.io/) microVMs, run on the open-source
63
+ [E2B](https://github.com/e2b-dev/infra) sandbox infrastructure. This package is derived from the
64
+ open-source E2B Code Interpreter SDK;
65
+ [UPSTREAM.md](https://github.com/boxfab/python-sdk/blob/main/UPSTREAM.md) lists every change.
66
+
67
+ **Using the E2B Code Interpreter SDKs.** BoxFab serves the same API and provides the
68
+ `code-interpreter-v1` template, so the E2B Code Interpreter SDKs work with it as well. Set both
69
+ variables, the domain first:
70
+
71
+ ```bash
72
+ export E2B_DOMAIN=boxfab.io
73
+ export E2B_API_KEY="<your BoxFab API key>"
74
+ ```
75
+
76
+ Without `E2B_DOMAIN`, the E2B SDKs send requests, including the key, to E2B's own service.
77
+
78
+ Tested against BoxFab with `e2b-code-interpreter` 2.11.6 (Python) and `@e2b/code-interpreter` 2.9.0
79
+ (JavaScript).
80
+
81
+ ## License
82
+
83
+ MIT, as the E2B Code Interpreter SDK it is derived from; see [LICENSE](LICENSE).
84
+
85
+ BoxFab is a product of ContextFab, Inc.
@@ -0,0 +1,15 @@
1
+ from boxfab import *
2
+ from .client import BoxFab, BoxFabClientParams, E2B, E2BClientParams
3
+ from .code_interpreter_sync import Sandbox
4
+ from .code_interpreter_async import AsyncSandbox
5
+ from .models import (
6
+ Context,
7
+ Execution,
8
+ ExecutionError,
9
+ Result,
10
+ MIMEType,
11
+ Logs,
12
+ OutputHandler,
13
+ OutputMessage,
14
+ RunCodeLanguage,
15
+ )
@@ -0,0 +1,232 @@
1
+ import enum
2
+ from typing import Any, List, Tuple, Optional, Union
3
+
4
+
5
+ class ChartType(str, enum.Enum):
6
+ """
7
+ Chart types
8
+ """
9
+
10
+ LINE = "line"
11
+ SCATTER = "scatter"
12
+ BAR = "bar"
13
+ PIE = "pie"
14
+ BOX_AND_WHISKER = "box_and_whisker"
15
+ SUPERCHART = "superchart"
16
+ UNKNOWN = "unknown"
17
+
18
+
19
+ class ScaleType(str, enum.Enum):
20
+ """
21
+ Ax scale types
22
+ """
23
+
24
+ LINEAR = "linear"
25
+ DATETIME = "datetime"
26
+ CATEGORICAL = "categorical"
27
+ LOG = "log"
28
+ SYMLOG = "symlog"
29
+ LOGIT = "logit"
30
+ FUNCTION = "function"
31
+ FUNCTIONLOG = "functionlog"
32
+ ASINH = "asinh"
33
+ UNKNOWN = "unknown"
34
+
35
+
36
+ class Chart:
37
+ """
38
+ Extracted data from a chart. It's useful for building an interactive charts or custom visualizations.
39
+ """
40
+
41
+ type: ChartType
42
+ title: str
43
+
44
+ elements: List[Any]
45
+
46
+ def __init__(self, **kwargs):
47
+ self._raw_data = kwargs
48
+ self.type = ChartType(kwargs["type"] or ChartType.UNKNOWN)
49
+ self.title = kwargs["title"]
50
+ self.elements = kwargs["elements"]
51
+
52
+ def to_dict(self) -> dict:
53
+ return self._raw_data
54
+
55
+
56
+ class Chart2D(Chart):
57
+ x_label: Optional[str]
58
+ y_label: Optional[str]
59
+ x_unit: Optional[str]
60
+ y_unit: Optional[str]
61
+
62
+ def __init__(self, **kwargs):
63
+ super().__init__(**kwargs)
64
+ self.x_label = kwargs["x_label"]
65
+ self.y_label = kwargs["y_label"]
66
+ self.x_unit = kwargs["x_unit"]
67
+ self.y_unit = kwargs["y_unit"]
68
+
69
+
70
+ class PointData:
71
+ label: str
72
+ points: List[Tuple[Union[str, float], Union[str, float]]]
73
+
74
+ def __init__(self, **kwargs):
75
+ self.label = kwargs["label"]
76
+ self.points = [(x, y) for x, y in kwargs["points"]]
77
+
78
+
79
+ class PointChart(Chart2D):
80
+ x_ticks: List[Union[str, float]]
81
+ x_tick_labels: List[str]
82
+ x_scale: ScaleType
83
+
84
+ y_ticks: List[Union[str, float]]
85
+ y_tick_labels: List[str]
86
+ y_scale: ScaleType
87
+
88
+ elements: List[PointData]
89
+
90
+ def __init__(self, **kwargs):
91
+ super().__init__(**kwargs)
92
+ self.x_label = kwargs["x_label"]
93
+
94
+ try:
95
+ self.x_scale = ScaleType(kwargs.get("x_scale"))
96
+ except ValueError:
97
+ self.x_scale = ScaleType.UNKNOWN
98
+
99
+ self.x_ticks = kwargs["x_ticks"]
100
+ self.x_tick_labels = kwargs["x_tick_labels"]
101
+
102
+ self.y_label = kwargs["y_label"]
103
+
104
+ try:
105
+ self.y_scale = ScaleType(kwargs.get("y_scale"))
106
+ except ValueError:
107
+ self.y_scale = ScaleType.UNKNOWN
108
+
109
+ self.y_ticks = kwargs["y_ticks"]
110
+ self.y_tick_labels = kwargs["y_tick_labels"]
111
+
112
+ self.elements = [PointData(**d) for d in kwargs["elements"]]
113
+
114
+
115
+ class LineChart(PointChart):
116
+ type = ChartType.LINE
117
+
118
+
119
+ class ScatterChart(PointChart):
120
+ type = ChartType.SCATTER
121
+
122
+
123
+ class BarData:
124
+ label: str
125
+ group: str
126
+ value: str
127
+
128
+ def __init__(self, **kwargs):
129
+ self.label = kwargs["label"]
130
+ self.value = kwargs["value"]
131
+ self.group = kwargs["group"]
132
+
133
+
134
+ class BarChart(Chart2D):
135
+ type = ChartType.BAR
136
+
137
+ elements: List[BarData]
138
+
139
+ def __init__(self, **kwargs):
140
+ super().__init__(**kwargs)
141
+ self.elements = [BarData(**d) for d in kwargs["elements"]]
142
+
143
+
144
+ class PieData:
145
+ label: str
146
+ angle: float
147
+ radius: float
148
+
149
+ def __init__(self, **kwargs):
150
+ self.label = kwargs["label"]
151
+ self.angle = kwargs["angle"]
152
+ self.radius = kwargs["radius"]
153
+
154
+
155
+ class PieChart(Chart):
156
+ type = ChartType.PIE
157
+
158
+ elements: List[PieData]
159
+
160
+ def __init__(self, **kwargs):
161
+ super().__init__(**kwargs)
162
+ self.elements = [PieData(**d) for d in kwargs["elements"]]
163
+
164
+
165
+ class BoxAndWhiskerData:
166
+ label: str
167
+ min: float
168
+ first_quartile: float
169
+ median: float
170
+ third_quartile: float
171
+ max: float
172
+ outliers: List[float]
173
+
174
+ def __init__(self, **kwargs):
175
+ self.label = kwargs["label"]
176
+ self.min = kwargs["min"]
177
+ self.first_quartile = kwargs["first_quartile"]
178
+ self.median = kwargs["median"]
179
+ self.third_quartile = kwargs["third_quartile"]
180
+ self.max = kwargs["max"]
181
+ self.outliers = kwargs.get("outliers") or []
182
+
183
+
184
+ class BoxAndWhiskerChart(Chart2D):
185
+ type = ChartType.BOX_AND_WHISKER
186
+
187
+ elements: List[BoxAndWhiskerData]
188
+
189
+ def __init__(self, **kwargs):
190
+ super().__init__(**kwargs)
191
+ self.elements = [BoxAndWhiskerData(**d) for d in kwargs["elements"]]
192
+
193
+
194
+ class SuperChart(Chart):
195
+ type = ChartType.SUPERCHART
196
+
197
+ elements: List[Chart]
198
+
199
+ def __init__(self, **kwargs):
200
+ super().__init__(**kwargs)
201
+ self.elements = []
202
+ for raw_chart in kwargs["elements"]:
203
+ chart = _deserialize_chart(raw_chart)
204
+ if chart is not None:
205
+ self.elements.append(chart)
206
+
207
+
208
+ ChartTypes = Union[
209
+ Chart, LineChart, ScatterChart, BarChart, PieChart, BoxAndWhiskerChart, SuperChart
210
+ ]
211
+
212
+
213
+ def _deserialize_chart(data: Optional[dict]) -> Optional[ChartTypes]:
214
+ if not data:
215
+ return None
216
+
217
+ if data["type"] == ChartType.LINE:
218
+ chart = LineChart(**data)
219
+ elif data["type"] == ChartType.SCATTER:
220
+ chart = ScatterChart(**data)
221
+ elif data["type"] == ChartType.BAR:
222
+ chart = BarChart(**data)
223
+ elif data["type"] == ChartType.PIE:
224
+ chart = PieChart(**data)
225
+ elif data["type"] == ChartType.BOX_AND_WHISKER:
226
+ chart = BoxAndWhiskerChart(**data)
227
+ elif data["type"] == ChartType.SUPERCHART:
228
+ chart = SuperChart(**data)
229
+ else:
230
+ chart = Chart(**data)
231
+
232
+ return chart
@@ -0,0 +1,95 @@
1
+ from typing import Dict, Type, TypeVar, Unpack, cast
2
+
3
+ from boxfab import ApiParams, BoxFabClientParams, E2BClientParams
4
+ from boxfab import BoxFab as CoreBoxFab
5
+ from boxfab_code_interpreter.code_interpreter_async import AsyncSandbox
6
+ from boxfab_code_interpreter.code_interpreter_sync import Sandbox
7
+
8
+ T = TypeVar("T")
9
+
10
+ __all__ = ["BoxFab", "BoxFabClientParams", "E2B", "E2BClientParams"]
11
+
12
+
13
+ def _bind(cls: Type[T], api_params: ApiParams) -> Type[T]:
14
+ """Generate a subclass of ``cls`` carrying ``api_params`` as its bound params."""
15
+ return cast(
16
+ Type[T],
17
+ type(cls.__name__, (cls,), {"_bound_api_params": api_params}),
18
+ )
19
+
20
+
21
+ class BoxFab:
22
+ """
23
+ BoxFab client with an explicitly bound connection configuration.
24
+
25
+ The resource classes exposed by the client (`Sandbox`, `AsyncSandbox`,
26
+ `Volume`, `AsyncVolume`, `Template`, `AsyncTemplate`, `Secret`,
27
+ `AsyncSecret`) behave exactly like the top-level exports of the same name,
28
+ except the params passed to the client are used as the defaults instead of
29
+ the environment variables.
30
+ Per-call params still take precedence over the client's params.
31
+
32
+ Multiple clients are fully isolated from each other and from the top-level
33
+ env-configured exports.
34
+
35
+ Example:
36
+ ```python
37
+ from boxfab_code_interpreter import BoxFab
38
+
39
+ client = BoxFab(api_key="e2b_...", domain="boxfab.io")
40
+
41
+ sandbox = client.Sandbox.create()
42
+ execution = sandbox.run_code("x = 1; x += 1; x")
43
+ ```
44
+ """
45
+
46
+ def __init__(self, **opts: Unpack[BoxFabClientParams]):
47
+ """
48
+ Create a new client with the API params bound to it.
49
+
50
+ :param opts: API params used as the defaults for every call made
51
+ through this client's resource classes.
52
+ """
53
+ # Params are copied so later mutations of the caller's dicts cannot
54
+ # change the bound configuration.
55
+ api_params = cast(ApiParams, dict(cast(Dict[str, object], opts)))
56
+
57
+ headers = api_params.get("headers")
58
+ if headers is not None:
59
+ api_params["headers"] = dict(headers)
60
+
61
+ api_headers = api_params.get("api_headers")
62
+ if api_headers is not None:
63
+ api_params["api_headers"] = dict(api_headers)
64
+
65
+ self.Sandbox = _bind(Sandbox, api_params)
66
+ """Code Interpreter `Sandbox` class bound to this client's connection configuration."""
67
+
68
+ self.AsyncSandbox = _bind(AsyncSandbox, api_params)
69
+ """Code Interpreter `AsyncSandbox` class bound to this client's connection configuration."""
70
+
71
+ # The resources that are not specific to the Code Interpreter are bound
72
+ # by the core client.
73
+ core = CoreBoxFab(**api_params)
74
+
75
+ self.Volume = core.Volume
76
+ """`Volume` class bound to this client's connection configuration."""
77
+
78
+ self.AsyncVolume = core.AsyncVolume
79
+ """`AsyncVolume` class bound to this client's connection configuration."""
80
+
81
+ self.Template = core.Template
82
+ """`Template` class bound to this client's connection configuration."""
83
+
84
+ self.AsyncTemplate = core.AsyncTemplate
85
+ """`AsyncTemplate` class bound to this client's connection configuration."""
86
+
87
+ self.Secret = core.Secret
88
+ """`Secret` class bound to this client's connection configuration."""
89
+
90
+ self.AsyncSecret = core.AsyncSecret
91
+ """`AsyncSecret` class bound to this client's connection configuration."""
92
+
93
+
94
+ # Upstream name, kept so code written for the upstream package ports by changing only the import.
95
+ E2B = BoxFab