Overview
Daytona supports two primary execution modes:- Code execution - Run code directly using language-specific runtimes
- Command execution - Execute shell commands with full control over the environment
Code Execution
Basic Code Running
Execute code in the sandbox using the appropriate language runtime:Code Execution with Parameters
Pass environment variables and command-line arguments:string
required
Code to execute in the sandbox
CodeRunParams
Execution parameters
number
Maximum execution time in seconds (0 = no timeout)
Execution Artifacts
The response includes parsed artifacts from execution:Command Execution
Running Shell Commands
Execute shell commands with full environment control:Commands with Working Directory
Specify the working directory for command execution:Commands with Environment Variables
Commands with Timeout
string
required
Shell command to execute
string
Working directory for command execution. Defaults to sandbox working directory.
Record<string, string>
Environment variables to set for the command
number
Maximum time in seconds to wait (0 = wait indefinitely)
Session-Based Execution
Sessions maintain state between commands, ideal for multi-step workflows.Creating a Session
Executing Commands in a Session
Commands in a session share environment and context:Asynchronous Session Commands
Run long-running commands without blocking:Streaming Session Logs
Stream output from asynchronous commands in real-time:Sending Input to Session Commands
Send input to interactive commands:Managing Sessions
string
required
Unique identifier for the session
SessionExecuteRequest
required
Command execution request
Error Handling
Handle execution failures gracefully:Best Practices
Set appropriate timeouts
Set appropriate timeouts
Always set timeouts for potentially long-running commands to prevent indefinite blocking.
Stream logs for long operations
Stream logs for long operations
For long-running operations, use async execution with log streaming to provide real-time feedback.
Clean up sessions
Clean up sessions
Delete sessions when finished to free up sandbox resources.
Related Resources
PTY Sessions
Interactive terminal sessions with full TTY support
Code Interpreter
Advanced Python code execution with context isolation