Skip to main content
The Daytona Python SDK provides a simple interface for interacting with Daytona Sandboxes, enabling sandbox management, code execution, file operations, and more.

Installation

Quick Start

Configuration

Using Environment Variables

Set the following environment variables:
Then initialize the client:

Using Configuration Object

Sandbox Management

Creating Sandboxes

Basic Sandbox Creation

Customized Sandbox Creation

Listing Sandboxes

Getting a Sandbox

Sandbox Lifecycle

Setting Labels

Code Execution

Running Python Code

Executing Shell Commands

Code Interpreter (Stateful Execution)

File Operations

Uploading Files

Downloading Files

File System Operations

Git Operations

Cloning Repositories

Git Status and Branches

Committing Changes

Language Server Protocol

Starting an LSP Server

Code Intelligence

Stopping LSP Server

Async Support

The Python SDK provides full async support:

Error Handling

Complete Example

API Reference

Daytona Class

Methods

  • create(params=None) - Create a new sandbox
  • get(sandbox_id_or_name) - Get a sandbox by ID or name
  • list(labels=None, page=None, limit=None) - List sandboxes with pagination
  • delete(sandbox) - Delete a sandbox
  • start(sandbox) - Start a stopped sandbox
  • stop(sandbox) - Stop a running sandbox

Sandbox Class

Properties

  • fs - FileSystem operations interface
  • git - Git operations interface
  • process - Process execution interface
  • code_interpreter - Code interpreter interface
  • id - Sandbox ID
  • state - Current state
  • labels - Custom labels
  • env - Environment variables

Methods

  • set_labels(labels) - Set custom labels
  • get_preview_link(port) - Get port preview URL

Process Class

Methods

  • exec(command, cwd=None, timeout=None) - Execute a shell command
  • code_run(code, params=None) - Execute code directly

FileSystem Class

Methods

  • upload_file(content, path) - Upload a file
  • upload_files(files) - Upload multiple files
  • download_file(path) - Download a file
  • download_files(requests) - Download multiple files
  • list_files(path) - List files in a directory
  • create_folder(path, mode='755') - Create a folder
  • search_files(root, pattern) - Search for files
  • replace_in_files(files, old, new) - Replace content in files

Git Class

Methods

  • clone(url, path, branch=None, username=None, password=None) - Clone a repository
  • status(path) - Get repository status
  • branches(path) - List branches
  • add(path, files) - Add files to staging
  • commit(path, message, author, email) - Commit changes
  • push(path, username=None, password=None) - Push changes

Best Practices

Always Use Context Managers

Check Exit Codes

Use Type Hints

Next Steps

SDK Overview

Compare all available SDKs

API Reference

Complete API documentation

Examples

Browse Python examples on GitHub

TypeScript SDK

Learn about the TypeScript SDK