Skip to content

feat: Add Daytona Deployment Support#288

Open
hyoungjun-noh wants to merge 3 commits into
SWE-agent:mainfrom
hyoungjun-noh:feat-support-daytona
Open

feat: Add Daytona Deployment Support#288
hyoungjun-noh wants to merge 3 commits into
SWE-agent:mainfrom
hyoungjun-noh:feat-support-daytona

Conversation

@hyoungjun-noh
Copy link
Copy Markdown

Summary

This PR adds support for running SWE-ReX agents in Daytona sandbox environments. Daytona is a sandbox environment platform that provides secure, isolated execution environments for AI agents.

Changes

New Components

  • DaytonaRuntime (runtime/daytona.py): SDK-based runtime that communicates with the swerex server running inside a Daytona sandbox. Uses the Daytona SDK's command execution capabilities instead of HTTP requests to bypass OAuth authentication issues with Preview URLs.

  • DaytonaDeployment (deployment/daytona.py): Deployment class for creating and managing Daytona sandboxes. Supports both self-hosted Daytona servers and public Daytona cloud.

Key Features

  • SDK-based communication: Uses Daytona SDK's execute_session_command to run commands inside the sandbox, avoiding OAuth authentication issues with Preview URLs
  • Self-hosted and cloud support: Configure with api_url for self-hosted or target for Daytona cloud
  • Health check polling: Monitors swerex server startup inside the sandbox using Python's urllib (no curl dependency)
  • Base64 encoding: Uses base64 encoding for command transfer to avoid shell escaping issues
  • Session management: Creates separate sessions for server process, health checks, and runtime communication

Configuration

from swerex.deployment.config import DaytonaDeploymentConfig
from swerex.deployment.daytona import DaytonaDeployment

# Self-hosted Daytona server
config = DaytonaDeploymentConfig(
    image="python:3.12-slim",
    api_url="https://your-daytona-server.com",
    api_key="your-api-key",
    port=8000,
)

# Or Daytona cloud
config = DaytonaDeploymentConfig(
    image="python:3.12-slim",
    target="us",
    api_key="your-api-key",
)

deployment = DaytonaDeployment.from_config(config)
await deployment.start()

Installation

pip install 'swe-rex[daytona]'

Implementation Details

Communication Flow

  1. DaytonaDeployment creates a Daytona sandbox from the specified image
  2. Starts the swerex server inside the sandbox using SDK command execution
  3. Polls for server health using Python urllib (no curl dependency)
  4. Creates DaytonaRuntime with a separate session for runtime commands
  5. DaytonaRuntime uses SDK command execution with base64-encoded Python scripts to call swerex API endpoints

Why SDK-based Communication?

Direct HTTP access to the swerex server via Preview URLs encounters OAuth authentication issues. By using the SDK's command execution to run Python scripts inside the sandbox, we can communicate with the swerex server on localhost without going through the OAuth layer.

Testing

Tested with:

  • Self-hosted Daytona server and public Daytona cloud service
  • Mini-SWE-Agent running terminal-bench tasks
  • Multiple concurrent sandbox creation and execution

Files Changed

  • src/swerex/runtime/daytona.py - New DaytonaRuntime class
  • src/swerex/deployment/daytona.py - New DaytonaDeployment class
  • src/swerex/deployment/config.py - Added DaytonaDeploymentConfig
  • pyproject.toml - Added daytona-sdk dependency and [daytona] extra
  • README.md - Updated installation instructions
  • CHANGELOG.md - Added Unreleased section with Daytona support

Related

hj-noh added 3 commits April 15, 2026 11:52
- Add api_url field to DaytonaDeploymentConfig for self-hosted deployments
- Switch from sync Daytona to AsyncDaytona client for better async support
- Add _poll_command method for async command execution polling
- Add _check_server_health method to verify server readiness with auth
- Support both cloud (target-based) and self-hosted (api_url-based) modes
Replace RemoteRuntime with DaytonaRuntime to communicate with the swerex
server inside Daytona sandboxes. The new implementation uses the Daytona
SDK's command execution capabilities instead of HTTP requests via Preview
URLs, which bypasses OAuth authentication issues encountered with the
previous approach.

Changes:
- Import and use DaytonaRuntime instead of RemoteRuntime
- Create runtime sessions via SDK instead of extracting Preview URLs
- Remove preview URL and token handling logic
- Add new DaytonaRuntime class that wraps SDK command execution
Remove WIP status from README. Refactor health check and command execution logic in DaytonaDeployment for improved reliability and readability. Add unit tests for DaytonaRuntime.
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.

1 participant