---
title: "Manage drives and defaults"
description: "Create drives, choose where client calls run, and give a sandbox one drive."
canonical_url: "https://docs.flashdrive.space/sdk/drives-and-defaults"
---
# Manage drives and defaults

> Create drives, choose where client calls run, and give a sandbox one drive.

These examples use the latest stable release of the Python SDK.

Each workspace has one or more drives, and one of them is the workspace default. `client.drives` creates and lists drives and changes the default; `client.sandbox_tokens` gives a cloud sandbox or job access to one drive. To create drives or change the default, use an API key with **Read / Write** permission.

## Create a drive

```python
from flashdrive import Flashdrive

with Flashdrive() as client:
    drive = client.drives.create("Research", idempotency_key="create-research-1")
    print(drive.id, drive.status)
```

`drives.create(name, *, idempotency_key=None, timeout=30)` returns a `Drive`. Names are trimmed and must have 1 to 120 characters. Reuse the same `idempotency_key` and name to retry a creation whose reply was lost.

A new drive can still be preparing when `create()` returns. Read `client.drives.get(drive.id).status` until it is `ready`; the other statuses are `provisioning` and `failed`. Creating a drive does not change the workspace default.

## List and read drives

<table>
<thead>
  <tr>
    <th>
      Call
    </th>
    
    <th>
      Result
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        drives.list()
      </code>
    </td>
    
    <td>
      A list of <code>
        Drive
      </code>
      
       objects.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        drives.list(deleted=True)
      </code>
    </td>
    
    <td>
      A list of <code>
        DeletedDrive
      </code>
      
       objects, with <code>
        id
      </code>
      
      , <code>
        name
      </code>
      
      , <code>
        version
      </code>
      
      , <code>
        deleted_at
      </code>
      
       and <code>
        recoverable_until
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        drives.get(drive_id)
      </code>
    </td>
    
    <td>
      A <code>
        Drive
      </code>
      
       with its current <code>
        status
      </code>
      
       and <code>
        document_count
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        drives.usage(drive_id=None)
      </code>
    </td>
    
    <td>
      A <code>
        DriveUsage
      </code>
      
       with <code>
        document_count
      </code>
      
      , <code>
        source_bytes
      </code>
      
      , <code>
        deleted_document_count
      </code>
      
      , <code>
        deleted_source_bytes
      </code>
      
       and <code>
        stored_bytes
      </code>
      
      . Default: the client's drive.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        drives.get_default()
      </code>
    </td>
    
    <td>
      A <code>
        DefaultDrive
      </code>
      
       with <code>
        default_drive_id
      </code>
      
      , <code>
        version
      </code>
      
       and <code>
        etag
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        drives.set_default(drive_id)
      </code>
    </td>
    
    <td>
      The new <code>
        DefaultDrive
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

A `Drive` has `id`, `name`, `version`, `status`, `document_count`, `etag` and `full_text`. Unknown status values arrive as plain strings, so include a fallback when you match on them. Every response object keeps the service's full JSON in `raw`.

## Choose where calls run

A call's `drive_id` comes first, then the `drive_id` you gave the client, then the workspace default:

```python
with Flashdrive(drive_id="DRIVE_UUID") as client:
    client.upload("notes.md")                            # DRIVE_UUID
    client.upload("notes.md", drive_id="OTHER_UUID")     # OTHER_UUID
```

The default is read once per call and stays fixed through that call's retries and polling. An explicit drive that does not exist raises an error; it never falls back to the default.

The workspace default is shared with everyone in the workspace, so `set_default()` changes where their calls go too:

```python
with Flashdrive() as client:
    client.drives.set_default("DRIVE_UUID")
    print(client.drives.get_default().default_drive_id)
```

## Grep is on for every drive

Keyword and pattern search is on for every drive, including each new one, and there is no setting to turn it off. A `Drive`'s `full_text` attribute shows it.

If `files.grep` raises a `ConflictError` with code `full_text_search_off`, search is unavailable for that drive: contact [support](mailto:support@evokoa.com) with the error's `request_id`. Listing, globbing, reading and editing files still work. See [find, read and edit files](https://docs.flashdrive.space/sdk/files).

## Delete a drive

```python
with Flashdrive() as client:
    client.drives.delete("DRIVE_UUID", idempotency_key="delete-old-drive-1")
```

`drives.delete(drive_id)` reads the drive's current version and deletes it only if nothing changed in between. It returns `None`. The service refuses:

