exxec 0.3.3__tar.gz → 0.3.6__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 (64) hide show
  1. {exxec-0.3.3 → exxec-0.3.6}/PKG-INFO +1 -2
  2. {exxec-0.3.3 → exxec-0.3.6}/pyproject.toml +2 -3
  3. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/daytona_provider/helpers.py +1 -1
  4. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/daytona_provider/process_manager.py +7 -4
  5. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/daytona_provider/provider.py +9 -5
  6. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/daytona_provider/pty_manager.py +32 -80
  7. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/docker_provider/provider.py +10 -6
  8. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/e2b_provider/provider.py +7 -3
  9. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/local_provider/provider.py +7 -3
  10. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/mock_provider/provider.py +6 -2
  11. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/modal_provider/provider.py +7 -3
  12. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/ssh_provider/provider.py +7 -3
  13. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/vercel_provider/process_manager.py +4 -4
  14. {exxec-0.3.3 → exxec-0.3.6}/LICENSE +0 -0
  15. {exxec-0.3.3 → exxec-0.3.6}/README.md +0 -0
  16. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/__init__.py +0 -0
  17. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/acp_provider/__init__.py +0 -0
  18. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/acp_provider/process_manager.py +0 -0
  19. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/acp_provider/provider.py +0 -0
  20. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/base.py +0 -0
  21. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/beam_provider/__init__.py +0 -0
  22. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/beam_provider/helpers.py +0 -0
  23. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/beam_provider/process_manager.py +0 -0
  24. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/beam_provider/provider.py +0 -0
  25. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/daytona_provider/__init__.py +0 -0
  26. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/docker_provider/__init__.py +0 -0
  27. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/docker_provider/pty_manager.py +0 -0
  28. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/e2b_provider/__init__.py +0 -0
  29. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/e2b_provider/process_manager.py +0 -0
  30. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/e2b_provider/pty_manager.py +0 -0
  31. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/events.py +0 -0
  32. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/local_provider/__init__.py +0 -0
  33. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/local_provider/pty_manager.py +0 -0
  34. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/local_provider/utils.py +0 -0
  35. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/log.py +0 -0
  36. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/microsandbox_provider/__init__.py +0 -0
  37. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/microsandbox_provider/provider.py +0 -0
  38. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/mock_provider/__init__.py +0 -0
  39. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/mock_provider/process_manager.py +0 -0
  40. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/mock_provider/pty_manager.py +0 -0
  41. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/modal_provider/__init__.py +0 -0
  42. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/modal_provider/pty_manager.py +0 -0
  43. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/models.py +0 -0
  44. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/parse_output.py +0 -0
  45. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/pep723.py +0 -0
  46. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/process_manager.py +0 -0
  47. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/pty_manager.py +0 -0
  48. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/py.typed +0 -0
  49. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/pyodide_provider/__init__.py +0 -0
  50. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/pyodide_provider/filesystem.py +0 -0
  51. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/pyodide_provider/provider.py +0 -0
  52. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/pyodide_provider/pyodide_server.ts +0 -0
  53. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/remote_callable.py +0 -0
  54. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/srt_provider/__init__.py +0 -0
  55. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/srt_provider/config.py +0 -0
  56. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/srt_provider/provider.py +0 -0
  57. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/ssh_provider/__init__.py +0 -0
  58. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/ssh_provider/pty_manager.py +0 -0
  59. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/vercel_provider/__init__.py +0 -0
  60. {exxec-0.3.3 → exxec-0.3.6}/src/exxec/vercel_provider/provider.py +0 -0
  61. {exxec-0.3.3 → exxec-0.3.6}/src/exxec_config/__init__.py +0 -0
  62. {exxec-0.3.3 → exxec-0.3.6}/src/exxec_config/configs.py +0 -0
  63. {exxec-0.3.3 → exxec-0.3.6}/src/exxec_config/py.typed +0 -0
  64. {exxec-0.3.3 → exxec-0.3.6}/src/exxec_config/srt_sandbox_config.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: exxec
3
- Version: 0.3.3
3
+ Version: 0.3.6
4
4
  Summary: Execution environments
5
5
  Keywords:
6
6
  Author: Philipp Temminghoff
