Agents SDK

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 deploy

Login

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-agent

Use --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:

1

Bundle

The CLI finds your entrypoint and bundles it locally with esbuild.

2

Upload

The bundle, template archive, and deployment metadata are uploaded to the deploy API together with your agent slug.

3

Sandbox

The platform prepares the E2B sandbox template and starts the runtime processes that host your tools and MCP servers inside that sandbox.

4

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.

terminal
# 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_KEY

See 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:

  1. Bundles your updated code
  2. Kills the old sandbox
  3. Creates a fresh sandbox with the new bundle
  4. 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.

WhatSourceManaged via
Code-managed
Agent configagents/my-agent/index.tsCode & redeploy
System promptagents/my-agent/index.tsCode & redeploy
Custom toolsagents/my-agent/index.tsCode & redeploy
Lifecycle hooksagents/my-agent/index.tsCode & redeploy
Platform-managed
Environment variablesDashboardDashboard or cli env set
DeploymentsDashboardcli deploy
Logs & costsDashboardDashboard 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.

What's next

Deploy - 21st Agents SDK Docs