anyenv 1.2.1__tar.gz → 1.2.2__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 (55) hide show
  1. {anyenv-1.2.1 → anyenv-1.2.2}/PKG-INFO +40 -15
  2. {anyenv-1.2.1 → anyenv-1.2.2}/README.md +36 -13
  3. {anyenv-1.2.1 → anyenv-1.2.2}/pyproject.toml +7 -2
  4. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/code_execution/__init__.py +28 -1
  5. anyenv-1.2.2/src/anyenv/code_execution/base.py +99 -0
  6. anyenv-1.2.2/src/anyenv/code_execution/beam_provider.py +376 -0
  7. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/code_execution/daytona_provider.py +71 -3
  8. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/code_execution/docker_provider.py +102 -27
  9. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/code_execution/e2b_provider.py +91 -3
  10. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/code_execution/local_provider.py +106 -4
  11. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/code_execution/mcp_python_provider.py +27 -0
  12. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/code_execution/subprocess_provider.py +102 -3
  13. anyenv-1.2.1/src/anyenv/code_execution/base.py +0 -50
  14. {anyenv-1.2.1 → anyenv-1.2.2}/LICENSE +0 -0
  15. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/__init__.py +0 -0
  16. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/anypath.py +0 -0
  17. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/async_run.py +0 -0
  18. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/calling/__init__.py +0 -0
  19. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/calling/async_executor.py +0 -0
  20. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/calling/threadgroup.py +0 -0
  21. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/code_execution/models.py +0 -0
  22. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/__init__.py +0 -0
  23. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/aiohttp_backend/__init__.py +0 -0
  24. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/aiohttp_backend/backend.py +0 -0
  25. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/base.py +0 -0
  26. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/exceptions.py +0 -0
  27. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/functional.py +0 -0
  28. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/http_types.py +0 -0
  29. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/httpx_backend/__init__.py +0 -0
  30. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/httpx_backend/backend.py +0 -0
  31. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/httpx_backend/js_transport.py +0 -0
  32. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/httpx_backend/serializer.py +0 -0
  33. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/pyodide_backend/__init__.py +0 -0
  34. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/download/pyodide_backend/backend.py +0 -0
  35. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/__init__.py +0 -0
  36. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/base.py +0 -0
  37. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/msgspec_provider/__init__.py +0 -0
  38. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/msgspec_provider/provider.py +0 -0
  39. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/orjson_provider/__init__.py +0 -0
  40. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/orjson_provider/provider.py +0 -0
  41. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/pydantic_provider/__init__.py +0 -0
  42. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/pydantic_provider/provider.py +0 -0
  43. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/stdlib_provider/__init__.py +0 -0
  44. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/stdlib_provider/provider.py +0 -0
  45. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/json_tools/utils.py +0 -0
  46. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/log.py +0 -0
  47. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/package_install/__init__.py +0 -0
  48. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/package_install/base.py +0 -0
  49. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/package_install/functional.py +0 -0
  50. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/package_install/micropip_install.py +0 -0
  51. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/package_install/pip_install.py +0 -0
  52. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/parse_time.py +0 -0
  53. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/py.typed +0 -0
  54. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/testing.py +0 -0
  55. {anyenv-1.2.1 → anyenv-1.2.2}/src/anyenv/validate.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anyenv
3
- Version: 1.2.1
3
+ Version: 1.2.2
4
4
  Summary: Compatibility layer for some basic operations to allow painless operation in PyOdide and Python pre-releases
5
5
  Keywords:
6
6
  Author: Philipp Temminghoff
@@ -24,7 +24,8 @@ Requires-Dist: anyio>=4.8.0
24
24
  Requires-Dist: appdirs>=1.4.4
25
25
  Requires-Dist: aiohttp ; extra == 'aiohttp'
26
26
  Requires-Dist: aiohttp-client-cache ; extra == 'aiohttp'
27
- Requires-Dist: daytona ; extra == 'daytona'
27
+ Requires-Dist: beam-client>=0.2.187 ; extra == 'beam'
28
+ Requires-Dist: daytona ; python_full_version < '3.14' and extra == 'daytona'
28
29
  Requires-Dist: testcontainers ; extra == 'docker'
29
30
  Requires-Dist: e2b-code-interpreter ; extra == 'e2b'
30
31
  Requires-Dist: httpx ; extra == 'httpx'
@@ -39,6 +40,7 @@ Project-URL: Documentation, https://phil65.github.io/anyenv/
39
40
  Project-URL: Issues, https://github.com/phil65/anyenv/issues