@@ -29,7 +29,6 @@ Requires-Dist: upathtools>=1.9.0
29
29
  Requires-Dist: beam-client>=0.2.187 ; extra == 'beam'
30
30
  Requires-Dist: daytona ; python_full_version < '3.14' and extra == 'daytona'
31
31
  Requires-Dist: testcontainers ; extra == 'docker'
32
- Requires-Dist: morefs ; extra == 'docker'
33
32
  Requires-Dist: e2b-code-interpreter ; extra == 'e2b'
34
33
  Requires-Dist: fastmcp ; extra == 'mcp'
35
34
  Requires-Dist: mcp-run-python ; extra == 'mcp'
@@ -2,7 +2,7 @@
2
2
 
3
3
  [project]
4
4
  name = "exxec"
5
- version = "0.3.3"
5
+ version = "0.3.6"
6
6
  description = "Execution environments"
7
7
  readme = "README.md"
8
8
  requires-python = ">=3.13"
@@ -47,7 +47,7 @@ Source = "https://github.com/phil65/exxec"
47
47
  [project.optional-dependencies]
48
48
  beam = ["beam-client>=0.2.187"]
49
49
  daytona = ["daytona; python_version < '3.14'"]
50
- docker = ["testcontainers", "morefs"]
50
+ docker = ["testcontainers"]
51
51
  e2b = ["e2b-code-interpreter"]
52
52
  mcp = ["fastmcp", "mcp-run-python"]
53
53
  microsandbox = ["microsandbox"]
@@ -289,7 +289,6 @@ python-platform = "all"
289
289
 
290
290
  [tool.uv]
291
291
  default-groups = ["dev", "lint", "docs"]
292
-
293
292
  # Override to resolve beam-client (<14) vs daytona (>=15) websockets conflict
294
293
  override-dependencies = ["websockets>=15.0.0"]
295
294
 
@@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, assert_never
6
6
 
7
7
 
8
8
  if TYPE_CHECKING:
9
- from daytona.common.daytona import CodeLanguage # type: ignore[import-untyped]
9
+ from daytona.common.daytona import CodeLanguage
10
10
 
11
11
  from exxec.parse_output import Language
12
12
 
@@ -18,7 +18,7 @@ from exxec.log import get_logger
18
18
  if TYPE_CHECKING:
19
19
  from pathlib import Path
20
20
 
21
- from daytona._async.sandbox import AsyncSandbox # type: ignore[import-untyped]
21
+ from daytona._async.sandbox import AsyncSandbox
22
22
 
23
23
 
24
24
  logger = get_logger(__name__)
@@ -81,7 +81,7 @@ class DaytonaTerminalManager(ProcessManagerProtocol):
81
81
 
82
82
  try:
83
83
  await self.sandbox.process.create_session(session_id)
84
- from daytona.common.process import SessionExecuteRequest # type: ignore[import-untyped]
84
+ from daytona.common.process import SessionExecuteRequest
85
85
 
86
86
  request = SessionExecuteRequest(command=full_command, runAsync=True) # ty: ignore[unknown-argument]
87
87
  response = await self.sandbox.process.execute_session_command(session_id, request)
@@ -108,11 +108,14 @@ class DaytonaTerminalManager(ProcessManagerProtocol):
108
108
  return
109
109
  try:
110
110
 
111
- def on_logs(chunk: str) -> None:
111
+ def on_stdout(chunk: str) -> None:
112
+ terminal.add_output(chunk)
113
+
114
+ def on_stderr(chunk: str) -> None:
112
115
  terminal.add_output(chunk)
113
116
 
114
117
  await self.sandbox.process.get_session_command_logs_async(
115
- terminal.session_id, terminal.command_id, on_logs
118
+ terminal.session_id, terminal.command_id, on_stdout, on_stderr
116
119
  )
