> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments/startup-scripts.md).

# Startup Scripts

Run a Bash script as root on a Dedicated Deployment before inference starts.

A startup script installs packages or downloads data on a Dedicated Deployment before inference starts. Use one when your models or Workflows need a Python package, a system tool, or a data file that the inference container does not include.

{% hint style="info" %}
Startup scripts are off by default. [Contact sales](https://roboflow.com/sales) to turn them on for your workspace.
{% endhint %}

## About

The script is Bash. It runs as root on every container start, including new replicas and restarts. Inference then runs as a non-root user.

Your script must finish within 10 minutes. An error or a timeout stops inference from starting, and the container tries again. Start the script with `set -e` so it stops on a failed command, and write it so that running it again is safe.

Nothing is prepared for you. Install any tool you need, such as pip. Files under `/userdata` can be lost when the container is replaced or the deployment is paused, so download them again on each start. Environment variables that your script exports are not passed to inference.

`INFERENCE_UID` and `INFERENCE_GID` hold the numeric user and group IDs that inference runs as. Use them to give inference access to the files your script creates.

```bash
#!/bin/bash
set -e
apt-get update
apt-get install -y --no-install-recommends curl jq python3-pip
python3 -m pip install 'humanize==4.12.3'
mkdir -p /userdata/custom-data
curl --fail --location 'https://YOUR_HOST/data.json' --output /userdata/custom-data/data.json
chown -R "$INFERENCE_UID:$INFERENCE_GID" /userdata/custom-data
```

A script can be 64 KiB at most and cannot contain NUL characters.

## Web App

Enter the script in the "Startup Script (Bash)" field. The field is in the "Create a Dedicated Deployment" dialog and in the settings of an existing deployment. Select "Clear Script" to remove it.

Saving a script does not restart running containers. The change applies the next time a container starts. To apply it right away, pause the deployment and resume it.

To read the output of your script, select "View Logs" on the deployment, then select "Refresh" for new entries. The dialog shows up to 300 entries from the last hour across all replicas, and entries can take a short time to appear. Anything your script prints appears there, so do not print credentials.

## Failures

A deployment pauses after every replica fails its startup script 5 times in a row. A success resets the count for that replica. The status then reads "Paused: Startup Script Failures". Fix or clear the script, then select "Resume". Incoming requests do not resume the deployment.

The person who created the deployment and the workspace owners get one email when the script starts failing. Roboflow sends no further email for the same failure until the deployment recovers or you change the script.

## HTTP API

Dedicated Deployment endpoints are hosted at `https://roboflow.cloud`. See [Dedicated Deployments](/deployment/roboflow-cloud/dedicated-deployments.md#http-api) for the rest of them.

[Create a Deployment](/deployment/roboflow-cloud/dedicated-deployments.md#create-a-deployment) accepts an optional `startup_script` string in its body. To change the script on a deployment that already exists, post to `/update_startup_script`.

<mark style="color:green;">`POST`</mark> `/update_startup_script`

<table data-search="false"><thead><tr><th width="200">Name</th><th width="120">Type</th><th>Description</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td><code>api_key</code></td><td>string</td><td>Workspace API key.</td><td>true</td></tr><tr><td><code>deployment_name</code></td><td>string</td><td>Deployment to update.</td><td>true</td></tr><tr><td><code>startup_script</code></td><td>string</td><td>Script contents. Send an empty string to remove the script.</td><td>true</td></tr></tbody></table>

```bash
curl -X POST "https://roboflow.cloud/update_startup_script" \
  -H "Content-Type: application/json" \
  -d '{
    "api_key": "'$ROBOFLOW_API_KEY'",
    "deployment_name": "my-deployment",
    "startup_script": "#!/bin/bash\nset -e\napt-get update\n"
  }'
```