<table>
<thead>
  <tr>
    <th>
      Code
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        default_drive_in_use
      </code>
    </td>
    
    <td>
      The drive is the workspace default. Choose another default first.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        drive_not_empty
      </code>
    </td>
    
    <td>
      The drive still holds files or folders, or has work in progress. Remove them first.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stale_version
      </code>
    </td>
    
    <td>
      The drive changed since it was read. Read it again before retrying.
    </td>
  </tr>
</tbody>
</table>

## Restore a deleted drive

```python
with Flashdrive() as client:
    for gone in client.drives.list(deleted=True):
        print(gone.id, gone.name, gone.recoverable_until)
    record = client.drives.deletion("DRIVE_UUID")
    drive = client.drives.restore("DRIVE_UUID", idempotency_key="restore-old-drive-1")
```

A deleted drive can be restored until its `recoverable_until`. `drives.deletion(drive_id)` reads the deletion record without restoring anything, and `drives.restore(drive_id)` brings the drive back and returns it as a `Drive`.

## Read a drive's usage

`drives.usage()` reports how many files and bytes a drive holds, live and in the trash. A deleted file stays in the trash for one hour; until then it counts in the `deleted_` fields and in `stored_bytes`, which is what counts towards the drive's size limit. A drive without usage reporting answers `not_supported_on_this_drive`.

## Follow changes

`client.drives.changes()` lists what changed in a drive since a cursor. See [follow changes](https://docs.flashdrive.space/sdk/files) for the full workflow.

## Give a sandbox one drive

`client.sandbox_tokens` makes short-lived tokens for cloud sandboxes, containers and GPU jobs: one drive, optionally one folder and its subfolders, `read` or `read_write`, for 5 minutes to 12 hours (300 to 43,200 seconds, default 3,600).

```python
with Flashdrive() as client:
    made = client.sandbox_tokens.create(access="read", folder_id="FOLDER_UUID",
                                        ttl_seconds=3600, name="render-job")
    secret = made["token"]          # shown once: hand it straight to the sandbox's secret store
    client.sandbox_tokens.extend(made["id"], ttl_seconds=7200)
    live = client.sandbox_tokens.list(state="live")
    client.sandbox_tokens.revoke(made["id"])
```

<table>
<thead>
  <tr>
    <th>
      Call
    </th>
    
    <th>
      Result
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        sandbox_tokens.create(access=, drive_id=None, folder_id=None, ttl_seconds=None, name=None)
      </code>
    </td>
    
    <td>
      A dictionary with <code>
        id
      </code>
      
      , <code>
        name
      </code>
      
      , <code>
        display_prefix
      </code>
      
      , <code>
        workspace_id
      </code>
      
      , <code>
        drive_id
      </code>
      
      , <code>
        folder_id
      </code>
      
      , <code>
        access
      </code>
      
      , <code>
        minted_by
      </code>
      
      , <code>
        created_at
      </code>
      
      , <code>
        expires_at
      </code>
      
      , <code>
        revoked_at
      </code>
      
      , <code>
        state
      </code>
      
       and, once, <code>
        token
      </code>
      
      . It is never retried, so a lost reply does not make a second token. <code>
        name
      </code>
      
       is up to 120 characters.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sandbox_tokens.list(drive_id=None, state="live", limit=None, cursor=None)
      </code>
    </td>
    
    <td>
      A page (<code>
        data
      </code>
      
      , <code>
        next_cursor
      </code>
      
      ) of tokens without their secrets, newest first. <code>
        state="recent"
      </code>
      
       adds tokens that ended in the last 30 days. Workspace admins see every token, others the ones they made.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sandbox_tokens.extend(token_id, ttl_seconds=None)
      </code>
    </td>
    
    <td>
      The token, with its expiry moved to now plus <code>
        ttl_seconds
      </code>
      
       (default one hour). The token itself does not change, so work in flight keeps going.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sandbox_tokens.revoke(token_id)
      </code>
    </td>
    
    <td>
      The token, revoked; new requests are refused within 60 seconds. Repeating is harmless.
    </td>
  </tr>
</tbody>
</table>

Never print or log the token. Inside the sandbox, the SDK reads it from `FLASHDRIVE_API_KEY`, ideally injected by the sandbox's network proxy rather than placed on a command line. With a folder token, pass `folder_id` to `client.upload(...)`. A sandbox token cannot make, list, extend or revoke tokens, and cannot make file links, so `files.link`, `files.read_bytes` and `files.download` are not available to it. See [give a sandbox one drive](https://docs.flashdrive.space/cli/sandboxes) for what a token can do and how to pass it to common sandboxes.


## Sitemap

See the full [sitemap](https://docs.flashdrive.space/sitemap.md) for all pages.
