> ## Documentation Index
> Fetch the complete documentation index at: https://vastai-80aa3a82-ltxv2-serverless.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Instances FAQ

> Questions about creating and managing instances

<script
  type="application/ld+json"
  dangerouslySetInnerHTML={{
__html: JSON.stringify({
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
  {
    "@type": "Question",
    "name": "What does Lifetime mean on my instance?",
    "acceptedAnswer": {
      "@type": "Answer",
      "text": "Every instance offer has a Max Duration. When you accept an offer and create an instance, this becomes the instance lifetime and begins counting down. When the lifetime expires, the instance is automatically stopped. The host can extend the contract (adding more lifetime), but this is at their discretion. Always assume your instance will be lost once the lifetime expires and copy out any important data before then."
    }
  },
  {
    "@type": "Question",
    "name": "How can I restart programs when my instance restarts?",
    "acceptedAnswer": {
      "@type": "Answer",
      "text": "For custom command instances: Your command runs automatically on startup. For SSH instances: Place startup commands in /root/onstart.sh. This script runs automatically on container startup."
    }
  },
  {
    "@type": "Question",
    "name": "How do I set environment variables?",
    "acceptedAnswer": {
      "@type": "Answer",
      "text": "Use the -e Docker syntax in the docker create/run options: -e TZ=UTC -e TASKID=TEST. To make variables visible in SSH/Jupyter sessions, export them to /etc/environment. You can also set global environment variables in your account Settings page."
    }
  },
  {
    "@type": "Question",
    "name": "How do I get the instance ID from within the container?",
    "acceptedAnswer": {
      "@type": "Answer",
      "text": "Use the VAST_CONTAINERLABEL environment variable: echo $VAST_CONTAINERLABEL. This will output something like C.38250."
    }
  },
  {
    "@type": "Question",
    "name": "How can I find OPEN_BUTTON_TOKEN?",
    "acceptedAnswer": {
      "@type": "Answer",
      "text": "SSH into your instance or open Jupyter terminal and run: echo $OPEN_BUTTON_TOKEN. Alternatively, check the instance logs."
    }
  },
  {
    "@type": "Question",
    "name": "How do I stop an instance from within itself?",
    "acceptedAnswer": {
      "@type": "Answer",
      "text": "A special instance API key is pre-installed. Install the CLI with pip install vastai, then use vastai stop instance $CONTAINER_ID to stop the instance. If $CONTAINER_ID is not defined, check your environment variables with env."
    }
  },
  {
    "@type": "Question",
    "name": "Can I run Docker within my instance?",
    "acceptedAnswer": {
      "@type": "Answer",
      "text": "No, Vast.ai does not support Docker-in-Docker due to security constraints. Each Docker container must run on a separate instance."
    }
  },
  {
    "@type": "Question",
    "name": "Can I change disk size after creating an instance?",
    "acceptedAnswer": {
      "@type": "Answer",
      "text": "No. Disk size is permanent and cannot be changed after instance creation. If you run out of space, you'll need to create a new instance with a larger disk. Always allocate more space than you think you need to avoid interruptions."
    }
  },
  {
    "@type": "Question",
    "name": "What happens to my data when an instance stops?",
    "acceptedAnswer": {
      "@type": "Answer",
      "text": "Stopped instances: Data persists, storage charges continue. Destroyed instances: All data is permanently deleted. Lifetime expired: Instance stops, data remains until destroyed. Always backup important data to external storage."
    }
  }
]
})
}}
/>

## Instance Lifecycle

### What does "Lifetime" mean on my instance?

Every instance offer has a **Max Duration**. When you accept an offer and create an instance, this becomes the instance lifetime and begins counting down. When the lifetime expires, the instance is automatically stopped.

The host can extend the contract (adding more lifetime), but this is at their discretion. **Important:** Always assume your instance will be lost once the lifetime expires and copy out any important data before then.

### How can I restart programs when my instance restarts?

**For custom command instances:** Your command runs automatically on startup.

**For SSH instances:** Place startup commands in `/root/onstart.sh`. This script runs automatically on container startup.

```bash theme={null}
# Example /root/onstart.sh
#!/bin/bash
cd /workspace
python train.py --resume
```

## Environment Configuration

### How do I set environment variables?

Use the `-e` Docker syntax in the docker create/run options:

```bash theme={null}
-e TZ=UTC -e TASKID="TEST"
```

To make variables visible in SSH/Jupyter sessions, export them to `/etc/environment`:

```bash theme={null}
# Export variables with underscores
env | grep _ >> /etc/environment

# Or export all variables
env >> /etc/environment
```

You can also set global environment variables in your account Settings page.

### How do I get the instance ID from within the container?

Use the `VAST_CONTAINERLABEL` environment variable:

```bash theme={null}
echo $VAST_CONTAINERLABEL
# Output: C.38250
```

### How can I find OPEN\_BUTTON\_TOKEN?

SSH into your instance or open Jupyter terminal and run:

```bash theme={null}
echo $OPEN_BUTTON_TOKEN
```

Alternatively, check the instance logs.

## Controlling Instances

### How do I stop an instance from within itself?

A special instance API key is pre-installed. Install the CLI and use it:

```bash theme={null}
# Install CLI
pip install vastai

# Test with start (no-op if already running)
vastai start instance $CONTAINER_ID

# Stop the instance
vastai stop instance $CONTAINER_ID
```

If `$CONTAINER_ID` is not defined, check your environment variables with `env`.

### Can I run Docker within my instance?

No, Vast.ai does not support Docker-in-Docker due to security constraints. Each Docker container must run on a separate instance.

## Data and Storage

### Can I change disk size after creating an instance?

**No.** Disk size is permanent and cannot be changed after instance creation. If you run out of space, you'll need to create a new instance with a larger disk.

**Tip:** Always allocate more space than you think you need to avoid interruptions.

### What happens to my data when an instance stops?

* **Stopped instances:** Data persists, storage charges continue
* **Destroyed instances:** All data is permanently deleted
* **Lifetime expired:** Instance stops, data remains until destroyed

Always backup important data to external storage.
