---
name: sanity-runtime-cli
description: Use the Sanity `blueprints` and `functions` commands to manage Sanity Blueprints and develop, test, and operate Sanity Functions. Use when an agent needs to inspect or run `blueprints` & `functions` commands, work with Blueprint manifests and remote Stacks, or work with Sanity Function resources.
---

# Sanity Runtime CLI

Typically, the `@sanity/runtime-cli` (`sanity-run`) CLI is not used directly by end-users. The main `@sanity/cli` (`sanity`) loads and uses this CLI internally.  
All `sanity-run` commands can also be run as `sanity <command>` when `@sanity/cli` is available.  
The preferred way to run Sanity commands is with `npx @sanity/cli <command>`.

If Sanity authentication has been configured, `sanity-run` may be preferred in environments like CI/CD pipelines for its smaller install size.

## Read command guidance first

Before running an unfamiliar command, print its agent-oriented guidance:

```sh
sanity-run blueprints deploy --skill
sanity-run functions test --skill
sanity-run functions env add --skill
```

`--skill` prints the matching Markdown file and exits without executing the command. `--llms` and `--skills` are aliases.

Use `--help` or [README.md](./README.md) for exhaustive arguments and flags. Use `--skill` for command workflows, automation advice, safety checks, and output-handling guidance.

## Find command skill files

Command guidance is stored in [skills/](./skills/). Derive filenames from oclif command IDs by replacing colons with hyphens:

- `blueprints:deploy` → `skills/blueprints-deploy.md`
- `functions:test` → `skills/functions-test.md`
- `functions:env:add` → `skills/functions-env-add.md`

Read the file matching the command before invoking it. Follow its guidance for destructive operations, credentials, environment variables, and long-running commands.

## Resolve the target

Most `blueprints` commands and every `functions` command that touches remote state need a scope (project or organization), a Stack, and a token. Each is resolved independently, in this order:

1. Command flags, such as `--project-id`, `--organization-id`, and `--stack`.
2. Environment variables: `SANITY_PROJECT_ID`, `SANITY_ORGANIZATION_ID`, `SANITY_BLUEPRINT_STACK_ID`.
3. Values exported by the Blueprint manifest.
4. `.sanity/blueprint.config.json`.

When both a project ID and an organization ID resolve, project scope wins. Prefer explicit flags in CI and when correcting a misconfigured target; a value inherited from a lower-priority source is easy to miss.

`SANITY_AUTH_TOKEN` supplies the token, otherwise it is read from the `@sanity/cli` login config. `SANITY_BLUEPRINT_PATH` points at a Blueprint file or its directory when it is not discoverable from the working directory.

## Choose a command family

- Use `blueprints` commands to manage local Blueprint manifests and remote Stack deployments.
- Use `functions` commands to scaffold, build, emulate, test, and operate Sanity Functions.

## Read Sanity documentation

- [Sanity Blueprints](https://www.sanity.io/docs/blueprints)
- [Sanity Functions](https://www.sanity.io/docs/functions)
