FileSystem | Daytona

FileSystem

class FileSystem()

Provides file system operations within a Sandbox.

This class implements a high-level interface to file system operations that can be performed within a Daytona Sandbox.

FileSystem.init

def __init__(api_client: FileSystemApi, http_client: httpx.Client)

Initializes a new FileSystem instance.

Arguments:

FileSystem.create_folder

@intercept_errors(message_prefix="Failed to create folder: ")
@with_instrumentation()

def create_folder(path: str,

mode: str,

request_timeout: float | None = None) -> None

Creates a new directory in the Sandbox at the specified path with the given permissions.

Arguments:

Example:

# Create a directory with standard permissions

sandbox.fs.create_folder("workspace/data", "755")

# Create a private directory

sandbox.fs.create_folder("workspace/secrets", "700")

FileSystem.delete_file

@intercept_errors(message_prefix="Failed to delete file: ")
@with_instrumentation()

def delete_file(path: str,

recursive: bool = False,

request_timeout: float | None = None) -> None

Deletes a file from the Sandbox.

Arguments:

Example:

# Delete a file

sandbox.fs.delete_file("workspace/data/old_file.txt")

FileSystem.download_file

@overload
def download_file(remote_path: str, timeout: int = 30 * 60) -> bytes

Downloads a file from the Sandbox. Returns the file contents as a bytes object.

Arguments:

Returns:

Example:

# Download and save a file locally

content = sandbox.fs.download_file("workspace/data/file.txt")

with open("local_copy.txt", "wb") as f:

f.write(content)

# Download and process text content

content = sandbox.fs.download_file("workspace/data/config.json")

config = json.loads(content.decode('utf-8'))

FileSystem.move_files

@intercept_errors(message_prefix="Failed to move files: ")
@with_instrumentation()

def move_files(source: str,

destination: str,

request_timeout: float | None = None) -> None

Moves or renames a file or directory. The parent directory of the destination must exist.

Arguments:

Example:

# Rename a file

sandbox.fs.move_files(

"workspace/data/old_name.txt",

"workspace/data/new_name.txt"
)

# Move a file to a different directory

sandbox.fs.move_files(

"workspace/data/file.txt",

"workspace/archive/file.txt"
)

# Move a directory

sandbox.fs.move_files(

"workspace/old_dir",

"workspace/new_dir"
)

FileSystem.upload_file

@overload
def upload_file(file: bytes, remote_path: str, timeout: int = 30 * 60) -> None

Uploads a file to the specified path in the Sandbox.

Arguments:

Example:

# Upload a text file

content = b"Hello, World!"

sandbox.fs.upload_file(content, "tmp/hello.txt")

CancelEvent

@runtime_checkable

class CancelEvent(Protocol)

Duck-typed cancellation token. Compatible with threading.Event and asyncio.Event.

FileUpload

@dataclass
class FileUpload()

Represents a file to be uploaded to the Sandbox.

Attributes:

DownloadProgress

@dataclass
class DownloadProgress()

Progress information for a streaming download.

Attributes:

UploadProgress

@dataclass
class UploadProgress()

Progress information for a streaming upload.

Attributes: