<p align="center" style="font-size: 48px; font-weight: bold;">Work in Progress</p>
# Daytona Client for Rust
[](https://crates.io/crates/daytona-client)
[](https://docs.rs/daytona-client)
[](https://github.com/krzysztofwos/daytona-client#license)
[](https://github.com/krzysztofwos/daytona-client/actions)
A Rust client library for the [Daytona API](https://www.daytona.io), providing secure sandbox environments for code execution and development.
## Status
**This project is under active development and not yet ready for production use.**
### Current Features
- ✅ **Sandboxes**: Create, list, get, delete, start, stop, archive operations
- ✅ **Workspaces**: Full workspace lifecycle management
- ✅ **Basic Process Execution**: Execute commands in sandboxes
- ✅ **Session Management**: Create and manage persistent command sessions
- ✅ **File Operations**: Basic upload via bulk-upload endpoint
- 🚧 **Git Operations**: Basic clone, status, commit functionality (partial)
- ✅ **Type Safety**: Strongly typed models with comprehensive error handling
### Known Issues & Limitations
- ⚠️ **File API**: Upload works but some endpoints have routing issues
- ⚠️ **Git API**: Limited functionality, some endpoints not fully implemented
- ⚠️ **Process Execution**: Environment variables and working directory support incomplete
- ⚠️ **Code Execution**: Language-specific execution helpers need refinement
- ❌ **WebSockets**: Real-time connections not yet implemented
- ❌ **LSP Support**: Language server protocol integration not implemented
## Installation
Add this to your `Cargo.toml`:
```toml
[dependencies]
daytona-client = "0.2"
```
## Quick Start
```rust
use daytona_client::{DaytonaClient, CreateSandboxParams};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client from environment variables
let client = DaytonaClient::from_env()?;
// Create a sandbox
let sandbox = client.sandboxes()
.create(CreateSandboxParams {
class: Some("small".to_string()),
..Default::default()
})
.await?;
// Execute a command
let result = client.process()
.execute_command(&sandbox.id, "echo 'Hello from Daytona!'")
.await?;
println!("Output: {}", result.result);
// Clean up
client.sandboxes().delete(&sandbox.id).await?;
Ok(())
}
```
## 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
- ✅ **Process Execution**: Execute commands, session management
- 🚧 **File Operations**: Basic upload via bulk-upload endpoint (some routing issues)
- 🚧 **Git Operations**: Basic clone, status, commit (limited functionality)
- ❌ **Organization Management**: Not yet implemented
- ❌ **Port Forwarding**: Not yet implemented
- ❌ **WebSocket Connections**: Not yet implemented
- ❌ **LSP Integration**: Not yet implemented
### Testing Status
- ✅ **Sandbox Integration Tests**: Comprehensive lifecycle testing
- ✅ **Workspace Integration Tests**: Full workflow testing
- ✅ **Process Integration Tests**: Command execution testing
- ✅ **Session Integration Tests**: Persistent session testing
- 🚧 **File Integration Tests**: Currently disabled due to API routing bugs
- 🚧 **Git Integration Tests**: Currently disabled due to API issues
## Examples
### Basic Sandbox Operations
```rust
use daytona_client::{DaytonaClient, CreateSandboxParams};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = DaytonaClient::from_env()?;
// Create a sandbox
let sandbox = client.sandboxes()
.create(CreateSandboxParams {
class: Some("small".to_string()),
..Default::default()
})
.await?;
println!("Created sandbox: {}", sandbox.id);
// Execute a command
let result = client.process()
.execute_command(&sandbox.id, "echo 'Hello from Daytona!'")
.await?;
println!("Output: {}", result.result);
// Clean up
client.sandboxes().delete(&sandbox.id).await?;
Ok(())
}
```
### File Upload
```rust
// Upload a file
client.files()
.upload(&sandbox.id, "/app/main.py", b"print('Hello World!')")
.await?;
```
### Session Management
```rust
use daytona_client::SessionExecuteRequest;
// Create a persistent session
let session_id = "my-session";
client.process()
.create_session(&sandbox.id, session_id)
.await?;
// Execute commands in the session
let response = client.process()
.execute_session_command(&sandbox.id, session_id, SessionExecuteRequest {
command: "python -c 'x = 42; print(f\"x = {x}\")'".to_string(),
run_async: Some(false),
})
.await?;
println!("Session output: {:?}", response.output);
```
### Workspace Management
```rust
use daytona_client::{CreateWorkspaceParams, WorkspaceState};
// Create a workspace
let workspace = client.workspaces()
.create(CreateWorkspaceParams {
name: "my-project".to_string(),
description: Some("Development environment".to_string()),
class: Some("small".to_string()),
..Default::default()
})
.await?;
// Wait for it to start
let workspace = client.workspaces()
.wait_for_state(&workspace.id, WorkspaceState::Started, 120)
.await?;
println!("Workspace {} is ready!", workspace.id);
```
## Error Handling
The client provides comprehensive error types:
```rust
use daytona_client::{DaytonaError, Result};
match client.sandboxes().create(params).await {
Ok(sandbox) => println!("Created: {}", sandbox.id),
Err(DaytonaError::QuotaExceeded(msg)) => {
eprintln!("Quota exceeded: {}", msg);
}
Err(DaytonaError::AuthenticationFailed(msg)) => {
eprintln!("Auth failed: {}", msg);
}
Err(e) => eprintln!("Error: {}", e),
}
```
## Testing
### Prerequisites
Set your Daytona API key:
```bash
export DAYTONA_API_KEY="your-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:
```bash
# Run all tests (resource-intensive tests run sequentially)
cargo test
# Run specific test suites
cargo test --test sandbox_integration
cargo test --test workspace_integration
cargo test --test process_integration
```
**Note:** File and Git integration tests are currently disabled due to an API routing bug.
### Cleanup Utilities
If tests fail or are interrupted, sandboxes may not be cleaned up. Use the provided utilities:
```bash
# Check current resource usage
cargo run --bin verify-cleanup
# Clean up test sandboxes only (safer)
cargo run --bin cleanup-test-sandboxes
# Force cleanup all resources (interactive)
cargo run --bin force-cleanup
```
## 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](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))
at the option of the licensee.
## Acknowledgments
This client is not officially affiliated with Daytona. For official SDKs, visit [Daytona's documentation](https://www.daytona.io/docs).