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:

src/agent.ts
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)
  },
})
Tip: @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:

PriorityFile
1an/agent.ts
2an/index.ts
3src/agent.ts
4src/index.ts
5agent.ts
6index.ts

The entry point must have a default export that returns an agent config created with agent().

package.json

Two required dependencies:

package.json
{
  "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 deploy

Login

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_abc123

How deploy works

When you run an deploy, four things happen:

1

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.

2

Upload

The bundle is base64-encoded and sent to the deploy API along with your agent slug and API key.

3

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.

4

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:

.an/project.json
{
  "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:

  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

AN agents are code-first. Agent behavior lives entirely in your code. The dashboard is for monitoring and managing environment variables.

WhatWhereManaged from
Agent configmodel, runtime, permission mode, max turnssrc/agent.tsCode only
System promptinstructions that define agent behaviorsrc/agent.tsCode only
Custom toolstool definitions with Zod schemassrc/agent.tsCode only
Lifecycle hooksonStart, onToolCall, onFinish, etc.src/agent.tsCode only
Environment variablessecrets and config injected at deployDashboardDashboard
Deploymentssandbox status, bundle hash, deploy timeDashboardan deploy
Logs & costsconversations, token usage, USD costsDashboardView only
Build & Deploy — An Docs