40
41
  Project-URL: Source, https://github.com/phil65/anyenv
41
42
  Provides-Extra: aiohttp
43
+ Provides-Extra: beam
42
44
  Provides-Extra: daytona
43
45
  Provides-Extra: docker
44
46
  Provides-Extra: e2b
@@ -90,7 +92,7 @@ from anyenv.code_execution import get_environment
90
92
  # Local execution (same process)
91
93
  env = get_environment("local")
92
94
 
93
- # Subprocess execution (separate Python process)
95
+ # Subprocess execution (separate Python process)
94
96
  env = get_environment("subprocess")
95
97
 
96
98
  # Docker execution (containerized)
@@ -124,7 +126,7 @@ Executes code in a separate Python process for basic isolation.
124
126
 
125
127
  ```python
126
128
  env = get_environment(
127
- "subprocess",
129
+ "subprocess",
128
130
  executable="python3",
129
131
  timeout=60.0,
130
132
  language="python"
@@ -133,7 +135,7 @@ env = get_environment(
133
135
 
134
136
  **Parameters:**
135
137
  - `executable` (str): Python executable to use (default: "python")
136
- - `timeout` (float): Execution timeout in seconds (default: 30.0)
138
+ - `timeout` (float): Execution timeout in seconds (default: 30.0)
137
139
  - `language` (Language): Programming language (default: "python")
138
140
 
139
141
  **Use cases:** Isolated execution, testing with different Python versions
@@ -181,7 +183,7 @@ env = get_environment(
181
183
 
182
184
  **Use cases:** Remote development, cloud-based CI/CD, collaborative coding
183
185
 
184
- ### E2B Provider
186
+ ### E2B Provider
185
187
  Executes code in E2B sandboxes for secure, ephemeral execution environments.
186
188
 
187
189
  ```python
