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:
api_clientFileSystemApi - API client for Sandbox file system operations.http_clienthttpx.Client - Shared pooled client for upload/download.
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:
pathstr - Path where the folder should be created. Relative paths are resolved based on the sandbox working directory.modestr - Folder permissions in octal format (e.g., "755" for rwxr-xr-x).request_timeoutfloat | None - Optional client-side request timeout in seconds.
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:
pathstr - Path to the file to delete.recursivebool - If the file is a directory, this must be true to delete it.request_timeoutfloat | None - Optional client-side request timeout in seconds.
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:
remote_pathstr - Path to the file in the Sandbox.timeoutint - Timeout for the download operation in seconds.
Returns:
bytes- The file contents as a bytes object.
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:
sourcestr - Path to the source file or directory.destinationstr - Path to the destination.request_timeoutfloat | None - Optional client-side request timeout in seconds.
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:
filebytes - File contents as a bytes object.remote_pathstr - Path to the destination file.timeoutint - Timeout for the upload operation in seconds.
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:
sourcebytes | str - File contents as bytes or a local file path.destinationstr - Absolute destination path in the Sandbox.
DownloadProgress
@dataclass
class DownloadProgress()
Progress information for a streaming download.
Attributes:
bytes_receivedint - Cumulative bytes received so far.total_bytesint | None - Total bytes expected, if known.
UploadProgress
@dataclass
class UploadProgress()
Progress information for a streaming upload.
Attributes:
bytes_sentint - Cumulative bytes sent so far.