
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeGreat question! For Sanity Studio v2, switching between datasets is done through configuration in your sanity.json file and environment variables. Here's how to set it up:
The cleanest approach for v2 is to use environment variables to specify which dataset your Studio should connect to. In your sanity.json, you can reference the dataset using process.env:
{
"root": true,
"project": {
"name": "Your Project Name"
},
"api": {
"projectId": "your-project-id",
"dataset": "production"
},
"plugins": [
"@sanity/base",
"@sanity/desk-tool"
]
}Then create .env files to switch between datasets:
For your original production dataset (.env.production):
SANITY_STUDIO_DATASET=production
For your cloned dataset (.env.staging or .env.local):
SANITY_STUDIO_DATASET=production-clone
Update your sanity.json to use the environment variable:
{
"api": {
"projectId": "your-project-id",
"dataset": "${SANITY_STUDIO_DATASET}"
}
}Then run your Studio with the appropriate environment:
# For production dataset
sanity start
# For your cloned dataset
SANITY_STUDIO_DATASET=production-clone sanity start
# Or use a different mode
SANITY_ACTIVE_ENV=staging sanity startAnother approach is to maintain separate Studio directories or configurations for each dataset. You could:
dataset value in each sanity.json to point to different datasetsSANITY_STUDIO_ to be automatically picked up.env.local file should be added to your .gitignore to avoid committing environment-specific settingsJust a friendly reminder that Sanity Studio v2 is now deprecated. When you have time, consider migrating to v3, which has a much better workspaces feature that makes switching between datasets super easy with a dropdown in the Studio UI!
For v3, you'd use workspaces configuration in sanity.config.js which gives you a native UI switcher between datasets - much more convenient than the v2 approach.
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