117
120
  command_info = await self.sandbox.process.get_session_command(
118
121
  terminal.session_id, terminal.command_id
@@ -18,7 +18,7 @@ if TYPE_CHECKING:
18
18
  from contextlib import AbstractAsyncContextManager
19
19
  from types import TracebackType
20
20
 
21
- from daytona._async.sandbox import AsyncSandbox # type: ignore[import-untyped]
21
+ from daytona._async.sandbox import AsyncSandbox
22
22
  from upathtools.filesystems import DaytonaFS
23
23
 
24
24
  from exxec.daytona_provider.pty_manager import DaytonaPtyManager
@@ -62,7 +62,7 @@ class DaytonaExecutionEnvironment(ExecutionEnvironment):
62
62
  inherit_env: If True, inherit environment variables from os.environ
63
63
  default_command_timeout: Default timeout for command execution in seconds
64
64
  """
65
- from daytona import AsyncDaytona, DaytonaConfig # type: ignore[import-untyped]
65
+ from daytona import AsyncDaytona, DaytonaConfig
66
66
 
67
67
  super().__init__(
68
68
  lifespan_handler=lifespan_handler,
@@ -81,6 +81,8 @@ class DaytonaExecutionEnvironment(ExecutionEnvironment):
81
81
  self._sandbox: AsyncSandbox | None = None
82
82
  # Daytona sandboxes run Linux containers
83
83
  self._os_type = "Linux"
84
+ # Cache PTY manager instance
85
+ self._pty_manager: DaytonaPtyManager | None = None
84
86
 
85
87
  @property
86
88
  def sandbox(self) -> AsyncSandbox:
@@ -91,7 +93,7 @@ class DaytonaExecutionEnvironment(ExecutionEnvironment):
91
93
  async def __aenter__(self) -> Self:
92
94
  """Setup Daytona client and create sandbox."""
93
95
  await super().__aenter__()
94
- from daytona.common.daytona import ( # type: ignore[import-untyped]
96
+ from daytona.common.daytona import (
95
97
  CreateSandboxFromImageParams,
96
98
  )
97
99
 
@@ -134,9 +136,11 @@ class DaytonaExecutionEnvironment(ExecutionEnvironment):
134
136
 
135
137
  def get_pty_manager(self) -> DaytonaPtyManager:
136
138
  """Return a DaytonaPtyManager for interactive terminal sessions."""
137
- from exxec.daytona_provider.pty_manager import DaytonaPtyManager
139
+ if self._pty_manager is None:
140
+ from exxec.daytona_provider.pty_manager import DaytonaPtyManager
138
141
 
139
- return DaytonaPtyManager(self.sandbox)
142
+ self._pty_manager = DaytonaPtyManager(self.sandbox)
143
+ return self._pty_manager
140
144
 
141
145
  async def execute(self, code: str) -> ExecutionResult:
142
146
  """Execute code in the Daytona sandbox."""
@@ -17,7 +17,8 @@ from exxec.pty_manager import BasePtyManager, PtyInfo, PtySize
17
17
  if TYPE_CHECKING:
18
18
  from collections.abc import AsyncIterator
19
19
 
20
- from daytona._async.sandbox import AsyncSandbox # type: ignore[import-untyped]
20
+ from daytona._async.sandbox import AsyncSandbox
21
+ from daytona.handle.async_pty_handle import AsyncPtyHandle
21
22
 
22
23
 
23
24
  @dataclass
@@ -25,11 +26,10 @@ class DaytonaPtySession:
25
26
  """Tracks a Daytona PTY session."""
26
27
 
27
28
  info: PtyInfo
28
- handle: object # Daytona PTY handle
29
+ handle: AsyncPtyHandle
29
30
  sandbox: AsyncSandbox
30
31
  _output_buffer: list[bytes] = field(default_factory=list)
31
32
  _output_event: asyncio.Event = field(default_factory=asyncio.Event)
32
- _reader_task: asyncio.Task[None] | None = None
33
33
 
34
34
 
35
35
  class DaytonaPtyManager(BasePtyManager):
@@ -38,13 +38,8 @@ class DaytonaPtyManager(BasePtyManager):
38
38
  Uses Daytona's process.create_pty_session API for interactive
39
39
  terminal sessions with full resize support.
40
40
 
41
- Key Daytona API features used:
42
- - sandbox.process.create_pty_session(id, pty_size)
43
- - handle.send_input(data)
44
- - handle.resize(PtySize)
45
- - handle.kill()
46
- - handle.wait()
47
- - Iteration over handle for output streaming
41
+ The on_data callback is used for streaming output, eliminating
42
+ the need for background reader tasks.
48
43
  """
49
44
 
50
45
  def __init__(self, sandbox: AsyncSandbox) -> None:
@@ -69,16 +64,15 @@ class DaytonaPtyManager(BasePtyManager):
69
64
 
70
65
  Args:
71
66
  size: Initial terminal size (defaults to 24x80)
72
- command: Not directly used - Daytona creates a shell session.
73
- Send commands via send_input after creation.
74
- args: Not used for Daytona PTY
75
- cwd: Working directory - change via cd command after session start
76
- env: Not directly supported - set via export commands
67
+ command: Command to run after shell starts (sent via stdin)
68
+ args: Arguments for the command
69
+ cwd: Working directory for the PTY session
70
+ env: Environment variables for the PTY session
77
71
 
78
72
  Returns:
79
73
  PtyInfo with session details
80
74
  """
81
- from daytona.common.pty import PtySize as DaytonaPtySize # type: ignore[import-untyped]
75
+ from daytona.common.pty import PtySize as DaytonaPtySize
82
76
 
83
77
  size = size or PtySize()
84
78
  command = command or "/bin/bash"
@@ -90,12 +84,6 @@ class DaytonaPtyManager(BasePtyManager):
90
84
  # Create Daytona PtySize object
91
85
  daytona_size = DaytonaPtySize(cols=size.cols, rows=size.rows)
92
86
 
93
- # Create PTY session using Daytona API
94
- handle = await self._sandbox.process.create_pty_session( # pyright: ignore[reportAttributeAccessIssue]
95
- id=pty_id,
96
- pty_size=daytona_size,
97
- )
98
-
99
87
  # Daytona doesn't expose PID directly
100
88
  info = PtyInfo(
101
89
  id=pty_id,
@@ -110,6 +98,20 @@ class DaytonaPtyManager(BasePtyManager):
110
98
  output_buffer: list[bytes] = []
111
99
  output_event = asyncio.Event()
112
100
 
101
+ # Callback to handle PTY output - called by Daytona when data arrives
102
+ def on_data(data: bytes) -> None:
103
+ output_buffer.append(data)
104
+ output_event.set()
105
+
106
+ # Create PTY session using Daytona API with callback
107
+ handle = await self._sandbox.process.create_pty_session(
108
+ id=pty_id,
109
+ on_data=on_data,
110
+ cwd=cwd,
111
+ envs=env,
112
+ pty_size=daytona_size,
113
+ )
114
+
113
115
  session = DaytonaPtySession(
114
116
  info=info,
115
117
  handle=handle,
@@ -120,13 +122,6 @@ class DaytonaPtyManager(BasePtyManager):
120
122
  self._sessions[pty_id] = info
121
123
  self._daytona_sessions[pty_id] = session
122
124
 
123
- # Start background reader task
124
- session._reader_task = asyncio.create_task(self._read_output(session))
125
-
126
- # If cwd specified, send cd command
127
- if cwd:
128
- await self.write(pty_id, f"cd {cwd}\n".encode())
129
-
130
125
  # If command specified (not default shell), send it
131
126
  if command and command != "/bin/bash":
132
127
  full_cmd = f"{command} {' '.join(args)}\n" if args else f"{command}\n"
@@ -134,42 +129,6 @@ class DaytonaPtyManager(BasePtyManager):
134
129
 
135
130
  return info
136
131
 
137
- async def _read_output(self, session: DaytonaPtySession) -> None:
138
- """Background task to read from Daytona PTY handle."""
139
- loop = asyncio.get_event_loop()
140
-
141
- try:
142
- # Daytona handle supports iteration for output
143
- # Run in executor since it may block
144
- def read_sync() -> bytes | None:
145
- try:
146
- for data in session.handle: # type: ignore[attr-defined]
147
- return data # type: ignore[no-any-return]
148
- except StopIteration:
149
- return None
150
- except Exception: # noqa: BLE001
151
- return None
152
- return None
153
-
154
- while session.info.status == "running":
155
- data = await loop.run_in_executor(None, read_sync)
156
- if data:
157
- session._output_buffer.append(data)
158
- session._output_event.set()
159
- else:
160
- # End of stream
161
- break
162
- except Exception: # noqa: BLE001
163
- pass
164
- finally:
165
- session.info.status = "exited"
166
- # Try to get exit code
167
- try:
168
- result = await loop.run_in_executor(None, session.handle.wait) # type: ignore[attr-defined]
169
- session.info.exit_code = result.exit_code
170
- except Exception: # noqa: BLE001
171
- pass
172
-
173
132
  async def resize(self, pty_id: str, size: PtySize) -> None:
174
133
  """Resize a PTY session.
175
134
 
@@ -187,10 +146,8 @@ class DaytonaPtyManager(BasePtyManager):
187
146
  msg = f"PTY session {pty_id} not found"
188
147
  raise KeyError(msg)
189
148
 
190
- # Resize using Daytona API
191
- loop = asyncio.get_event_loop()
192
149
  daytona_size = DaytonaPtySize(cols=size.cols, rows=size.rows)
193
- await loop.run_in_executor(None, session.handle.resize, daytona_size) # type: ignore[attr-defined]
150
+ await session.handle.resize(daytona_size)
194
151
  session.info.size = size
195
152
 
196
153
  async def write(self, pty_id: str, data: bytes) -> None:
@@ -210,8 +167,7 @@ class DaytonaPtyManager(BasePtyManager):
210
167
 
211
168
  # Daytona send_input expects string
212
169
  text = data.decode() if isinstance(data, bytes) else data
213
- loop = asyncio.get_event_loop()
214
- await loop.run_in_executor(None, session.handle.send_input, text) # type: ignore[attr-defined]
170
+ await session.handle.send_input(text)
215
171
 
216
172
  async def read(self, pty_id: str, size: int = 4096) -> bytes:
217
173
  """Read data from a PTY's output buffer.
@@ -292,17 +248,13 @@ class DaytonaPtyManager(BasePtyManager):
292
248
  return False
293
249
 
294
250
  try:
295
- # Cancel reader task
296
- if session._reader_task:
297
- session._reader_task.cancel()
298
- with contextlib.suppress(asyncio.CancelledError):
299
- await session._reader_task
300
-
301
- # Kill using Daytona API
302
- loop = asyncio.get_event_loop()
303
- await loop.run_in_executor(None, session.handle.kill) # type: ignore[attr-defined]
304
-
251
+ await session.handle.kill()
305
252
  session.info.status = "exited"
253
+
254
+ # Try to get exit code
255
+ with contextlib.suppress(Exception):
256
+ result = await session.handle.wait()
257
+ session.info.exit_code = result.exit_code
306
258
  except Exception: # noqa: BLE001
307
259
  pass
308
260
 
@@ -69,6 +69,8 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
69
69
  self.host_workdir: str | None = None
70
70
  # Docker containers are always Linux
71
71
  self._os_type = "Linux"
72
+ # Cache PTY manager instance
73
+ self._pty_manager: DockerPtyManager | None = None
72
74
 
73
75
  async def __aenter__(self) -> Self:
74
76
  from testcontainers.core.container import DockerContainer
@@ -124,7 +126,7 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
124
126
  def get_fs(self) -> DirFileSystem:
125
127
  """Return a DirFileSystem instance for the shared host directory."""
126
128
  from fsspec.implementations.dirfs import DirFileSystem
127
- from morefs.asyn_local import AsyncLocalFileSystem
129
+ from upathtools.filesystems import AsyncLocalFileSystem
128
130
 
129
131
  if not self.host_workdir:
130
132
  msg = "Docker environment not started"
@@ -133,12 +135,14 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
133
135
 
134
136
  def get_pty_manager(self) -> DockerPtyManager:
135
137
  """Return a DockerPtyManager for interactive terminal sessions."""
136
- from exxec.docker_provider.pty_manager import DockerPtyManager
138
+ if self._pty_manager is None:
139
+ from exxec.docker_provider.pty_manager import DockerPtyManager
137
140
 
138
- if not self.container:
139
- msg = "Docker environment not started"
140
- raise RuntimeError(msg)
141
- return DockerPtyManager(self.container.get_wrapped_container())
141
+ if not self.container:
142
+ msg = "Docker environment not started"
143
+ raise RuntimeError(msg)
144
+ self._pty_manager = DockerPtyManager(self.container.get_wrapped_container())
145
+ return self._pty_manager
142
146
 
143
147
  async def execute(self, code: str) -> ExecutionResult:
144
148
  """Execute code in Docker container."""
@@ -97,6 +97,8 @@ class E2bExecutionEnvironment(ExecutionEnvironment):
97
97
  self.sandbox: AsyncSandbox | None = None
98
98
  # E2B sandboxes run Linux
99
99
  self._os_type = "Linux"
100
+ # Cache PTY manager instance
101
+ self._pty_manager: E2BPtyManager | None = None
100
102
 
101
103
  def _ensure_initialized(self) -> AsyncSandbox:
102
104
  """Ensure async context."""
@@ -147,10 +149,12 @@ class E2bExecutionEnvironment(ExecutionEnvironment):
147
149
 
148
150
  def get_pty_manager(self) -> E2BPtyManager:
149
151
  """Return an E2BPtyManager for interactive terminal sessions."""
150
- from exxec.e2b_provider.pty_manager import E2BPtyManager
152
+ if self._pty_manager is None:
153
+ from exxec.e2b_provider.pty_manager import E2BPtyManager
151
154
 
152
- sandbox = self._ensure_initialized()
153
- return E2BPtyManager(sandbox)
155
+ sandbox = self._ensure_initialized()
156
+ self._pty_manager = E2BPtyManager(sandbox)
157
+ return self._pty_manager
154
158
 
155
159
  async def get_domain(self, port: int) -> str:
156
160
  """Return the domain name for the sandbox."""
@@ -88,6 +88,8 @@ class LocalExecutionEnvironment(ExecutionEnvironment):
88
88
  self.root_path = root_path
89
89
  # Local provider knows OS statically
90
90
  self._os_type = platform.system() # type: ignore[assignment]
91
+ # Cache PTY manager instance
92
+ self._pty_manager: LocalPtyManager | None = None
91
93
 
92
94
  async def __aenter__(self) -> Self:
93
95
  # Start tool server via base class
@@ -125,7 +127,7 @@ class LocalExecutionEnvironment(ExecutionEnvironment):
125
127
  def get_fs(self) -> AsyncFileSystem:
126
128
  """Return an AsyncLocalFileSystem for the current working directory."""
127
129
  from fsspec.implementations.dirfs import DirFileSystem # type: ignore[import-untyped]
128
- from morefs.asyn_local import AsyncLocalFileSystem
130
+ from upathtools.filesystems import AsyncLocalFileSystem
129
131
 
130
132
  fs = AsyncLocalFileSystem()
131
133
  if self.root_path:
@@ -134,9 +136,11 @@ class LocalExecutionEnvironment(ExecutionEnvironment):
134
136
 
135
137
  def get_pty_manager(self) -> LocalPtyManager:
136
138
  """Return a LocalPtyManager for interactive terminal sessions."""
137
- from exxec.local_provider.pty_manager import LocalPtyManager
139
+ if self._pty_manager is None:
140
+ from exxec.local_provider.pty_manager import LocalPtyManager
138
141
 
139
- return LocalPtyManager(cwd=self.cwd)
142
+ self._pty_manager = LocalPtyManager(cwd=self.cwd)
143
+ return self._pty_manager
140
144
 
141
145
  async def execute(self, code: str) -> ExecutionResult:
142
146
  """Execute code in same process or isolated subprocess."""
@@ -81,6 +81,8 @@ class MockExecutionEnvironment(ExecutionEnvironment):
81
81
  self._os_type = "Linux"
82
82
  self._deterministic_ids = deterministic_ids
83
83
  self._process_counter = 0
84
+ # Cache PTY manager instance
85
+ self._pty_manager: MockPtyManager | None = None
84
86
 
85
87
  @property
86
88
  def process_manager(self) -> MockProcessManager:
@@ -107,9 +109,11 @@ class MockExecutionEnvironment(ExecutionEnvironment):
107
109
 
108
110
  def get_pty_manager(self) -> MockPtyManager:
109
111
  """Return a MockPtyManager for testing interactive terminal sessions."""
110
- from exxec.mock_provider.pty_manager import MockPtyManager
112
+ if self._pty_manager is None:
113
+ from exxec.mock_provider.pty_manager import MockPtyManager
111
114
 
112
- return MockPtyManager()
115
+ self._pty_manager = MockPtyManager()
116
+ return self._pty_manager
113
117
 
114
118
  async def execute(self, code: str) -> ExecutionResult:
115
119
  """Execute code and return mock result."""
@@ -112,6 +112,8 @@ class ModalExecutionEnvironment(ExecutionEnvironment):
112
112
  self.sandbox: Sandbox | None = None
113
113
  # Modal sandboxes run Linux
114
114
  self._os_type = "Linux"
115
+ # Cache PTY manager instance
116
+ self._pty_manager: ModalPtyManager | None = None
115
117
 
116
118
  def _ensure_initialized(self) -> Sandbox:
117
119
  """Validate that the environment is properly initialized.
@@ -208,10 +210,12 @@ class ModalExecutionEnvironment(ExecutionEnvironment):
208
210
 
209
211
  def get_pty_manager(self) -> ModalPtyManager:
210
212
  """Return a ModalPtyManager for interactive terminal sessions."""
211
- from exxec.modal_provider.pty_manager import ModalPtyManager
213
+ if self._pty_manager is None:
214
+ from exxec.modal_provider.pty_manager import ModalPtyManager
212
215
 
213
- sandbox = self._ensure_initialized()
214
- return ModalPtyManager(sandbox)
216
+ sandbox = self._ensure_initialized()
217
+ self._pty_manager = ModalPtyManager(sandbox)
218
+ return self._pty_manager
215
219
 
216
220
  async def execute(self, code: str) -> ExecutionResult:
217
221
  """Execute code in the Modal sandbox."""
@@ -81,6 +81,8 @@ class SshExecutionEnvironment(ExecutionEnvironment):
81
81
  self._connection_cm: _ACMWrapper[SSHClientConnection] | None = None
82
82
  self.connection: SSHClientConnection | None = None
83
83
  self._remote_work_dir: str | None = None
84
+ # Cache PTY manager instance
85
+ self._pty_manager: SshPtyManager | None = None
84
86
  self._fs: WrapperFileSystem | None = None
85
87
 
86
88
  def _ensure_connected(self) -> SSHClientConnection:
@@ -207,10 +209,12 @@ class SshExecutionEnvironment(ExecutionEnvironment):
207
209
 
208
210
  def get_pty_manager(self) -> SshPtyManager:
209
211
  """Return a SshPtyManager for interactive terminal sessions."""
210
- from exxec.ssh_provider.pty_manager import SshPtyManager
212
+ if self._pty_manager is None:
213
+ from exxec.ssh_provider.pty_manager import SshPtyManager
211
214
 
212
- connection = self._ensure_connected()
213
- return SshPtyManager(connection)
215
+ connection = self._ensure_connected()
216
+ self._pty_manager = SshPtyManager(connection)
217
+ return self._pty_manager
214
218
 
215
219
  async def _verify_tools(self) -> None:
216
220
  """Verify that required tools are available on the remote machine."""
@@ -129,13 +129,13 @@ class VercelTerminalManager(ProcessManagerProtocol):
129
129
  # Check if command has finished by trying to get it again
130
130
  assert terminal.command_id
131
131
  updated_command = await self.sandbox.get_command(terminal.command_id)
132
- if updated_command.cmd.exitCode is not None:
132
+ if updated_command.cmd.exit_code is not None:
133
133
  # Command finished, collect final output
134
134
  if await updated_command.stdout():
135
135
  terminal.add_output(await updated_command.stdout())
136
136
  if await updated_command.stderr():
137
137
  terminal.add_output(f"STDERR: {await updated_command.stderr()}")
138
- terminal.set_exit_code(updated_command.cmd.exitCode)
138
+ terminal.set_exit_code(updated_command.cmd.exit_code)
139
139
  except Exception: # noqa: BLE001
140
140
  pass # Best effort
141
141
 
@@ -159,8 +159,8 @@ class VercelTerminalManager(ProcessManagerProtocol):
159
159
  if terminal.command_id:
160
160
  try:
161
161
  updated_command = await self.sandbox.get_command(terminal.command_id)
162
- if updated_command.cmd.exitCode is not None:
163
- terminal.set_exit_code(updated_command.cmd.exitCode)
162
+ if updated_command.cmd.exit_code is not None:
163
+ terminal.set_exit_code(updated_command.cmd.exit_code)
164
164
  break
165
165
  except Exception: # noqa: BLE001
166
166
  continue
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