
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeNo worries about asking again! This is definitely a common roadblock. Let me clarify what's happening with environment variables in Sanity Studio.
The good news is that SANITY_STUDIO_ prefixed variables do work in Sanity Studio, but you need to set them up correctly using environment-specific .env files.
Create two separate .env files in your Studio folder:
.env.development (loaded during sanity start):
SANITY_STUDIO_IS_PRODUCTION=false
.env.production (loaded during sanity build):
SANITY_STUDIO_IS_PRODUCTION=true
Then in your desk structure file, access them using process.env:
// In your desk structure file
export const structure = (S) => {
const isProduction = process.env.SANITY_STUDIO_IS_PRODUCTION === 'true'
if (isProduction) {
// Production desk structure
return S.list()
.title('Content')
.items([
// your production items
])
}
// Development desk structure
return S.list()
.title('Content (Dev)')
.items([
// your dev items with extra tools, debug panels, etc.
])
}According to the Sanity documentation on environment variables, Sanity Studio automatically loads the appropriate .env file based on the SANITY_ACTIVE_ENV variable, which defaults to:
'development' when running sanity start'production' when running sanity buildThe key requirements are:
SANITY_STUDIO_ - This is mandatory for variables to be passed to the frontendprocess.env - Access variables via process.env.SANITY_STUDIO_YOUR_VAR (not import.meta.env).env files - Use .env.development and .env.production for different environments.env* to your .gitignore if you add any sensitive valuesThis approach gives you clean separation between your development and production desk structures without any hacky workarounds!
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