App SDK deployment
Learn how to deploy your App SDK app to your organization dashboard.
This guide shows how to deploy an App SDK app to your organization's Dashboard, enable auto-updates, undeploy the app, and set up deployment from a CI/CD pipeline.
Prerequisites
Before you deploy, make sure you have the following:
- Node.js 22.12 or later. The Sanity CLI exits with an error on older versions.
- An App SDK app with
app.organizationIdset insanity.cli.tsto the ID of the Sanity organization that owns the app. - A recent Sanity CLI for some options on this page:
@sanity/cli8.12.0 or later fordeploy --create, 8.13.0 or later to pass an app ID toundeploy, and 8.19.0 or later to create organization tokens withtokens create.
Deploy your app
To deploy your App SDK app, you use the same command as when deploying a studio: sanity deploy
npx sanity@latest deploypnpm dlx sanity@latest deployyarn dlx sanity@latest deploybunx sanity@latest deployTo deploy App SDK apps, you need the Administrator or Developer role in your organization, or an equivalent role. Organization-level robot tokens with the "Manage SDK Apps" permission (which grants deploy, read, and delete access to App SDK apps) can also be used to deploy App SDK apps. For more information, see Roles and permissions.
Deployment size limit
A single deployment is limited to 2 GB. The limit applies to the total size of the built files in the deployment, and deploys that exceed it are rejected with an error. The same limit applies to Studio deployments and App SDK app deployments.
Most deployments are a few megabytes, so typical projects stay well below this limit.
Enable auto-updates
To keep your App SDK app up to date without redeploying, enable auto-updates the same way you do for a studio. Set deployment.autoUpdates to true in your sanity.cli.ts file, alongside the appId saved during your first deploy:
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
app: {
organizationId: 'YOUR_ORGANIZATION_ID',
},
deployment: {
appId: 'YOUR_APP_ID',
autoUpdates: true,
},
})Replace YOUR_ORGANIZATION_ID with the ID of the Sanity organization that owns the app, and YOUR_APP_ID with the app ID the CLI prints after your first deploy.
With auto-updates enabled, your deployed app loads @sanity/sdk, @sanity/sdk-react, and sanity (if installed) at runtime. It picks up patch and minor releases without a rebuild.
Undeploy your app
To undeploy your App SDK app, you can use sanity undeploy from within your app’s directory.
npx sanity@latest undeploypnpm dlx sanity@latest undeployyarn dlx sanity@latest undeploybunx sanity@latest undeployTo find the deployment to remove, the CLI reads your app's ID from deployment.appId in your sanity.cli.ts file, which the CLI tells you to add after your first deploy. With @sanity/cli 8.13.0 or later, you can pass the ID as an argument instead: npx sanity@latest undeploy YOUR_APP_ID.
Deploy from a CI/CD pipeline
App SDK deployment requires an organization-level robot token with the Manage SDK Apps permission. This is different from Studio deployment, which uses project-level tokens. To create this token, you need the Developer or Administrator role in your organization.
To create a robot token:
- Go to Manage and select your organization.
- Select API > Tokens.
- Select Add API token, and then select the Manage SDK Apps permission. Select Save token.
- Copy the token and store it as a secret in your CI/CD environment (for example, as a GitHub Actions secret).
You can also create this token with the Sanity CLI in @sanity/cli 8.19.0 or later. From your app's directory, run npx sanity@latest tokens create "CI deploy token" --grant sdk-apps. The CLI shows the token only once, so copy it right away.
Set the SANITY_AUTH_TOKEN environment variable to your robot token. The Sanity CLI reads this variable automatically when deploying.
In a CI/CD pipeline, the CLI can't prompt for input. The first deploy creates the app, so pass the --title flag to name it: npx sanity deploy --title "My App". If your organization already has other apps, also pass --create (requires @sanity/cli 8.12.0 or later). After the first deploy, add the app ID to your configuration as deployment.appId and commit it. Later deploys update that app without prompting. At that point, remove --create, because the CLI rejects it when an app ID is configured.
GitHub Actions example
name: Deploy App SDK
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npx sanity deploy --title 'My App'
env:
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_DEPLOY_TOKEN }}On its first run, this workflow creates the app. If your organization already has other apps, add --create to that first run. When the run finishes, the CLI output shows the new app ID. Add it to sanity.cli.ts as deployment.appId and commit the change before the next push. Without it, the next run fails, because the organization now has an app and the CLI can't ask which one to deploy to.
Environment variables
The following environment variables are relevant for App SDK deployment:
SANITY_AUTH_TOKEN: the organization-level robot token for authentication. Required for non-interactive deployment.SANITY_APP_*: any environment variables prefixed withSANITY_APP_are embedded in your app's browser code at build time.
Don't put secrets in SANITY_APP_ variables
The build writes the value of every SANITY_APP_ variable into your app's JavaScript files, and anyone who can load those files can read it. Limiting who can open the app in the Dashboard doesn't hide these values. Keep API keys, service tokens, and other secrets on a server you control, and have your app call that server instead.
Troubleshooting
The following errors are commonly reported by developers deploying App SDK apps:
- "Unauthorized" or "Insufficient permissions": verify that your token is an organization-level robot token with the Manage SDK Apps permission enabled.
- "Session does not match project host": this can occur in CI/CD environments. Ensure
SANITY_AUTH_TOKENis set correctly and that no cached credentials are interfering.
Next steps
Learn more about configuring and deploying App SDK apps:
- Configuration: Set your app's title, icon, Dashboard visibility, and other
sanity.cli.tsoptions. - Deploy CLI command reference: See every
sanity deployflag, including--dry-runto check a deploy without uploading anything. - Undeploy CLI command reference: See the
sanity undeployarguments and flags, including--dry-run.
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?