## FileSystem

```python
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__

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

Initializes a new FileSystem instance.

**Arguments**:

- `api_client` _FileSystemApi_ \- API client for Sandbox file system operations.
- `http_client` _httpx.Client_ \- Shared pooled client for upload/download.

#### FileSystem.create_folder

```python
@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**:

- `path` _str_ \- Path where the folder should be created. Relative paths are resolved based on the sandbox working directory.
- `mode` _str_ \- Folder permissions in octal format (e.g., "755" for rwxr-xr-x).
- `request_timeout` _float | None_ \- Optional client-side request timeout in seconds.

**Example**:

```python
# 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

```python
@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**:

- `path` _str_ \- Path to the file to delete.
- `recursive` _bool_ \- If the file is a directory, this must be true to delete it.
- `request_timeout` _float | None_ \- Optional client-side request timeout in seconds.

**Example**:

```python
# Delete a file

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

#### FileSystem.download_file

```python
@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_path` _str_ \- Path to the file in the Sandbox.
- `timeout` _int_ \- Timeout for the download operation in seconds.

**Returns**:

- `bytes` \- The file contents as a bytes object.

**Example**:

```python
# 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

```python
@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**:

- `source` _str_ \- Path to the source file or directory.
- `destination` _str_ \- Path to the destination.
- `request_timeout` _float | None_ \- Optional client-side request timeout in seconds.

**Example**:

```python
# 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

```python
@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**:

- `file` _bytes_ \- File contents as a bytes object.
- `remote_path` _str_ \- Path to the destination file.
- `timeout` _int_ \- Timeout for the upload operation in seconds.

**Example**:

```python
# Upload a text file

content = b"Hello, World!"

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

#### CancelEvent

```python
@runtime_checkable

class CancelEvent(Protocol)
```

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

#### FileUpload

```python
@dataclass
class FileUpload()
```

Represents a file to be uploaded to the Sandbox.

**Attributes**:

- `source` _bytes | str_ \- File contents as bytes or a local file path.
- `destination` _str_ \- Absolute destination path in the Sandbox.

#### DownloadProgress

```python
@dataclass
class DownloadProgress()
```

Progress information for a streaming download.

**Attributes**:

- `bytes_received` _int_ \- Cumulative bytes received so far.
- `total_bytes` _int | None_ \- Total bytes expected, if known.

#### UploadProgress

```python
@dataclass
class UploadProgress()
```

Progress information for a streaming upload.

**Attributes**:

- `bytes_sent` _int_ \- Cumulative bytes sent so far.
