Build & Deploy
Project structure, full configuration reference, CLI commands, and deploy internals.
Project layout
my-agent/ ├── package.json # @an-sdk/agent + zod ├── src/ │ └── agent.ts # Agent configuration (entry point) ├── .an/ # Generated on first deploy │ └── project.json # Links project to deployed agent ├── .env # Local env vars (optional) └── .gitignore # Should include .an/
This is the minimal layout. You can organize your code however you like — the CLI only needs a valid entry point that exports an agent config.
Agent configuration
The agent file is where all your configuration lives — model, runtime, system prompt, tools, hooks:
import { agent, tool } from "@an-sdk/agent"
import { z } from "zod"
export default agent({
// Model and runtime
model: "claude-sonnet-4-6",
runtime: "claude-code",
// Instructions
systemPrompt: "You are a helpful coding assistant.",
// Execution limits
permissionMode: "default",
maxTurns: 50,
// Custom tools
tools: {
greet: tool({
description: "Greet a user",
inputSchema: z.object({ name: z.string() }),
execute: async ({ name }) => ({
content: [{ type: "text", text: `Hello, ${name}!` }],
}),
}),
},
// Lifecycle hooks
onFinish: async ({ result }) => {
console.log("Done:", result)
},
})@an-sdk/agent is externalized during bundling — the sandbox provides it at runtime. You don't need to worry about bundle size from this import.Entry points
When you run an deploy, the CLI searches for the first matching file:
| Priority | File |
|---|---|
| 1 | an/agent.ts |
| 2 | an/index.ts |
| 3 | src/agent.ts |
| 4 | src/index.ts |
| 5 | agent.ts |
| 6 | index.ts |
The entry point must have a default export that returns an agent config created with agent().
package.json
Two required dependencies:
{
"name": "my-agent",
"type": "module",
"dependencies": {
"@an-sdk/agent": "latest",
"zod": "^3.24"
}
}CLI reference
The CLI is available as an npm package. Run it with npx or install globally:
# Run directly with npx
npx @an-sdk/cli login
npx @an-sdk/cli deploy
# Or install globally
npm install -g @an-sdk/cli
an login
an deployLogin
Authenticate with your API key. Get one from the dashboard.
$ an 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
$ an deploy
Bundling src/agent.ts...
Bundled (12.3kb)
Deploying my-agent...
✓ https://api.an.dev/v1/chat/my-agent
Agent: my-agent
Sandbox: sbx_abc123How deploy works
When you run an deploy, four things happen:
Bundle
The CLI finds your entry point and bundles it with esbuild (Node 22, ESM, minified). @an-sdk/agent is externalized — the sandbox provides it at runtime.
Upload
The bundle is base64-encoded and sent to the deploy API along with your agent slug and API key.
Sandbox
The server creates an E2B sandbox with the AN runtime template (Node 24, git, curl, ripgrep, GitHub CLI). The agent bundle, credentials, and environment variables are injected.
Live
The agent config is saved to the database with the sandbox URL and bundle hash. Your agent is immediately available at its chat endpoint.
Environment variables
Set environment variables from the dashboard. They are injected as a .env file in the sandbox on every deploy. Your agent code can read them via process.env.
Storage: Encrypted in the database as JSON on the AgentConfig
Injection: Written to /home/user/.env inside the sandbox at deploy time
Updates: Changes take effect on the next deploy
Generated files
After your first deploy, the CLI creates a .an/ directory with project metadata:
{
"agentId": "a1b2c3d4-...",
"slug": "my-agent"
}This file links your local project to the deployed agent. Subsequent deploys reuse the same slug and update the existing agent (killing the old sandbox and creating a new one). Add .an/ to your .gitignore.
Redeploying
Run an deploy again to update your agent. 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
AN agents are code-first. Agent behavior lives entirely in your code. The dashboard is for monitoring and managing environment variables.
| What | Where | Managed from |
|---|---|---|
| Agent configmodel, runtime, permission mode, max turns | src/agent.ts | Code only |
| System promptinstructions that define agent behavior | src/agent.ts | Code only |
| Custom toolstool definitions with Zod schemas | src/agent.ts | Code only |
| Lifecycle hooksonStart, onToolCall, onFinish, etc. | src/agent.ts | Code only |
| Environment variablessecrets and config injected at deploy | Dashboard | Dashboard |
| Deploymentssandbox status, bundle hash, deploy time | Dashboard | an deploy |
| Logs & costsconversations, token usage, USD costs | Dashboard | View only |