exxec 0.2.1__tar.gz → 0.3.0__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 (63) hide show
  1. {exxec-0.2.1 → exxec-0.3.0}/PKG-INFO +1 -1
  2. {exxec-0.2.1 → exxec-0.3.0}/pyproject.toml +5 -1
  3. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/__init__.py +1 -1
  4. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/acp_provider/provider.py +46 -3
  5. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/base.py +30 -4
  6. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/beam_provider/provider.py +45 -5
  7. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/daytona_provider/provider.py +23 -8
  8. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/docker_provider/provider.py +47 -9
  9. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/e2b_provider/provider.py +34 -14
  10. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/local_provider/provider.py +29 -16
  11. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/microsandbox_provider/provider.py +35 -5
  12. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/mock_provider/provider.py +14 -2
  13. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/modal_provider/provider.py +26 -15
  14. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/pyodide_provider/provider.py +18 -3
  15. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/remote_callable.py +1 -1
  16. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/srt_provider/provider.py +2 -1
  17. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/ssh_provider/provider.py +47 -15
  18. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/vercel_provider/provider.py +50 -5
  19. exxec-0.3.0/src/exxec_config/__init__.py +44 -0
  20. {exxec-0.2.1/src/exxec → exxec-0.3.0/src/exxec_config}/configs.py +5 -4
  21. exxec-0.3.0/src/exxec_config/srt_sandbox_config.py +79 -0
  22. {exxec-0.2.1 → exxec-0.3.0}/LICENSE +0 -0
  23. {exxec-0.2.1 → exxec-0.3.0}/README.md +0 -0
  24. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/acp_provider/__init__.py +0 -0
  25. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/acp_provider/process_manager.py +0 -0
  26. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/beam_provider/__init__.py +0 -0
  27. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/beam_provider/helpers.py +0 -0
  28. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/beam_provider/process_manager.py +0 -0
  29. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/daytona_provider/__init__.py +0 -0
  30. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/daytona_provider/helpers.py +0 -0
  31. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/daytona_provider/process_manager.py +0 -0
  32. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/daytona_provider/pty_manager.py +0 -0
  33. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/docker_provider/__init__.py +0 -0
  34. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/docker_provider/pty_manager.py +0 -0
  35. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/e2b_provider/__init__.py +0 -0
  36. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/e2b_provider/process_manager.py +0 -0
  37. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/e2b_provider/pty_manager.py +0 -0
  38. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/events.py +0 -0
  39. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/local_provider/__init__.py +0 -0
  40. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/local_provider/pty_manager.py +0 -0
  41. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/local_provider/utils.py +0 -0
  42. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/log.py +0 -0
  43. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/microsandbox_provider/__init__.py +0 -0
  44. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/mock_provider/__init__.py +0 -0
  45. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/mock_provider/process_manager.py +0 -0
  46. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/mock_provider/pty_manager.py +0 -0
  47. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/modal_provider/__init__.py +0 -0
  48. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/modal_provider/pty_manager.py +0 -0
  49. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/models.py +0 -0
  50. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/parse_output.py +0 -0
  51. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/pep723.py +0 -0
  52. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/process_manager.py +0 -0
  53. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/pty_manager.py +0 -0
  54. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/py.typed +0 -0
  55. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/pyodide_provider/__init__.py +0 -0
  56. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/pyodide_provider/filesystem.py +0 -0
  57. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/pyodide_provider/pyodide_server.ts +0 -0
  58. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/srt_provider/__init__.py +0 -0
  59. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/srt_provider/config.py +0 -0
  60. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/ssh_provider/__init__.py +0 -0
  61. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/ssh_provider/pty_manager.py +0 -0
  62. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/vercel_provider/__init__.py +0 -0
  63. {exxec-0.2.1 → exxec-0.3.0}/src/exxec/vercel_provider/process_manager.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: exxec
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: Execution environments
5
5
  Keywords:
6
6
  Author: Philipp Temminghoff
@@ -2,7 +2,7 @@
2
2
 
3
3
  [project]
4
4
  name = "exxec"
5
- version = "0.2.1"
5
+ version = "0.3.0"
6
6
  description = "Execution environments"
7
7
  readme = "README.md"
8
8
  requires-python = ">=3.13"
@@ -294,6 +294,10 @@ default-groups = ["dev", "lint", "docs"]
294
294
  override-dependencies = ["websockets>=15.0.0"]
295
295
 
296
296
  [tool.uv.build-backend]
297
+ module-name = [
298
+ "exxec",
299
+ "exxec_config",
300
+ ]
297
301
  wheel-exclude = [
298
302
  ".mypy_cache/**",
299
303
  "__pycache__/**",
@@ -31,7 +31,7 @@ from exxec.models import ExecutionResult, ServerInfo
31
31
  from exxec.remote_callable import create_remote_callable, infer_package_dependencies
32
32
 
33
33
  # from exxec.server import fastapi_tool_server
34
- from exxec.configs import ExecutionEnvironmentConfig
34
+ from exxec_config import ExecutionEnvironmentConfig
35
35
  from exxec.ssh_provider import SshExecutionEnvironment, SshPtyManager
36
36
  from exxec.pty_manager import BasePtyManager, PtyInfo, PtyManagerProtocol, PtySize
37
37
 
@@ -61,6 +61,7 @@ class ACPExecutionEnvironment(ExecutionEnvironment):
61
61
  cwd: str | None = None,
62
62
  env_vars: dict[str, str] | None = None,
63
63
  language: Language = "python",
64
+ default_command_timeout: float | None = None,
64
65
  ) -> None:
65
66
  """Initialize ACP execution environment.
66
67
 
@@ -72,12 +73,14 @@ class ACPExecutionEnvironment(ExecutionEnvironment):
72
73
  cwd: Working directory for the environment
73
74
  env_vars: Environment variables to set for all executions
74
75
  language: Programming language for code execution (python, javascript, typescript)
76
+ default_command_timeout: Default timeout for command execution in seconds
75
77
  """
76
78
  super().__init__(
77
79
  lifespan_handler=lifespan_handler,
78
80
  dependencies=dependencies,
79
81
  cwd=cwd,
80
82
  env_vars=env_vars,
83
+ default_command_timeout=default_command_timeout,
81
84
  )
82
85
  self._fs = fs
83
86
  self._requests = requests
@@ -190,15 +193,25 @@ class ACPExecutionEnvironment(ExecutionEnvironment):
190
193
  cmd, args=args, output_byte_limit=1048576, env=self.env_vars or None
191
194
  )
192
195
 
193
- async def execute_command(self, command: str) -> ExecutionResult:
196
+ async def execute_command(
197
+ self,
198
+ command: str,
199
+ *,
200
+ timeout: float | None = None,
201
+ ) -> ExecutionResult:
194
202
  """Execute a terminal command using ACP terminal capabilities.
195
203
 
196
204
  Args:
197
205
  command: Terminal command to execute (supports shell features like pipes)
206
+ timeout: Optional timeout in seconds (wraps command with shell timeout)
198
207
 
199
208
  Returns:
200
209
  ExecutionResult with command output and metadata
201
210
  """
211
+ effective_timeout = timeout if timeout is not None else self.default_command_timeout
212
+ # Wrap command with shell timeout if specified
213
+ if effective_timeout is not None:
214
+ command = f"timeout {effective_timeout} {command}"
202
215
  start_time = time.perf_counter()
203
216
  try:
204
217
  # Pass command directly without splitting - ACP clients run it through
@@ -211,6 +224,18 @@ class ACPExecutionEnvironment(ExecutionEnvironment):
211
224
  exit_code = exit_result.exit_code or 0
212
225
  duration = time.perf_counter() - start_time
213
226
  output = output_response.output or ""