@@ -202,6 +204,29 @@ env = get_environment(
202
204
 
203
205
  **Use cases:** Secure code execution, AI code generation, online code runners
204
206
 
207
+ ### Beam Provider
208
+ Executes code in Beam cloud sandboxes for scalable, serverless execution environments.
209
+
210
+ ```python
211
+ env = get_environment(
212
+ "beam",
213
+ cpu=1.0,
214
+ memory=128,
215
+ keep_warm_seconds=600,
216
+ timeout=300.0,
217
+ language="python"
218
+ )
219
+ ```
220
+
221
+ **Parameters:**
222
+ - `cpu` (float | str): CPU cores allocated to the container (default: 1.0)
223
+ - `memory` (int | str): Memory allocated to the container in MiB (default: 128)
224
+ - `keep_warm_seconds` (int): Seconds to keep sandbox alive, -1 for no timeout (default: 600)
225
+ - `timeout` (float): Execution timeout in seconds (default: 300.0)
226
+ - `language` (Language): Programming language (default: "python")
227
+
228
+ **Use cases:** Serverless execution, auto-scaling workloads, GPU-accelerated computing
229
+
205
230
  ### MCP Provider
206
231
  Executes Python code with Model Context Protocol support for AI integrations.
207
232
 
@@ -234,7 +259,7 @@ async def main():
234
259
  """
235
260
  ```
236
261
 
237
- ### 2. Result Variable Pattern
262
+ ### 2. Result Variable Pattern
238
263
  ```python
239
264
  code = """
240
265
  import math
@@ -265,7 +290,7 @@ Some providers support multiple programming languages:
265
290
  # JavaScript execution
266
291
  env = get_environment("subprocess", language="javascript", executable="node")
267
292
 
268
- # TypeScript execution
293
+ # TypeScript execution
269
294
  env = get_environment("docker", language="typescript", image="node:18")
270
295
  ```
271
296
 
@@ -294,7 +319,7 @@ env = get_environment(
294
319
 
295
320
  # Subprocess with specific Python version
296
321
  env = get_environment(
297
- "subprocess",
322
+ "subprocess",
298
323
  executable="/usr/bin/python3.11",
299
324
  timeout=120.0
300
325
  )
@@ -331,7 +356,7 @@ async with env:
331
356
  print(f"✓ {line}")
332
357
  ```
333
358
 
334
- **Supported providers:** `subprocess`, `docker`
359
+ **Supported providers:** `subprocess`, `docker`, `local`, `beam`
335
360
  **Use cases:** Progress monitoring, real-time feedback, large output processing
336
361
 
337
362
  ## HTTP Downloads
@@ -403,7 +428,7 @@ data = load_json('{"key": "value"}') # From string
403
428
  data = load_json(Path("config.json")) # From file
404
429
  data = load_json(b'{"key": "value"}') # From bytes
405
430
 
406
- # Dump JSON to various targets
431
+ # Dump JSON to various targets
407
432
  json_str = dump_json(data) # To string
408
433
  dump_json(data, Path("output.json")) # To file
409
434
  json_bytes = dump_json(data, return_bytes=True) # To bytes
@@ -456,7 +481,7 @@ result = await run_sync_in_thread(sync_function, arg1, arg2)
456
481
  # Enhanced gather with better error handling
457
482
  results = await gather(
458
483
  async_func1(),
459
- async_func2(),
484
+ async_func2(),
460
485
  async_func3(),
461
486
  return_exceptions=True
462
487
  )
@@ -481,7 +506,7 @@ async with ThreadGroup() as group:
481
506
  # Add functions to run concurrently
482
507
  group.spawn(some_function, arg1, arg2)
483
508
  group.spawn(another_function, arg3)
484
-
509
+
485
510
  # Wait for all to complete
486
511
  results = await group.gather()
487
512
 
@@ -490,7 +515,7 @@ spawner = function_spawner(my_function, max_workers=10)
490
515
  results = await spawner([arg1, arg2, arg3, arg4])
491
516
 
492
517
  # Method spawner for object methods
493
- obj_spawner = method_spawner(my_object.method, max_workers=5)
518
+ obj_spawner = method_spawner(my_object.method, max_workers=5)
494
519
  results = await obj_spawner([data1, data2, data3])
495
520
  ```
496
521
 
@@ -525,7 +550,7 @@ response = await backend.get("https://example.com")
525
550
  All functionality automatically adapts to the execution environment:
526
551
 
527
552
  - **PyOdide**: Uses browser-compatible implementations
528
- - **Standard Python**: Uses optimal libraries (httpx, etc.)
553
+ - **Standard Python**: Uses optimal libraries (httpx, etc.)
529
554
  - **Limited environments**: Falls back to stdlib implementations
530
555
  - **Async contexts**: Provides async implementations
531
556
  - **Sync contexts**: Provides synchronous alternatives
@@ -41,7 +41,7 @@ from anyenv.code_execution import get_environment
41
41
  # Local execution (same process)
42
42
  env = get_environment("local")
43
43
 
44
- # Subprocess execution (separate Python process)
44
+ # Subprocess execution (separate Python process)
45
45
  env = get_environment("subprocess")
46
46
 
47
47
  # Docker execution (containerized)
@@ -75,7 +75,7 @@ Executes code in a separate Python process for basic isolation.
75
75
 
76
76
  ```python
77
77
  env = get_environment(
78
- "subprocess",
78
+ "subprocess",
79
79
  executable="python3",
80
80
  timeout=60.0,
81
81
  language="python"
@@ -84,7 +84,7 @@ env = get_environment(
84
84
 
85
85
  **Parameters:**
86
86
  - `executable` (str): Python executable to use (default: "python")
87
- - `timeout` (float): Execution timeout in seconds (default: 30.0)
87
+ - `timeout` (float): Execution timeout in seconds (default: 30.0)
88
88
  - `language` (Language): Programming language (default: "python")
89
89
 
90
90
  **Use cases:** Isolated execution, testing with different Python versions
@@ -132,7 +132,7 @@ env = get_environment(
132
132
 
133
133
  **Use cases:** Remote development, cloud-based CI/CD, collaborative coding
134
134
 
135
- ### E2B Provider
135
+ ### E2B Provider
136
136
  Executes code in E2B sandboxes for secure, ephemeral execution environments.
137
137
 
138
138
  ```python
@@ -153,6 +153,29 @@ env = get_environment(
153
153
 
154
154
  **Use cases:** Secure code execution, AI code generation, online code runners
155
155
 
156
+ ### Beam Provider
157
+ Executes code in Beam cloud sandboxes for scalable, serverless execution environments.
158
+
159
+ ```python
160
+ env = get_environment(
161
+ "beam",
162
+ cpu=1.0,
163
+ memory=128,
164
+ keep_warm_seconds=600,
165
+ timeout=300.0,
166
+ language="python"
167
+ )
168
+ ```
169
+
170
+ **Parameters:**
171
+ - `cpu` (float | str): CPU cores allocated to the container (default: 1.0)
172
+ - `memory` (int | str): Memory allocated to the container in MiB (default: 128)
173
+ - `keep_warm_seconds` (int): Seconds to keep sandbox alive, -1 for no timeout (default: 600)
174
+ - `timeout` (float): Execution timeout in seconds (default: 300.0)
175
+ - `language` (Language): Programming language (default: "python")
176
+
177
+ **Use cases:** Serverless execution, auto-scaling workloads, GPU-accelerated computing
178
+
156
179
  ### MCP Provider
157
180
  Executes Python code with Model Context Protocol support for AI integrations.
158
181
 
@@ -185,7 +208,7 @@ async def main():
185
208
  """
186
209
  ```
187
210
 
188
- ### 2. Result Variable Pattern
211
+ ### 2. Result Variable Pattern
189
212
  ```python
190
213
  code = """
191
214
  import math
@@ -216,7 +239,7 @@ Some providers support multiple programming languages:
216
239
  # JavaScript execution
217
240
  env = get_environment("subprocess", language="javascript", executable="node")
218
241
 
219
- # TypeScript execution
242
+ # TypeScript execution
220
243
  env = get_environment("docker", language="typescript", image="node:18")
221
244
  ```
222
245
 
@@ -245,7 +268,7 @@ env = get_environment(
245
268
 
246
269
  # Subprocess with specific Python version
247
270
  env = get_environment(
248
- "subprocess",
271
+ "subprocess",
249
272
  executable="/usr/bin/python3.11",
250
273
  timeout=120.0
251
274
  )
@@ -282,7 +305,7 @@ async with env:
282
305
  print(f"✓ {line}")
283
306
  ```
284
307
 
285
- **Supported providers:** `subprocess`, `docker`
308
+ **Supported providers:** `subprocess`, `docker`, `local`, `beam`
286
309
  **Use cases:** Progress monitoring, real-time feedback, large output processing
287
310
 
288
311
  ## HTTP Downloads
@@ -354,7 +377,7 @@ data = load_json('{"key": "value"}') # From string
354
377
  data = load_json(Path("config.json")) # From file
355
378
  data = load_json(b'{"key": "value"}') # From bytes
356
379
 
357
- # Dump JSON to various targets
380
+ # Dump JSON to various targets
358
381
  json_str = dump_json(data) # To string
359
382
  dump_json(data, Path("output.json")) # To file
360
383
  json_bytes = dump_json(data, return_bytes=True) # To bytes
@@ -407,7 +430,7 @@ result = await run_sync_in_thread(sync_function, arg1, arg2)
407
430
  # Enhanced gather with better error handling
408
431
  results = await gather(
409
432
  async_func1(),
410
- async_func2(),
433
+ async_func2(),
411
434
  async_func3(),
412
435
  return_exceptions=True
413
436
  )
@@ -432,7 +455,7 @@ async with ThreadGroup() as group:
432
455
  # Add functions to run concurrently
433
456
  group.spawn(some_function, arg1, arg2)
434
457
  group.spawn(another_function, arg3)
435
-
458
+
436
459
  # Wait for all to complete
437
460
  results = await group.gather()
438
461
 
@@ -441,7 +464,7 @@ spawner = function_spawner(my_function, max_workers=10)
441
464
  results = await spawner([arg1, arg2, arg3, arg4])
442
465
 
443
466
  # Method spawner for object methods
444
- obj_spawner = method_spawner(my_object.method, max_workers=5)
467
+ obj_spawner = method_spawner(my_object.method, max_workers=5)
445
468
  results = await obj_spawner([data1, data2, data3])
446
469
  ```
447
470
 
@@ -476,7 +499,7 @@ response = await backend.get("https://example.com")
476
499
  All functionality automatically adapts to the execution environment:
477
500
 
478
501
  - **PyOdide**: Uses browser-compatible implementations
479
- - **Standard Python**: Uses optimal libraries (httpx, etc.)
502
+ - **Standard Python**: Uses optimal libraries (httpx, etc.)
480
503
  - **Limited environments**: Falls back to stdlib implementations
481
504
  - **Async contexts**: Provides async implementations
482
505
  - **Sync contexts**: Provides synchronous alternatives
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "anyenv"
3
- version = "1.2.1"
3
+ version = "1.2.2"
4
4
  description = "Compatibility layer for some basic operations to allow painless operation in PyOdide and Python pre-releases"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -40,7 +40,8 @@ Source = "https://github.com/phil65/anyenv"
40
40
 
41
41
  [project.optional-dependencies]
42
42
  aiohttp = ["aiohttp", "aiohttp-client-cache"]
43
- daytona = ["daytona"]
43
+ beam = ["beam-client>=0.2.187"]
44
+ daytona = ["daytona; python_version < '3.14'"]
44
45
  docker = ["testcontainers"]
45
46
  e2b = ["e2b-code-interpreter"]
46
47
  httpx = ["httpx", "hishel"]
@@ -122,9 +123,13 @@ reportSelfClsParameterName = false
122
123
  reportPrivateImportUsage = false
123
124
 
124
125
  [tool.pytest.ini_options]
126
+ addopts = "-m 'not integration'"
125
127
  log_cli = true
126
128
  log_date_format = "%Y-%m-%d %H:%M:%S"
127
129
  log_format = "%(asctime)s %(levelname)s %(message)s"
130
+ markers = [
131
+ "integration: marks tests as integration tests (deselected by default)",
132
+ ]
128
133
  testpaths = "tests/"
129
134
  asyncio_mode = "auto"
130
135
 
@@ -6,6 +6,7 @@ from typing import Literal, overload, TYPE_CHECKING
6
6
 
7
7
  from anyenv.code_execution.base import ExecutionEnvironment
8
8
 
9
+ from anyenv.code_execution.beam_provider import BeamExecutionEnvironment
9
10
  from anyenv.code_execution.daytona_provider import DaytonaExecutionEnvironment
10
11
  from anyenv.code_execution.docker_provider import DockerExecutionEnvironment
11
12
  from anyenv.code_execution.local_provider import LocalExecutionEnvironment
@@ -22,6 +23,8 @@ from anyenv.code_execution.models import (
22
23
  from anyenv.code_execution.subprocess_provider import SubprocessExecutionEnvironment
23
24
 
24
25
  if TYPE_CHECKING:
26
+ from contextlib import AbstractAsyncContextManager
27
+
25
28
  from anyenv.code_execution.models import Language
26
29
 
27
30
 
@@ -29,6 +32,7 @@ if TYPE_CHECKING:
29
32
  def get_environment(
30
33
  provider: Literal["local"],
31
34
  *,
35
+ lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
32
36
  timeout: float = 30.0,
33
37
  ) -> LocalExecutionEnvironment: ...
34
38
 
@@ -37,6 +41,7 @@ def get_environment(
37
41
  def get_environment(
38
42
  provider: Literal["subprocess"],
39
43
  *,
44
+ lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
40
45
  executable: str = "python",
41
46
  timeout: float = 30.0,
42
47
  language: Language = "python",
@@ -58,6 +63,7 @@ def get_environment(
58
63
  def get_environment(
59
64
  provider: Literal["mcp"],
60
65
  *,
66
+ lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
61
67
  dependencies: list[str] | None = None,
62
68
  allow_networking: bool = True,
63
69
  timeout: float = 30.0,
@@ -68,6 +74,7 @@ def get_environment(
68
74
  def get_environment(
69
75
  provider: Literal["daytona"],
70
76
  *,
77
+ lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
71
78
  api_url: str | None = None,
72
79
  api_key: str | None = None,
73
80
  target: str | None = None,
@@ -81,6 +88,7 @@ def get_environment(
81
88
  def get_environment(
82
89
  provider: Literal["e2b"],
83
90
  *,
91
+ lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
84
92
  template: str | None = None,
85
93
  timeout: float = 300.0,
86
94
  keep_alive: bool = False,
@@ -88,8 +96,21 @@ def get_environment(
88
96
  ) -> E2bExecutionEnvironment: ...
89
97
 
90
98
 
99
+ @overload
91
100
  def get_environment(
92
- provider: Literal["local", "subprocess", "docker", "mcp", "daytona", "e2b"],
101
+ provider: Literal["beam"],
102
+ *,
103
+ lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
104
+ cpu: float | str = 1.0,
105
+ memory: int | str = 128,
106
+ keep_warm_seconds: int = 600,
107
+ timeout: float = 300.0,
108
+ language: Language = "python",
109
+ ) -> BeamExecutionEnvironment: ...
110
+
111
+
112
+ def get_environment( # noqa: PLR0911
113
+ provider: Literal["local", "subprocess", "docker", "mcp", "daytona", "e2b", "beam"],
93
114
  **kwargs,
94
115
  ) -> ExecutionEnvironment:
95
116
  """Get an execution environment based on provider name.
@@ -114,6 +135,9 @@ def get_environment(
114
135
 
115
136
  # E2B with template and language
116
137
  env = get_environment("e2b", template="python", timeout=600.0, language="javascript")
138
+
139
+ # Beam with custom resources
140
+ env = get_environment("beam", cpu=2.0, memory=512, timeout=600.0)
117
141
  ```
118
142
  """ # noqa: E501
119
143
  match provider:
@@ -129,12 +153,15 @@ def get_environment(
129
153
  return DaytonaExecutionEnvironment(**kwargs)
130
154
  case "e2b":
131
155
  return E2bExecutionEnvironment(**kwargs)
156
+ case "beam":
157
+ return BeamExecutionEnvironment(**kwargs)
132
158
  case _:
133
159
  error_msg = f"Unknown provider: {provider}"
134
160
  raise ValueError(error_msg)
135
161
 
136
162
 
137
163
  __all__ = [
164
+ "BeamExecutionEnvironment",
138
165
  "DaytonaExecutionEnvironment",
139
166
  "DockerExecutionEnvironment",
140
167
  "E2bExecutionEnvironment",
@@ -0,0 +1,99 @@
1
+ """Base execution environment interface."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from abc import ABC, abstractmethod
6
+ from typing import TYPE_CHECKING, Self
7
+
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import AsyncIterator
11
+ from contextlib import AbstractAsyncContextManager
12
+
13
+ from anyenv.code_execution.models import ExecutionResult, ServerInfo
14
+
15
+
16
+ class ExecutionEnvironment(ABC):
17
+ """Abstract base class for code execution environments."""
18
+
19
+ def __init__(
20
+ self,
21
+ lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
22
+ **kwargs,
23
+ ):
24
+ """Initialize execution environment with optional lifespan handler.
25
+
26
+ Args:
27
+ lifespan_handler: Optional async context manager for tool server
28
+ **kwargs: Additional keyword arguments for specific providers
29
+ """
30
+ self.lifespan_handler = lifespan_handler
31
+ self.server_info: ServerInfo | None = None
32
+
33
+ async def __aenter__(self) -> Self:
34
+ """Setup environment (start server, spawn process, etc.)."""
35
+ # Start tool server if provided
36
+ if self.lifespan_handler:
37
+ self.server_info = await self.lifespan_handler.__aenter__()
38
+ return self
39
+
40
+ async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
41
+ """Cleanup (stop server, kill process, etc.)."""
42
+ # Cleanup server if provided
43
+ if self.lifespan_handler:
44
+ await self.lifespan_handler.__aexit__(exc_type, exc_val, exc_tb)
45
+
46
+ @abstractmethod
47
+ async def execute(self, code: str) -> ExecutionResult:
48
+ """Execute code and return result with metadata."""
49
+ ...
50
+
51
+ async def execute_stream(self, code: str) -> AsyncIterator[str]:
52
+ """Execute code and stream output line by line (optional).
53
+
54
+ Not all execution environments support streaming.
55
+ Default implementation raises NotImplementedError.
56
+
57
+ Args:
58
+ code: Code to execute
59
+
60
+ Yields:
61
+ Lines of output as they are produced
62
+
63
+ Raises:
64
+ NotImplementedError: If streaming is not supported
65
+ """
66
+ msg = f"{self.__class__.__name__} does not support streaming"
67
+ raise NotImplementedError(msg)
68
+ yield
69
+
70
+ @abstractmethod
71
+ async def execute_command(self, command: str) -> ExecutionResult:
72
+ """Execute a terminal command and return result with metadata.
73
+
74
+ Args:
75
+ command: Terminal command to execute
76
+
77
+ Returns:
78
+ ExecutionResult with command output and metadata
79
+ """
80
+ ...
81
+
82
+ async def execute_command_stream(self, command: str) -> AsyncIterator[str]:
83
+ """Execute a terminal command and stream output line by line (optional).
84
+
85
+ Not all execution environments support streaming commands.
86
+ Default implementation raises NotImplementedError.
87
+
88
+ Args:
89
+ command: Terminal command to execute
90
+
91
+ Yields:
92
+ Lines of output as they are produced
93
+
94
+ Raises:
95
+ NotImplementedError: If command streaming is not supported
96
+ """
97
+ msg = f"{self.__class__.__name__} does not support command streaming"
98
+ raise NotImplementedError(msg)
99
+ yield