Skip to content

improvement: switch run_command to process.exec with cwd/env/timeout support#4

Open
hjpinheiro wants to merge 1 commit into
daytona:mainfrom
hjpinheiro:improvement/run-command-cwd-env
Open

improvement: switch run_command to process.exec with cwd/env/timeout support#4
hjpinheiro wants to merge 1 commit into
daytona:mainfrom
hjpinheiro:improvement/run-command-cwd-env

Conversation

@hjpinheiro

Copy link
Copy Markdown

Summary

Replaces the session-based execution pattern with a single process.exec() call, adding support for working directory, environment variables, and timeout.

What changed

Before (session-based — overhead per command):

sandbox.process.create_session(session_id)
response = sandbox.process.execute_session_command(session_id, ...)
# ... then delete_session in finally block

After (single call — cleaner, more capable):

response = sandbox.process.exec(command, cwd=cwd, env=env_vars, timeout=timeout)

New parameters

Parameter Type Description
cwd string (optional) Working directory (e.g. /home/daytona/project)
env_vars string/JSON (optional) Environment variables as JSON object string
timeout number (optional) Execution timeout in seconds

Other improvements

  • Added create_text_message(response.result) so agents see command output directly in chat (previously only JSON was returned)
  • Added _parse_env_vars() helper supporting both JSON strings and dicts

⚠️ Breaking change — output format

The JSON response changes from separate stdout/stderr fields to a combined output field:

// Before:
{"exit_code": 0, "stdout": "...", "stderr": "..."}

// After:
{"exit_code": 0, "output": "..."}  // combined stdout + stderr

This is because process.exec returns combined output in result. If separate stdout/stderr is important, the session-based approach can be kept as an alternative.

Testing

  • py_compile passes
  • YAML validated with yaml.safe_load()
  • process.exec signature verified: (command, cwd=None, env=None, timeout=None) -> ExecuteResponse

Replace session-based execution (create_session + execute_session_command
+ delete_session) with a single process.exec() call. This eliminates
per-command session overhead and adds support for:

- cwd: working directory for command execution
- env_vars: environment variables as JSON object string
- timeout: optional execution timeout in seconds

Also adds create_text_message so the agent sees command output directly
in the chat (previously only JSON was returned).

Breaking: output format changes from {stdout, stderr} to {output} (combined).
The process.exec API returns combined stdout+stderr in the result field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants