Skip to content

feature: add start_service and get_service_logs for background processes#8

Open
hjpinheiro wants to merge 1 commit into
daytona:mainfrom
hjpinheiro:feature/background-services
Open

feature: add start_service and get_service_logs for background processes#8
hjpinheiro wants to merge 1 commit into
daytona:mainfrom
hjpinheiro:feature/background-services

Conversation

@hjpinheiro

Copy link
Copy Markdown

Summary

Two new tools for running long-lived processes (web servers, daemons, build watchers) in sandboxes:

Tool Purpose SDK API
start_service Start a background command asynchronously process.create_session() + execute_session_command(var_async=True)
get_service_logs Retrieve logs from a background service process.get_session_command_logs()

Problem solved

run_command blocks until the command completes. This makes it impossible to start web servers, API servers, or any long-running process — the tool times out or blocks indefinitely.

start_service solves this by executing commands with var_async=True, which returns immediately with a session_id and cmd_id. The agent can then poll get_service_logs to check progress.

Design

start_service:

  • Creates a session, executes command with var_async=True
  • Returns session_id + cmd_id for log retrieval
  • Parameters: sandbox_id (required), command (required)

get_service_logs:

  • Retrieves current stdout/stderr from a running service
  • Auto-discovers cmd_id from the session if not provided (fallback via get_session())
  • Parameters: sandbox_id (required), session_id (required), cmd_id (optional)

Example workflow

1. create_sandbox → sandbox_id
2. start_service(sandbox_id, "python app.py") → session_id, cmd_id
3. get_service_logs(sandbox_id, session_id) → "Running on http://0.0.0.0:5000"
4. get_preview_url(sandbox_id, port=5000) → public URL

Testing

  • Both .py files pass py_compile
  • Both .yaml files pass yaml.safe_load
  • provider/daytona.yaml validates with 9 total tools (7 original + 2 new)

Two new tools for running long-lived processes in sandboxes:

- start_service: start a background command (web server, daemon) using
  async session execution. Returns session_id and cmd_id for later log
  retrieval. The command runs asynchronously — returns immediately.
- get_service_logs: retrieve stdout/stderr from a background service.
  Auto-discovers cmd_id from the session if not provided.

This solves the problem of run_command timing out on long-running servers.
Instead of blocking, the agent starts the service, then polls logs.
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