Deploy
CLI commands, deploy pipeline, redeploying, and what lives where. Set up your project first in Project Setup.
CLI reference
The CLI is available as an npm package. Run it with npx or install globally:
# Run directly with npx
npx @21st-sdk/cli login
npx @21st-sdk/cli deploy
# Or install globally
npm install -g @21st-sdk/cli
@21st-sdk/cli login
@21st-sdk/cli deployLogin
Authenticate with your API key. Get one from the dashboard.
$ @21st-sdk/cli login
Enter your API key: an_sk_...
Authenticated as John (team: my-team)Credentials are saved to ~/.an/credentials. You only need to log in once.
Deploy
# deploy every agent under agents/
npx @21st-sdk/cli deploy
# deploy only one agent
npx @21st-sdk/cli deploy --agent my-agentUse --agent <slug> when you only want to redeploy one agent from the agents/ directory.
How deploy works
When you run @21st-sdk/cli deploy, four things happen:
Bundle
The CLI finds your entrypoint and bundles it locally with esbuild.
Upload
The bundle, template archive, and deployment metadata are uploaded to the deploy API together with your agent slug.
Sandbox
The platform prepares the E2B sandbox template and starts the runtime processes that host your tools and MCP servers inside that sandbox.
Live
Your deployment becomes live immediately. The agent then runs in an isolated execution layer inside the sandbox when chats start.
Environment variables
Set secrets and config values (API keys for tools, database URLs) from the dashboard or via the CLI. Changes take effect on the next request — no redeploy required.
# list configured env vars
npx @21st-sdk/cli env list my-agent
# set one or more keys
npx @21st-sdk/cli env set my-agent OPENAI_API_KEY=sk-live-... STRIPE_KEY=sk_live-...
# remove a key
npx @21st-sdk/cli env remove my-agent OPENAI_API_KEYSee API Keys & Env Vars for how env vars are stored, injected, and isolated from the agent process.
Redeploying
Run @21st-sdk/cli deploy again to update your agent, or use @21st-sdk/cli deploy --agent my-agent to update just one slug. The CLI:
- Bundles your updated code
- Kills the old sandbox
- Creates a fresh sandbox with the new bundle
- Updates the agent config in the database
The agent URL stays the same. Active chat sessions may be interrupted during redeploy.
What lives where
Agents are code-first. Agent behavior lives entirely in your code. The dashboard is for monitoring and managing environment variables.
| What | Source | Managed via |
|---|---|---|
| Code-managed | ||
| Agent config | agents/my-agent/index.ts | Code & redeploy |
| System prompt | agents/my-agent/index.ts | Code & redeploy |
| Custom tools | agents/my-agent/index.ts | Code & redeploy |
| Lifecycle hooks | agents/my-agent/index.ts | Code & redeploy |
| Platform-managed | ||
| Environment variables | Dashboard | Dashboard or cli env set |
| Deployments | Dashboard | cli deploy |
| Logs & costs | Dashboard | Dashboard or cli logs |
Project metadata
Current CLI deploys do not require a local project metadata file. If you still have an old .an/project.json from an older version, you can remove it.