@21st-sdk/node
Server-side Node.js SDK for 21st Agents. Manage sandboxes, threads, and tokens programmatically.
Install
npm install @21st-sdk/node
Quick Start
import { AgentClient } from "@21st-sdk/node"
const client = new AgentClient({
apiKey: process.env.API_KEY_21ST!, // 21st_sk_...
})
// Create a sandbox for your agent
const sandbox = await client.sandboxes.create({ agent: "my-agent" })
// Create a thread
const thread = await client.threads.create({
sandboxId: sandbox.sandboxId,
name: "Review PR #42",
})
// Generate a short-lived token for browser clients
const { token, expiresAt } = await client.tokens.create({
agent: "my-agent",
expiresIn: "1h",
})
API
new AgentClient(config)
new AgentClient({
apiKey: string // Your 21st_sk_ API key
baseUrl?: string // Default: "https://relay.an.dev"
})
client.sandboxes
| Method | Description |
create({ agent }) | Create a new sandbox for an agent |
get(sandboxId) | Get sandbox details (status, threads, agent info) |
delete(sandboxId) | Delete a sandbox |
exec({ sandboxId, command, cwd?, envs?, timeoutMs? }) | Run a command inside a sandbox |
git.clone({ sandboxId, url, path?, token?, depth? }) | Clone a repository into a sandbox |
client.sandboxes.files
| Method | Description |
write({ sandboxId, files }) | Write one or more text files into a sandbox |
read({ sandboxId, path }) | Read one file from a sandbox |
list({ sandboxId, path, depth? }) | List files and directories under a path |
getInfo({ sandboxId, path }) | Get metadata for one file or directory |
exists({ sandboxId, path }) | Check whether a file or directory exists |
makeDir({ sandboxId, path }) | Create a directory path, returning whether it was newly created |
rename({ sandboxId, oldPath, newPath }) | Rename or move a file or directory |
remove({ sandboxId, path }) | Remove a file or directory |
client.threads
| Method | Description |
list({ sandboxId }) | List all threads in a sandbox |
create({ sandboxId, name? }) | Create a new thread |
get({ sandboxId, threadId }) | Get thread with messages |
delete({ sandboxId, threadId }) | Delete a thread |
client.tokens
| Method | Description |
create({ agent?, userId?, expiresIn? }) | Create a short-lived JWT (default: 1h) |
License
MIT
关于 @21st-sdk/node 的常见问题
@21st-sdk/node 是什么?
Server-side Node.js SDK for 21st Agents
如何安装 @21st-sdk/node?
在项目目录运行 npm install @21st-sdk/node,或使用 pnpm add / yarn add / bun add。
@21st-sdk/node 支持 TypeScript 吗?
支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。
@21st-sdk/node 支持 ESM 还是 CommonJS?
同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。
@21st-sdk/node 可以商用吗?
@21st-sdk/node 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。
@21st-sdk/node 的下载量有多少?
根据 npm 官方下载统计,@21st-sdk/node 在 2026/10/05 – 2026/11/03 这 30 天内被下载 4,841 次,日均约 161 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。
@21st-sdk/node 还在维护吗?
最新版本 0.1.1 发布于 2026/04/29(6 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/03/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。