
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes, it is absolutely possible to use a token for logging in to the Sanity CLI for automated deployments! This is actually the recommended approach for CI/CD environments.
For automated systems like CI/CD pipelines, you should use the SANITY_AUTH_TOKEN environment variable instead of interactive login. Here's how:
First, create a deploy token in your Sanity project management dashboard. Navigate to your project settings to generate a token with appropriate permissions.
In your CI/CD environment, set the SANITY_AUTH_TOKEN environment variable with your token:
SANITY_AUTH_TOKEN=<your-deploy-token> sanity deployOr for schema deployment:
SANITY_AUTH_TOKEN=<your-deploy-token> sanity schema deployFor automated deployments, you can configure your workflow like this:
// sanity.cli.ts
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: process.env.SANITY_STUDIO_PROJECT_ID,
dataset: process.env.SANITY_STUDIO_DATASET,
},
studioHost: process.env.SANITY_STUDIO_HOSTNAME
})Then in your CI/CD pipeline, ensure these environment variables are set:
SANITY_AUTH_TOKEN - Your deploy token (for authentication)SANITY_STUDIO_PROJECT_ID - Your project IDSANITY_STUDIO_DATASET - Your dataset nameSANITY_STUDIO_HOSTNAME - Your studio hostname (optional, for deployment)According to the Sanity deployment documentation, the sanity deploy command normally uses your local user session for authentication, which won't be available in CI/CD workflows. The SANITY_AUTH_TOKEN environment variable solves this by providing programmatic authentication.
This token-based authentication works for:
sanity deploy)sanity graphql deploy)The token-based authentication is secure and allows you to grant specific permissions without sharing user credentials. You can manage and revoke these tokens through your project settings at any time.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store