Daytona Client for Rust
A Rust client library for the Daytona API, providing secure sandbox environments for code execution and development.
Status
Version 0.5.0 — Complete volume and snapshot management with organization support.
Current Features
- ✅ Sandboxes: Create, list, get, delete, start, stop, archive operations
- ✅ Workspaces: Full workspace lifecycle management
- ✅ Volume Management: Create, attach, detach, delete with async state handling
- ✅ Snapshot Management: Create, list, activate, deactivate, remove snapshots
- ✅ Organization Management: Manage organizations, members, invitations, API keys
- ✅ Process Execution: Execute commands with sessions and timeout support
- ✅ Session Management: Create and manage persistent command sessions
- ✅ File Operations: Upload, download, list, move, copy, delete files and directories
- ✅ Git Operations: Clone, commit, push, pull, branch management, status, history
- ✅ LSP Integration: Language Server Protocol support for code intelligence features
- ✅ Preview URLs: Generate public preview URLs for sandbox ports
- ✅ Type Safety: Strongly typed models with comprehensive error handling
Known API Issues
These are server-side API bugs, not client library issues:
- ⚠️ Process Execution:
cwdparameter exists but doesn't work correctly - ⚠️ Sandbox Creation: API incorrectly rejects resource specifications (cpu, memory, disk) claiming a snapshot is used when it isn't
All other features are fully functional and tested.
Installation
Add this to your Cargo.toml:
[]
= "0.5"
Quick Start
use ;
async
Environment Variables
The client can be configured using environment variables:
DAYTONA_API_KEY— Daytona API key (required)DAYTONA_BASE_URL— API base URL (default:https://app.daytona.io/api)DAYTONA_ORGANIZATION_ID— Organization ID for multi-org accounts (optional)
Implementation Status
API Endpoints
- ✅ Sandbox Management: Create, list, get, delete, start, stop, archive
- ✅ Workspace Management: Create, list, get, delete, start, stop, archive
- ✅ Volume Management: Create, list, get, delete, attach, detach with state monitoring
- ✅ Snapshot Management: Create, list, get, activate, deactivate, remove, build logs
- ✅ Organization Management: Create, list, update, delete orgs; manage members and API keys
- ✅ Process Execution: Execute commands, session management
- ✅ File Operations: Full file and directory management via upload/download/list/move/copy/delete
- ✅ Git Operations: Clone, commit, push, pull, branch, status, history, stage
- ✅ LSP Integration: Code completions, hover, go-to-definition, diagnostics, formatting
- ✅ Preview URLs: Generate public URLs for sandbox ports
- ❌ WebSocket Connections: Not yet implemented
- ❌ Docker Registry: Not yet implemented
- ❌ Object Storage: Not yet implemented
- ❌ Computer Use/UI Automation: Not yet implemented
Testing Status
70+ integration tests covering all implemented features:
- ✅ Sandbox Integration Tests: Full lifecycle and operation testing
- ✅ Workspace Integration Tests: Complete workspace management testing
- ✅ Volume Integration Tests: Volume lifecycle with async state handling
- ✅ Snapshot Integration Tests: Snapshot creation, activation, and management
- ✅ Organization Integration Tests: Organization and member management
- ✅ Process Integration Tests: Command execution and session management
- ✅ File Integration Tests: Upload, download, and file management operations
- ✅ Git Integration Tests: Repository operations and branch management
- ✅ LSP Integration Tests: Language server operations and code intelligence
- ✅ Preview URL Integration Tests: Public URL generation for sandbox services
Examples
Basic Sandbox Operations
use ;
async
File Operations
// Upload a file
client.files
.upload
.await?;
// Download a file
let content = client.files
.download
.await?;
// List directory contents
let entries = client.files
.list
.await?;
Git Operations
use GitCloneRequest;
// Clone a repository
let clone_request = GitCloneRequest ;
client.git
.clone
.await?;
// Check status
let status = client.git
.status
.await?;
println!;
Session Management
use SessionExecuteRequest;
// Create a persistent session
let session_id = "my-session";
client.process
.create_session
.await?;
// Execute commands in the session
let response = client.process
.execute_session_command
.await?;
println!;
Workspace Management
use ;
// Create a workspace
let workspace = client.workspaces
.create
.await?;
// Wait for it to start
let workspace = client.workspaces
.wait_for_state
.await?;
println!;
Language Server Protocol (LSP)
use ;
// Initialize LSP for a sandbox
let lsp = sandbox.lsp;
await lsp.start.await?;
// Get code completions
let completions = lsp.get_completions.await?;
// Get hover information
let hover = lsp.get_hover.await?;
// Get diagnostics
let diagnostics = lsp.get_diagnostics.await?;
Preview URLs
// Get a public preview URL for a web application running on port 3000
let preview_url = client.sandboxes
.get_preview_url
.await?;
println!;
Volume Management
use VolumeState;
// Create a volume
let volume = client.volumes
.create
.await?;
// Wait for volume to be ready
let volume = client.volumes
.wait_for_state
.await?;
// Attach volume to a sandbox
let sandbox = client.sandboxes
.create
.await?;
// List all volumes
let volumes = client.volumes.list.await?;
println!;
// Delete volume
client.volumes.delete.await?;
Snapshot Management
use ;
// Create a snapshot
let snapshot_request = CreateSnapshotRequest ;
let snapshot = client.snapshots
.create
.await?;
// List snapshots with pagination
let paginated = client.snapshots
.list
.await?;
println!;
// Activate a snapshot
client.snapshots.activate.await?;
// Get build logs for a snapshot
let logs = client.snapshots
.get_build_logs
.await?;
// Remove snapshot
client.snapshots.remove.await?;
Organization Management
use ;
// Create an organization
let org = client.organizations
.create
.await?;
// Invite a member
client.organizations
.invite_member
.await?;
// Update member role
client.organizations
.update_member
.await?;
// Create API key for organization
let api_key = client.organizations
.create_api_key
.await?;
println!;
Error Handling
The client provides comprehensive error types:
use ;
match client.sandboxes.create.await
Testing
Prerequisites
Set the Daytona API key:
Running Tests
Tests that create sandboxes are automatically run sequentially using the serial_test crate to avoid exceeding Daytona's 30GB quota limit:
# Run all tests (resource-intensive tests run sequentially)
# Run specific test suites
Cleanup Utilities
If tests fail or are interrupted, sandboxes may not be cleaned up. Use the provided utilities:
# Check current resource usage
# Clean up test sandboxes only (safer)
# Force cleanup all resources (interactive)
Contributing
Contributions are welcome. Please feel free to submit a Pull Request.
License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at the option of the user.
Acknowledgments
This client is not officially affiliated with Daytona. For official SDKs, visit Daytona's documentation.