# Download Data
<subtitle>Download file data from the sandbox to local storage or share via presigned URL.</subtitle>

You can use the `files.read()` method to download data from the sandbox.

## Environment Setup

Before using the SDK, please ensure that the `AGENTBOX_API_KEY` environment variable is configured.

>
> You can obtain your API key from the [Console API Keys page](https://console.ucloud.cn/modelverse/experience/api-keys).

```bash
export AGENTBOX_API_KEY=your_api_key
```

```python
from ucloud_sandbox import Sandbox

sandbox = Sandbox.create()

# Read file from sandbox
content = sandbox.files.read('/path/in/sandbox')
# Write file to local file system
with open('/local/path', 'w') as file:
    file.write(content)
```

## Download Using Presigned URL

Sometimes, you may want to allow users in unauthorized environments (such as browsers) to download files from the sandbox. For this use case, you can use presigned URLs to allow users to securely download files.

All you need to do is create a sandbox with the `secure=True` option. A download URL will then be generated with a signature that only allows authorized users to access the file. You can optionally set an expiration time for the URL, making it valid only for a limited time.

```python
from ucloud_sandbox import Sandbox

# Start secure sandbox (by default, all operations must be authorized)
sandbox = Sandbox.create(timeout=12_000, secure=True)

# Create a presigned download URL with a 10-second expiration time
# Users can simply access this URL to download the file, which also works in browsers.
signed_url = sandbox.download_url(path="demo.txt", user="user", use_signature_expiration=10_000)
```