227
+ # Exit code 124 is timeout's exit code when command times out
228
+ if exit_code == 124: # noqa: PLR2004
229
+ return ExecutionResult(
230
+ result=None,
231
+ stdout=output,
232
+ stderr=None,
233
+ success=False,
234
+ exit_code=exit_code,
235
+ error=f"Command timed out after {effective_timeout} seconds",
236
+ error_type="TimeoutError",
237
+ duration=duration,
238
+ )
214
239
  return ExecutionResult(
215
240
  result=output,
216
241
  stdout=output,
@@ -223,15 +248,25 @@ class ACPExecutionEnvironment(ExecutionEnvironment):
223
248
  except Exception as e: # noqa: BLE001
224
249
  return ExecutionResult.failed(e, start_time)
225
250
 
226
- async def stream_command(self, command: str) -> AsyncIterator[ExecutionEvent]:
251
+ async def stream_command(
252
+ self,
253
+ command: str,
254
+ *,
255
+ timeout: float | None = None,
256
+ ) -> AsyncIterator[ExecutionEvent]:
227
257
  """Execute a terminal command and stream events.
228
258
 
229
259
  Args:
230
260
  command: Terminal command to execute (supports shell features like pipes)
261
+ timeout: Optional timeout in seconds (wraps command with shell timeout)
231
262
 
232
263
  Yields:
233
264
  ExecutionEvent objects as they occur
234
265
  """
266
+ effective_timeout = timeout if timeout is not None else self.default_command_timeout
267
+ # Wrap command with shell timeout if specified
268
+ if effective_timeout is not None:
269
+ command = f"timeout {effective_timeout} {command}"
235
270
  start_time = time.perf_counter()
236
271
  terminal_id: str | None = None
237
272
  try:
@@ -247,7 +282,15 @@ class ACPExecutionEnvironment(ExecutionEnvironment):
247
282
  if response.output:
248
283
  yield OutputEvent(process_id=terminal_id, data=response.output, stream="combined")
249
284
  exit_code = exit_result.exit_code or 0
250
- if exit_code == 0:
285
+ # Exit code 124 is timeout's exit code when command times out
286
+ if exit_code == 124: # noqa: PLR2004
287
+ yield ProcessErrorEvent(
288
+ process_id=terminal_id,
289
+ error=f"Command timed out after {effective_timeout} seconds",
290
+ error_type="TimeoutError",
291
+ exit_code=exit_code,
292
+ )
293
+ elif exit_code == 0:
251
294
  yield ProcessCompletedEvent(
252
295
  process_id=terminal_id,
253
296
  exit_code=exit_code,
@@ -33,6 +33,7 @@ class ExecutionEnvironment(ABC):
33
33
  cwd: str | None = None,
34
34
  env_vars: dict[str, str] | None = None,
35
35
  inherit_env: bool = False,
36
+ default_command_timeout: float | None = None,
36
37
  **kwargs: Any,
37
38
  ) -> None:
38
39
  """Initialize execution environment with optional lifespan handler.
@@ -43,6 +44,9 @@ class ExecutionEnvironment(ABC):
43
44
  cwd: Working directory for the environment (None means use default/auto)
44
45
  env_vars: Environment variables to set for all executions
45
46
  inherit_env: If True, inherit environment variables from os.environ
47
+ default_command_timeout: Default timeout for command execution in seconds.
48
+ If None, commands run without timeout unless explicitly specified.
49
+ This is separate from sandbox/instance lifetime timeouts.
46
50
  **kwargs: Additional keyword arguments for specific providers
47
51
  """
48
52
  self.lifespan_handler = lifespan_handler
@@ -51,6 +55,7 @@ class ExecutionEnvironment(ABC):
51
55
  self.cwd = cwd
52
56
  self.env_vars = env_vars or {}
53
57
  self.inherit_env = inherit_env
58
+ self.default_command_timeout = default_command_timeout
54
59
  self._process_manager: ProcessManagerProtocol | None = None
55
60
  self._os_type: OSType | None = None
56
61
 
@@ -196,11 +201,18 @@ class ExecutionEnvironment(ABC):
196
201
  ...
197
202
 
198
203
  @abstractmethod
199
- def stream_command(self, command: str) -> AsyncIterator[ExecutionEvent]:
204
+ def stream_command(
205
+ self,
206
+ command: str,
207
+ *,
208
+ timeout: float | None = None,
209
+ ) -> AsyncIterator[ExecutionEvent]:
200
210
  """Execute a terminal command and stream events (required).
201
211
 
202
212
  Args:
203
213
  command: Terminal command to execute
214
+ timeout: Command timeout in seconds. If None, uses default_command_timeout.
215
+ If both are None, command runs without timeout.
204
216
 
205
217
  Yields:
206
218
  ExecutionEvent objects as they occur
@@ -225,31 +237,45 @@ class ExecutionEnvironment(ABC):
225
237
  yield event.data
226
238
 
227
239
  @abstractmethod
228
- async def execute_command(self, command: str) -> ExecutionResult:
240
+ async def execute_command(
241
+ self,
242
+ command: str,
243
+ *,
244
+ timeout: float | None = None,
245
+ ) -> ExecutionResult:
229
246
  """Execute a terminal command and return result with metadata.
230
247
 
231
248
  Args:
232
249
  command: Terminal command to execute
250
+ timeout: Command timeout in seconds. If None, uses default_command_timeout.
251
+ If both are None, command runs without timeout.
233
252
 
234
253
  Returns:
235
254
  ExecutionResult with command output and metadata
236
255
  """
237
256
  ...
238
257
 
239
- async def execute_command_stream(self, command: str) -> AsyncIterator[str]:
258
+ async def execute_command_stream(
259
+ self,
260
+ command: str,
261
+ *,
262
+ timeout: float | None = None,
263
+ ) -> AsyncIterator[str]:
240
264
  """Execute a terminal command and stream output line by line.
241
265
 
242
266
  Default implementation delegates to stream_command() and filters OutputEvents.
243
267
 
244
268
  Args:
245
269
  command: Terminal command to execute
270
+ timeout: Command timeout in seconds. If None, uses default_command_timeout.
271
+ If both are None, command runs without timeout.
246
272
 
247
273
  Yields:
248
274
  Lines of output as they are produced
249
275
  """
250
276
  from exxec.events import OutputEvent
251
277
 
252
- async for event in self.stream_command(command):
278
+ async for event in self.stream_command(command, timeout=timeout):
253
279
  if isinstance(event, OutputEvent):
254
280
  yield event.data
255
281
 
@@ -47,6 +47,7 @@ class BeamExecutionEnvironment(ExecutionEnvironment):
47
47
  cwd: str | None = None,
48
48
  env_vars: dict[str, str] | None = None,
49
49
  inherit_env: bool = False,
50
+ default_command_timeout: float | None = None,
50
51
  ) -> None:
51
52
  """Initialize Beam environment.
52
53
 
@@ -56,11 +57,12 @@ class BeamExecutionEnvironment(ExecutionEnvironment):
56
57
  cpu: CPU cores allocated to the container
57
58
  memory: Memory allocated to the container (MiB or string with units)
58
59
  keep_warm_seconds: Seconds to keep sandbox alive (-1 for no timeout)
59
- timeout: Execution timeout in seconds
60
+ timeout: Sandbox lifetime timeout in seconds
60
61
  language: Programming language to use
61
62
  cwd: Working directory for the sandbox
62
63
  env_vars: Environment variables to set for all executions
63
64
  inherit_env: If True, inherit environment variables from os.environ
65
+ default_command_timeout: Default timeout for command execution in seconds
64
66
  """
65
67
  super().__init__(
66
68
  lifespan_handler=lifespan_handler,
@@ -68,6 +70,7 @@ class BeamExecutionEnvironment(ExecutionEnvironment):
68
70
  cwd=cwd,
69
71
  env_vars=env_vars,
70
72
  inherit_env=inherit_env,
73
+ default_command_timeout=default_command_timeout,
71
74
  )
72
75
  self.cpu = cpu
73
76
  self.memory = memory
@@ -162,14 +165,23 @@ class BeamExecutionEnvironment(ExecutionEnvironment):
162
165
  except Exception as e: # noqa: BLE001
163
166
  return ExecutionResult.failed(e, start_time)
164
167
 
165
- async def execute_command(self, command: str) -> ExecutionResult:
168
+ async def execute_command(
169
+ self,
170
+ command: str,
171
+ *,
172
+ timeout: float | None = None,
173
+ ) -> ExecutionResult:
166
174
  """Execute a terminal command in the Beam sandbox."""
167
175
  self.instance = self.validate_instance()
168
176
  cmd, args = parse_command(command)
169
177
  start_time = time.time()
178
+ effective_timeout = timeout if timeout is not None else self.default_command_timeout
170
179
  try:
171
180
  process = self.instance.process.exec(cmd, *args, env=self.get_env())
172
- exit_code = await asyncio.to_thread(process.wait)
181
+ exit_code = await asyncio.wait_for(
182
+ asyncio.to_thread(process.wait),
183
+ timeout=effective_timeout,
184
+ )
173
185
  output = "\n".join(line.rstrip("\n\r") for line in process.logs)
174
186
  success = exit_code == 0
175
187
  return ExecutionResult(
@@ -183,6 +195,17 @@ class BeamExecutionEnvironment(ExecutionEnvironment):
183
195
  stderr="", # Beam combines stdout/stderr
184
196
  )
185
197
 
198
+ except TimeoutError:
199
+ return ExecutionResult(
200
+ result=None,
201
+ duration=time.time() - start_time,
202
+ success=False,
203
+ error=f"Command timed out after {effective_timeout} seconds",
204
+ error_type="TimeoutError",
205
+ exit_code=1,
206
+ stdout="",
207
+ stderr="",
208
+ )
186
209
  except Exception as e: # noqa: BLE001
187
210
  return ExecutionResult.failed(e, start_time)
188
211
 
@@ -222,9 +245,15 @@ class BeamExecutionEnvironment(ExecutionEnvironment):
222
245
  except Exception as e: # noqa: BLE001
223
246
  yield ProcessErrorEvent.failed(e, process_id=process_id)
224
247
 
225
- async def stream_command(self, command: str) -> AsyncIterator[ExecutionEvent]:
248
+ async def stream_command(
249
+ self,
250
+ command: str,
251
+ *,
252
+ timeout: float | None = None,
253
+ ) -> AsyncIterator[ExecutionEvent]:
226
254
  """Execute a terminal command and stream events in the Beam sandbox."""
227
255
  self.instance = self.validate_instance()
256
+ effective_timeout = timeout if timeout is not None else self.default_command_timeout
228
257
  cmd, args = parse_command(command)
229
258
  process_id: str | None = None
230
259
  try:
@@ -236,7 +265,10 @@ class BeamExecutionEnvironment(ExecutionEnvironment):
236
265
  process_id=process_id, data=line.rstrip("\n\r"), stream="combined"
237
266
  )
238
267
 
239
- exit_code = await asyncio.to_thread(process.wait)
268
+ exit_code = await asyncio.wait_for(
269
+ asyncio.to_thread(process.wait),
270
+ timeout=effective_timeout,
271
+ )
240
272
  if exit_code == 0:
241
273
  yield ProcessCompletedEvent(process_id=process_id, exit_code=exit_code)
242
274
  else:
@@ -247,6 +279,14 @@ class BeamExecutionEnvironment(ExecutionEnvironment):
247
279
  exit_code=exit_code,
248
280
  )
249
281
 
282
+ except TimeoutError:
283
+ error_id = process_id or str(uuid.uuid4())[:8]
284
+ yield ProcessErrorEvent(
285
+ process_id=error_id,
286
+ error=f"Command timed out after {effective_timeout} seconds",
287
+ error_type="TimeoutError",
288
+ exit_code=1,
289
+ )
250
290
  except Exception as e: # noqa: BLE001
251
291
  error_id = process_id or str(uuid.uuid4())[:8]
252
292
  yield ProcessErrorEvent.failed(e, process_id=error_id)
@@ -4,7 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import contextlib
6
6
  import time
7
- from typing import TYPE_CHECKING, Self
7
+ from typing import TYPE_CHECKING, Any, Self
8
8
 
9
9
  from exxec.base import ExecutionEnvironment
10
10
  from exxec.daytona_provider.helpers import convert_language
@@ -43,6 +43,7 @@ class DaytonaExecutionEnvironment(ExecutionEnvironment):
43
43
  cwd: str | None = None,
44
44
  env_vars: dict[str, str] | None = None,
45
45
  inherit_env: bool = False,
46
+ default_command_timeout: float | None = None,
46
47
  ) -> None:
47
48
  """Initialize Daytona environment.
48
49
 
@@ -53,12 +54,13 @@ class DaytonaExecutionEnvironment(ExecutionEnvironment):
53
54
  api_key: API key for authentication (uses DAYTONA_API_KEY env var if None)
54
55
  target: Target location (uses DAYTONA_TARGET env var if None)
55
56
  image: Docker image to use for the sandbox
56
- timeout: Execution timeout in seconds
57
+ timeout: Sandbox lifetime timeout in seconds
57
58
  keep_alive: Keep sandbox running after execution
58
59
  language: Programming language to use for execution
59
60
  cwd: Working directory for the sandbox
60
61
  env_vars: Environment variables to set for all executions
61
62
  inherit_env: If True, inherit environment variables from os.environ
63
+ default_command_timeout: Default timeout for command execution in seconds
62
64
  """
63
65
  from daytona import AsyncDaytona, DaytonaConfig # type: ignore[import-untyped]
64
66
 
@@ -68,6 +70,7 @@ class DaytonaExecutionEnvironment(ExecutionEnvironment):
68
70
  cwd=cwd,
69
71
  env_vars=env_vars,
70
72
  inherit_env=inherit_env,
73
+ default_command_timeout=default_command_timeout,
71
74
  )
72
75
  self.image = image
73
76
  self.timeout = timeout
@@ -182,13 +185,20 @@ class DaytonaExecutionEnvironment(ExecutionEnvironment):
182
185
  except Exception as e: # noqa: BLE001
183
186
  return ExecutionResult.failed(e, start_time)
184
187
 
185
- async def execute_command(self, command: str) -> ExecutionResult:
188
+ async def execute_command(
189
+ self,
190
+ command: str,
191
+ *,
192
+ timeout: float | None = None,
193
+ ) -> ExecutionResult:
186
194
  """Execute a terminal command in the Daytona sandbox."""
187
195
  start_time = time.time()
196
+ effective_timeout = timeout if timeout is not None else self.default_command_timeout
188
197
  try:
189
- response = await self.sandbox.process.exec(
190
- command, timeout=int(self.timeout), env=self.get_env()
191
- )
198
+ exec_kwargs: dict[str, Any] = {"env": self.get_env()}
199
+ if effective_timeout is not None:
200
+ exec_kwargs["timeout"] = int(effective_timeout)
201
+ response = await self.sandbox.process.exec(command, **exec_kwargs)
192
202
  success = response.exit_code == 0
193
203
  return ExecutionResult(
194
204
  result=response.result if success else None,
@@ -228,12 +238,17 @@ class DaytonaExecutionEnvironment(ExecutionEnvironment):
228
238
  except Exception as e: # noqa: BLE001
229
239
  yield ProcessErrorEvent.failed(e, process_id=process_id)
230
240
 
231
- async def stream_command(self, command: str) -> AsyncIterator[ExecutionEvent]:
241
+ async def stream_command(
242
+ self,
243
+ command: str,
244
+ *,
245
+ timeout: float | None = None,
246
+ ) -> AsyncIterator[ExecutionEvent]:
232
247
  """Execute terminal command and stream events in the Daytona sandbox."""
233
248
  process_id = f"daytona_cmd_{id(self.sandbox)}"
234
249
  yield ProcessStartedEvent(process_id=process_id, command=command)
235
250
  try:
236
- result = await self.execute_command(command)
251
+ result = await self.execute_command(command, timeout=timeout)
237
252
  if result.stdout:
238
253
  yield OutputEvent(process_id=process_id, data=result.stdout, stream="combined")
239
254
  if result.success:
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import asyncio
5
6
  import contextlib
6
7
  import shutil
7
8
  import tempfile
@@ -35,7 +36,7 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
35
36
  lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
36
37
  dependencies: list[str] | None = None,
37
38
  image: str = "python:3.13-slim",
38
- timeout: float = 60.0,
39
+ default_command_timeout: float | None = 60.0,
39
40
  language: Language = "python",
40
41
  cwd: str | None = None,
41
42
  env_vars: dict[str, str] | None = None,
@@ -47,7 +48,8 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
47
48
  lifespan_handler: Async context manager for tool server (optional)
48
49
  dependencies: List of packages to install (pip for Python, npm for JS/TS)
49
50
  image: Docker image to use
50
- timeout: Execution timeout in seconds
51
+ default_command_timeout: Default timeout for command execution in seconds.
52
+ If None, commands run without timeout unless explicitly specified.
51
53
  language: Programming language to use
52
54
  cwd: Working directory for the sandbox
53
55
  env_vars: Environment variables to set for all executions
@@ -59,9 +61,9 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
59
61
  cwd=cwd,
60
62
  env_vars=env_vars,
61
63
  inherit_env=inherit_env,
64
+ default_command_timeout=default_command_timeout,
62
65
  )
63
66
  self.image = image
64
- self.timeout = timeout
65
67
  self.language: Language = language
66
68
  self.container: DockerContainer | None = None
67
69
  self.host_workdir: str | None = None
@@ -188,9 +190,15 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
188
190
  except Exception as e: # noqa: BLE001
189
191
  return ExecutionResult.failed(e, start_time)
190
192
 
191
- async def execute_command(self, command: str) -> ExecutionResult:
193
+ async def execute_command(
194
+ self,
195
+ command: str,
196
+ *,
197
+ timeout: float | None = None,
198
+ ) -> ExecutionResult:
192
199
  """Execute a terminal command in Docker container and return result."""
193
200
  start_time = time.time()
201
+ effective_timeout = timeout if timeout is not None else self.default_command_timeout
194
202
 
195
203
  try:
196
204
  if not self.container:
@@ -207,7 +215,9 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
207
215
  install_cmd = None
208
216
 
209
217
  if install_cmd:
210
- install_result = self.container.exec(["sh", "-c", install_cmd])
218
+ install_result = await asyncio.to_thread(
219
+ self.container.exec, ["sh", "-c", install_cmd]
220
+ )
211
221
  if install_result.exit_code != 0:
212
222
  error_msg = f"Failed to install dependencies: {self.dependencies}"
213
223
  return ExecutionResult(
@@ -224,7 +234,10 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
224
234
  # Execute the command cleanly (no dependency installation output)
225
235
  # Run in /workspace directory to match execute_command_stream behavior
226
236
  full_command = f"sh -c 'cd /workspace && {command}'"
227
- result = self.container.exec(full_command)
237
+ result = await asyncio.wait_for(
238
+ asyncio.to_thread(self.container.exec, full_command),
239
+ timeout=effective_timeout,
240
+ )
228
241
  duration = time.time() - start_time
229
242
 
230
243
  stdout = result.output.decode() if result.output else ""
@@ -241,6 +254,17 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
241
254
  stderr="",
242
255
  )
243
256
 
257
+ except TimeoutError:
258
+ return ExecutionResult(
259
+ result=None,
260
+ duration=time.time() - start_time,
261
+ success=False,
262
+ error=f"Command timed out after {effective_timeout} seconds",
263
+ error_type="TimeoutError",
264
+ exit_code=1,
265
+ stdout="",
266
+ stderr="",
267
+ )
244
268
  except Exception as e: # noqa: BLE001
245
269
  return ExecutionResult.failed(e, start_time)
246
270
 
@@ -293,9 +317,15 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
293
317
  except Exception as e: # noqa: BLE001
294
318
  yield ProcessErrorEvent.failed(e, process_id=process_id)
295
319
 
296
- async def stream_command(self, command: str) -> AsyncIterator[ExecutionEvent]:
320
+ async def stream_command(
321
+ self,
322
+ command: str,
323
+ *,
324
+ timeout: float | None = None,
325
+ ) -> AsyncIterator[ExecutionEvent]:
297
326
  """Execute a shell command and stream events in the Docker container."""
298
327
  process_id = f"docker_cmd_{id(self.container)}"
328
+ effective_timeout = timeout if timeout is not None else self.default_command_timeout
299
329
  yield ProcessStartedEvent(process_id=process_id, command=command)
300
330
 
301
331
  try:
@@ -307,7 +337,7 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
307
337
  )
308
338
  return
309
339
 
310
- full_command = f"sh -c 'cd /workspace && {command}'"
340
+ full_command = f"sh -c 'cd /workspace && timeout {effective_timeout} {command}'"
311
341
  docker_container = self.container.get_wrapped_container()
312
342
  result = docker_container.exec_run(full_command, stream=True)
313
343
 
@@ -319,7 +349,15 @@ class DockerExecutionEnvironment(ExecutionEnvironment):
319
349
  yield OutputEvent(process_id=process_id, data=line, stream="combined")
320
350
 
321
351
  exit_code = result.exit_code or 0
322
- if exit_code == 0:
352
+ # Exit code 124 is timeout's exit code when command times out
353
+ if exit_code == 124: # noqa: PLR2004
354
+ yield ProcessErrorEvent(
355
+ process_id=process_id,
356
+ error=f"Command timed out after {effective_timeout} seconds",
357
+ error_type="TimeoutError",
358
+ exit_code=exit_code,
359
+ )
360
+ elif exit_code == 0:
323
361
  yield ProcessCompletedEvent(process_id=process_id, exit_code=exit_code)
324
362
  else:
325
363
  yield ProcessErrorEvent(