> ## Documentation Index
> Fetch the complete documentation index at: https://docs.novita.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to a Volume

`novita.volume.connect()` connects to an existing volume by its ID and returns a `Volume` instance you can mount into sandboxes. Use it to reuse a volume that was created earlier — in a different process, session, or service — without re-creating it.

## Connect to a volume

Pass the ID of an existing volume. The returned instance carries the volume ID, name, and auth token.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Novita } from 'novita-sandbox'

  const novita = new Novita()

  const volume = await novita.volume.connect('vol-123')

  console.log('Volume ID:', volume.volumeId)
  console.log('Name:', volume.name)
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox import Novita

  novita = Novita()

  volume = novita.volume.connect("vol-123")

  print("Volume ID:", volume.volume_id)
  print("Name:", volume.name)
  ```
</CodeGroup>

## Connect, then mount into a sandbox

A common flow is to connect to an existing volume, create a sandbox, mount the volume, read the previously persisted data, and clean up. The data written by an earlier sandbox is still there.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Novita } from 'novita-sandbox'

  const novita = new Novita()

  // 1. Connect to an existing volume by ID.
  const volume = await novita.volume.connect('vol-123')

  // 2. Create a sandbox.
  const sandbox = await novita.sandbox.create()

  try {
    // 3. Mount the volume at a path inside the sandbox.
    await sandbox.mountVolume(volume.name, '/mnt/data')

    // 4. Read data that was persisted to the volume earlier.
    const result = await sandbox.commands.run('cat /mnt/data/note.txt')
    console.log(result.stdout)
  } finally {
    // 5. Clean up the sandbox. The volume and its data persist.
    await sandbox.kill()
  }
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox import Novita

  novita = Novita()

  # 1. Connect to an existing volume by ID.
  volume = novita.volume.connect("vol-123")

  # 2. Create a sandbox.
  sandbox = novita.sandbox.create()

  try:
      # 3. Mount the volume at a path inside the sandbox.
      sandbox.mount_volume(volume.name, "/mnt/data")

      # 4. Read data that was persisted to the volume earlier.
      result = sandbox.commands.run("cat /mnt/data/note.txt")
      print(result.stdout)
  finally:
      # 5. Clean up the sandbox. The volume and its data persist.
      sandbox.kill()
  ```
</CodeGroup>

<Tip>
  `novita.volume.connect()` looks up an existing volume and does not create a new one. If the volume ID does not exist, the call raises a not-found error (`404`). To create a new volume, use `novita.volume.create()` instead.
</Tip>
