daytona-client 0.1.0

Rust client for Daytona - secure sandboxes for AI code execution
Documentation
# Daytona Client for Rust

[![Crates.io](https://img.shields.io/crates/v/daytona-client.svg)](https://crates.io/crates/daytona-client)
[![Documentation](https://docs.rs/daytona-client/badge.svg)](https://docs.rs/daytona-client)
[![License: MIT/Apache-2.0](https://img.shields.io/badge/License-MIT%2FApache--2.0-blue.svg)](https://github.com/krzysztofwos/daytona-client#license)
[![Build Status](https://github.com/krzysztofwos/daytona-client/workflows/Rust%20CI/badge.svg)](https://github.com/krzysztofwos/daytona-client/actions)

A client library for the [Daytona API](https://www.daytona.io), providing secure sandbox environments for code execution and development.

## Features

- **Complete API Coverage**: Full implementation of the Daytona REST API
- **Secure Sandboxes**: Create isolated environments for code execution
- **File Management**: Upload, download, and manage files in sandboxes
- **Process Execution**: Run commands and code in multiple languages
- **Git Integration**: Clone repos, commit, push, pull, and manage branches
- **Workspace Management**: Create and manage persistent development environments
- **Real-time Support**: WebSocket connections for live updates (coming soon)
- **Type Safety**: Strongly typed API with comprehensive error handling

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
daytona-client = "0.1"
```

## Quick Start

```rust
use daytona_client::{DaytonaClient, DaytonaConfig, Language};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create client from environment variables
    let client = DaytonaClient::from_env()?;

    // Or configure manually
    let config = DaytonaConfig::new("your-api-key")
        .with_base_url("https://app.daytona.io/api");
    let client = DaytonaClient::new(config)?;

    // Create a sandbox
    let sandbox = client.sandboxes()
        .create(Default::default())
        .await?;

    // Execute Python code
    let result = client.process()
        .execute_code(&sandbox.id, Language::Python, r#"
print("Hello from Daytona!")
result = 2 + 2
print(f"2 + 2 = {result}")
"#)
        .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)

## API Coverage

### Core Operations

- **Sandboxes**: Create, list, get, delete, start, stop
-**Workspaces**: Full workspace lifecycle management
-**Files**: Upload, download, delete, list, copy, move
-**Process**: Execute commands, run code, install packages
-**Git**: Clone, commit, push, pull, branch management

### Advanced Features

- **Organizations**: Member and role management
-**Backups**: Create and restore workspace backups
-**Port Forwarding**: Create public URLs for services
- 🚧 **WebSockets**: Real-time terminal and logs (coming soon)
- 🚧 **LSP**: Language Server Protocol support (coming soon)

## Examples

### File Operations

```rust
// Upload a file
client.files()
    .upload_text(&sandbox.id, "/app/main.py", "print('Hello')")
    .await?;

// Download a file
let content = client.files()
    .download_text(&sandbox.id, "/app/main.py")
    .await?;

// List files
let files = client.files()
    .list(&sandbox.id, "/app")
    .await?;
```

### Git Operations

```rust
use daytona_client::GitCloneRequest;

// Clone a repository
client.git()
    .clone(&sandbox.id, GitCloneRequest {
        url: "https://github.com/user/repo.git".to_string(),
        path: "/workspace".to_string(),
        branch: Some("main".to_string()),
        ..Default::default()
    })
    .await?;

// Get status
let status = client.git()
    .status(&sandbox.id, "/workspace")
    .await?;

// Commit changes
client.git()
    .commit(&sandbox.id, "/workspace", GitCommitRequest {
        message: "Initial commit".to_string(),
        ..Default::default()
    })
    .await?;
```

### Workspace Management

```rust
use daytona_client::CreateWorkspaceParams;

// Create a workspace
let workspace = client.workspaces()
    .create(CreateWorkspaceParams {
        name: "my-project".to_string(),
        description: Some("Development environment".to_string()),
        ..Default::default()
    })
    .await?;

// Wait for it to start
let workspace = client.workspaces()
    .wait_for_state(&workspace.id, WorkspaceState::Started, 60)
    .await?;

// Create a port preview
let preview = client.workspaces()
    .create_port_preview(&workspace.id, 3000, true)
    .await?;

println!("Preview URL: {}", preview.url);
```

### Session-based Execution

```rust
// Create a stateful session for multiple executions
let session_id = "my-session";

// First execution — set a variable
client.process()
    .execute_code_with_session(
        &sandbox.id,
        Language::Python,
        "x = 42",
        session_id
    )
    .await?;

// Second execution — use the variable
let result = client.process()
    .execute_code_with_session(
        &sandbox.id,
        Language::Python,
        "print(f'x = {x}')",
        session_id
    )
    .await?;
```

## 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),
}
```

## 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).