Overview
The module handles:- Creating isolated sandboxes for each candidate
- Uploading and executing candidate scripts
- Capturing stdout and generated artifacts
- Measuring execution time and success metrics
- Automatic cleanup of sandbox resources
Requires the Daytona SDK (
pip install daytona-sdk) and a valid DAYTONA_API_KEY in your environment.Configuration
Environment Variables
Your Daytona API key for authentication
The Daytona API base URL
Configuration Functions
Core Functions
run_candidate_in_daytona
Run a single candidate script in a Daytona sandbox.Parameters
Identifier for the candidate (e.g., “alpha”, “beta”, “gamma”)
Local path to the candidate Python script to execute
The objective string to pass as the first argument to the script
Path where the script should write its output artifact (inside sandbox)
Optional callback for logging progress. Receives
(candidate_id, message) for each log event.Returns
Result object containing execution details and artifacts
Example
Execution Flow
- Initialize - Connect to Daytona API with credentials
- Create Sandbox - Provision isolated sandbox environment
- Upload Script - Base64 encode and transfer script to sandbox
- Execute - Run script with objective and output path arguments
- Capture Output - Collect stdout and read artifact file
- Cleanup - Delete sandbox resources
- Return Result - Package all data into
DaytonaResult
run_all_candidates_in_daytona
Run multiple candidates in parallel, each in their own sandbox.Parameters
List of candidate dictionaries with
id and script keysThe objective to pass to all candidates
Local directory where artifacts will be saved (creates subdirectories per candidate)
Optional callback for logging progress from all candidates
Returns
List of result objects, one per candidate, in the same order as input
Example
Data Classes
DaytonaResult
Contains the complete execution result for a candidate.Fields
The candidate identifier (“alpha”, “beta”, “gamma”)
The Daytona sandbox ID (first 8 characters shown in logs)
Whether the execution completed successfully (exit code 0 and artifact retrieved)
Standard output from the script execution
The contents of the output file, if successfully retrieved
Total execution time including sandbox creation and cleanup
Error description if
success is FalseSandbox Configuration
Each sandbox runs with the following configuration:Error Handling
The module handles several error scenarios gracefully:Best Practices
Sandbox Lifecycle: Sandboxes are automatically created and destroyed for each execution. No manual cleanup is required.
Timeouts: Scripts have 60 seconds to complete. Ensure your candidate scripts finish within this window.
Artifact Retrieval: The script must write to the exact
output_file path provided. Use sys.argv[2] to get this path.Shell Escaping: Objectives containing quotes are automatically escaped. Pass them directly without manual escaping.