agent-neckbeard 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,215 @@
1
+ /**
2
+ * agent-neckbeard - Deploy AI agents to E2B sandboxes
3
+ */
4
+ /**
5
+ * Base error class for agent-neckbeard errors.
6
+ * All custom errors extend this class.
7
+ */
8
+ declare class NeckbeardError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ /**
12
+ * Error thrown when sandbox deployment fails.
13
+ * This includes sandbox creation, dependency installation, and file upload failures.
14
+ */
15
+ declare class DeploymentError extends NeckbeardError {
16
+ readonly cause?: Error | undefined;
17
+ constructor(message: string, cause?: Error | undefined);
18
+ }
19
+ /**
20
+ * Error thrown when input or output schema validation fails.
21
+ */
22
+ declare class ValidationError extends NeckbeardError {
23
+ readonly cause?: Error | undefined;
24
+ constructor(message: string, cause?: Error | undefined);
25
+ }
26
+ /**
27
+ * Error thrown when agent execution fails in the sandbox.
28
+ */
29
+ declare class ExecutionError extends NeckbeardError {
30
+ readonly cause?: Error | undefined;
31
+ constructor(message: string, cause?: Error | undefined);
32
+ }
33
+ /**
34
+ * Error thrown when required environment variables are missing.
35
+ */
36
+ declare class ConfigurationError extends NeckbeardError {
37
+ constructor(message: string);
38
+ }
39
+ interface AgentRunContext {
40
+ executionId: string;
41
+ signal: AbortSignal;
42
+ env: Record<string, string>;
43
+ logger: {
44
+ debug: (message: string, ...args: unknown[]) => void;
45
+ info: (message: string, ...args: unknown[]) => void;
46
+ warn: (message: string, ...args: unknown[]) => void;
47
+ error: (message: string, ...args: unknown[]) => void;
48
+ };
49
+ }
50
+ type AgentRunResult<TOutput> = {
51
+ ok: true;
52
+ executionId: string;
53
+ output: TOutput;
54
+ } | {
55
+ ok: false;
56
+ executionId: string;
57
+ error: Error | NeckbeardError;
58
+ };
59
+ interface SchemaLike<T> {
60
+ parse: (data: unknown) => T;
61
+ }
62
+ interface OsDependencies {
63
+ /** APT packages to install (e.g., ['curl', 'git']) */
64
+ apt?: string[];
65
+ /** Custom shell commands to run during setup */
66
+ commands?: string[];
67
+ }
68
+ interface BuildOptions {
69
+ /** External dependencies to exclude from the bundle */
70
+ external?: string[];
71
+ /**
72
+ * Automatically detect dependencies that shouldn't be bundled (native addons).
73
+ * @default true
74
+ */
75
+ autoDetectExternal?: boolean;
76
+ }
77
+ /**
78
+ * Configuration for downloading a file into the sandbox filesystem.
79
+ * Files are downloaded during deploy() before the agent runs.
80
+ */
81
+ interface FileDownload {
82
+ /** URL to download the file from (supports http/https) */
83
+ url: string;
84
+ /**
85
+ * Destination path in the sandbox.
86
+ * Can be absolute (e.g., '/home/user/data/model.bin') or
87
+ * relative to /home/user/ (e.g., 'data/model.bin').
88
+ * Parent directories are created automatically.
89
+ */
90
+ path: string;
91
+ }
92
+ /** Default dependencies - empty by default, specify what you need */
93
+ declare const DEFAULT_DEPENDENCIES: OsDependencies;
94
+ interface AgentConfig<TInput, TOutput> {
95
+ /**
96
+ * E2B template name or ID to use for the sandbox.
97
+ * Templates define the sandbox's CPU, memory, and pre-installed software.
98
+ *
99
+ * Common templates:
100
+ * - 'code-interpreter-v1': 2 cores, 2048 MB (recommended for Claude Agent SDK)
101
+ * - 'base': 2 cores, 512 MB (minimal)
102
+ * - 'desktop': 8 cores, 8192 MB (for heavy workloads)
103
+ *
104
+ * Create custom templates via E2B CLI:
105
+ * e2b template build --cpu-count 4 --memory-mb 4096 --name my-template
106
+ *
107
+ * @see https://e2b.dev/docs/template/overview
108
+ */
109
+ template: string;
110
+ inputSchema: SchemaLike<TInput>;
111
+ outputSchema: SchemaLike<TOutput>;
112
+ run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
113
+ maxDuration?: number;
114
+ /** OS-level dependencies to install in the sandbox. Defaults to Claude Code. Set to {} to skip. */
115
+ dependencies?: OsDependencies;
116
+ /**
117
+ * Files to download and initialize in the sandbox filesystem.
118
+ * Downloaded during deploy() before the agent code runs.
119
+ * Useful for pre-loading models, datasets, configuration files, etc.
120
+ */
121
+ files?: FileDownload[];
122
+ /**
123
+ * Local path to a .claude directory containing skills and settings.
124
+ * The directory will be uploaded to /home/user/agent/.claude/ in the sandbox.
125
+ * This enables Claude Agent SDK to access skills defined in SKILL.md files
126
+ * within .claude/skills/ subdirectories.
127
+ *
128
+ * Example: claudeDir: './my-project/.claude'
129
+ *
130
+ * The Claude Agent SDK will discover skills when:
131
+ * - cwd is set to /home/user/agent/ (containing .claude/)
132
+ * - settingSources includes 'project'
133
+ * - allowedTools includes 'Skill'
134
+ */
135
+ claudeDir?: string;
136
+ /**
137
+ * Environment variables to pass to the sandbox.
138
+ * These will be available to the agent code via process.env and ctx.env.
139
+ * Undefined values are filtered out.
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * envs: {
144
+ * ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
145
+ * MY_API_KEY: process.env.MY_API_KEY,
146
+ * }
147
+ * ```
148
+ */
149
+ envs?: Record<string, string | undefined>;
150
+ /** Build-time options for bundling */
151
+ build?: BuildOptions;
152
+ }
153
+ declare class Agent<TInput, TOutput> {
154
+ readonly template: string;
155
+ readonly inputSchema: SchemaLike<TInput>;
156
+ readonly outputSchema: SchemaLike<TOutput>;
157
+ readonly maxDuration: number;
158
+ readonly dependencies: OsDependencies;
159
+ readonly files: FileDownload[];
160
+ readonly claudeDir?: string;
161
+ readonly envs: Record<string, string | undefined>;
162
+ readonly build: BuildOptions;
163
+ /** @internal Used by the sandbox runner - must be public for bundled code access */
164
+ _run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
165
+ private _sourceFile;
166
+ private _sandboxId?;
167
+ constructor(config: AgentConfig<TInput, TOutput>);
168
+ get sandboxId(): string | undefined;
169
+ /**
170
+ * Deploys the agent to an E2B sandbox.
171
+ *
172
+ * This method bundles the agent code using esbuild, creates a new E2B sandbox,
173
+ * installs any specified OS dependencies, downloads configured files, and
174
+ * uploads the agent code to the sandbox.
175
+ *
176
+ * @returns The sandbox ID, which can be used to reconnect via `run(input, { sandboxId })`
177
+ * @throws {ConfigurationError} If E2B_API_KEY environment variable is not set
178
+ * @throws {DeploymentError} If sandbox creation, dependency installation, or file upload fails
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const agent = new Agent({ ... });
183
+ * const sandboxId = await agent.deploy();
184
+ * console.log(`Deployed to sandbox: ${sandboxId}`);
185
+ * ```
186
+ */
187
+ deploy(): Promise<string>;
188
+ /**
189
+ * Executes the agent with the given input.
190
+ *
191
+ * The agent must be deployed before calling this method, or a sandboxId must
192
+ * be provided in the options. Input is validated against the input schema,
193
+ * then the agent runs in the sandbox with the validated input. Output is
194
+ * validated against the output schema before being returned.
195
+ *
196
+ * @param input - The input data for the agent, must conform to inputSchema
197
+ * @param options - Optional configuration for this run
198
+ * @param options.sandboxId - Sandbox ID to use, overrides the deployed sandbox
199
+ * @returns A result object indicating success or failure with output or error
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * // Using deployed sandbox
204
+ * const result = await agent.run({ prompt: 'Hello, world!' });
205
+ *
206
+ * // Using explicit sandboxId (for reconnecting)
207
+ * const result = await agent.run({ prompt: 'Hello!' }, { sandboxId: 'sbx_...' });
208
+ * ```
209
+ */
210
+ run(input: TInput, options?: {
211
+ sandboxId?: string;
212
+ }): Promise<AgentRunResult<TOutput>>;
213
+ }
214
+
215
+ export { Agent, type AgentConfig, type AgentRunContext, type AgentRunResult, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, DeploymentError, ExecutionError, type FileDownload, NeckbeardError, type OsDependencies, ValidationError };
@@ -0,0 +1,215 @@
1
+ /**
2
+ * agent-neckbeard - Deploy AI agents to E2B sandboxes
3
+ */
4
+ /**
5
+ * Base error class for agent-neckbeard errors.
6
+ * All custom errors extend this class.
7
+ */
8
+ declare class NeckbeardError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ /**
12
+ * Error thrown when sandbox deployment fails.
13
+ * This includes sandbox creation, dependency installation, and file upload failures.
14
+ */
15
+ declare class DeploymentError extends NeckbeardError {
16
+ readonly cause?: Error | undefined;
17
+ constructor(message: string, cause?: Error | undefined);
18
+ }
19
+ /**
20
+ * Error thrown when input or output schema validation fails.
21
+ */
22
+ declare class ValidationError extends NeckbeardError {
23
+ readonly cause?: Error | undefined;
24
+ constructor(message: string, cause?: Error | undefined);
25
+ }
26
+ /**
27
+ * Error thrown when agent execution fails in the sandbox.
28
+ */
29
+ declare class ExecutionError extends NeckbeardError {
30
+ readonly cause?: Error | undefined;
31
+ constructor(message: string, cause?: Error | undefined);
32
+ }
33
+ /**
34
+ * Error thrown when required environment variables are missing.
35
+ */
36
+ declare class ConfigurationError extends NeckbeardError {
37
+ constructor(message: string);
38
+ }
39
+ interface AgentRunContext {
40
+ executionId: string;
41
+ signal: AbortSignal;
42
+ env: Record<string, string>;
43
+ logger: {
44
+ debug: (message: string, ...args: unknown[]) => void;
45
+ info: (message: string, ...args: unknown[]) => void;
46
+ warn: (message: string, ...args: unknown[]) => void;
47
+ error: (message: string, ...args: unknown[]) => void;
48
+ };
49
+ }
50
+ type AgentRunResult<TOutput> = {
51
+ ok: true;
52
+ executionId: string;
53
+ output: TOutput;
54
+ } | {
55
+ ok: false;
56
+ executionId: string;
57
+ error: Error | NeckbeardError;
58
+ };
59
+ interface SchemaLike<T> {
60
+ parse: (data: unknown) => T;
61
+ }
62
+ interface OsDependencies {
63
+ /** APT packages to install (e.g., ['curl', 'git']) */
64
+ apt?: string[];
65
+ /** Custom shell commands to run during setup */
66
+ commands?: string[];
67
+ }
68
+ interface BuildOptions {
69
+ /** External dependencies to exclude from the bundle */
70
+ external?: string[];
71
+ /**
72
+ * Automatically detect dependencies that shouldn't be bundled (native addons).
73
+ * @default true
74
+ */
75
+ autoDetectExternal?: boolean;
76
+ }
77
+ /**
78
+ * Configuration for downloading a file into the sandbox filesystem.
79
+ * Files are downloaded during deploy() before the agent runs.
80
+ */
81
+ interface FileDownload {
82
+ /** URL to download the file from (supports http/https) */
83
+ url: string;
84
+ /**
85
+ * Destination path in the sandbox.
86
+ * Can be absolute (e.g., '/home/user/data/model.bin') or
87
+ * relative to /home/user/ (e.g., 'data/model.bin').
88
+ * Parent directories are created automatically.
89
+ */
90
+ path: string;
91
+ }
92
+ /** Default dependencies - empty by default, specify what you need */
93
+ declare const DEFAULT_DEPENDENCIES: OsDependencies;
94
+ interface AgentConfig<TInput, TOutput> {
95
+ /**
96
+ * E2B template name or ID to use for the sandbox.
97
+ * Templates define the sandbox's CPU, memory, and pre-installed software.
98
+ *
99
+ * Common templates:
100
+ * - 'code-interpreter-v1': 2 cores, 2048 MB (recommended for Claude Agent SDK)
101
+ * - 'base': 2 cores, 512 MB (minimal)
102
+ * - 'desktop': 8 cores, 8192 MB (for heavy workloads)
103
+ *
104
+ * Create custom templates via E2B CLI:
105
+ * e2b template build --cpu-count 4 --memory-mb 4096 --name my-template
106
+ *
107
+ * @see https://e2b.dev/docs/template/overview
108
+ */
109
+ template: string;
110
+ inputSchema: SchemaLike<TInput>;
111
+ outputSchema: SchemaLike<TOutput>;
112
+ run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
113
+ maxDuration?: number;
114
+ /** OS-level dependencies to install in the sandbox. Defaults to Claude Code. Set to {} to skip. */
115
+ dependencies?: OsDependencies;
116
+ /**
117
+ * Files to download and initialize in the sandbox filesystem.
118
+ * Downloaded during deploy() before the agent code runs.
119
+ * Useful for pre-loading models, datasets, configuration files, etc.
120
+ */
121
+ files?: FileDownload[];
122
+ /**
123
+ * Local path to a .claude directory containing skills and settings.
124
+ * The directory will be uploaded to /home/user/agent/.claude/ in the sandbox.
125
+ * This enables Claude Agent SDK to access skills defined in SKILL.md files
126
+ * within .claude/skills/ subdirectories.
127
+ *
128
+ * Example: claudeDir: './my-project/.claude'
129
+ *
130
+ * The Claude Agent SDK will discover skills when:
131
+ * - cwd is set to /home/user/agent/ (containing .claude/)
132
+ * - settingSources includes 'project'
133
+ * - allowedTools includes 'Skill'
134
+ */
135
+ claudeDir?: string;
136
+ /**
137
+ * Environment variables to pass to the sandbox.
138
+ * These will be available to the agent code via process.env and ctx.env.
139
+ * Undefined values are filtered out.
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * envs: {
144
+ * ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
145
+ * MY_API_KEY: process.env.MY_API_KEY,
146
+ * }
147
+ * ```
148
+ */
149
+ envs?: Record<string, string | undefined>;
150
+ /** Build-time options for bundling */
151
+ build?: BuildOptions;
152
+ }
153
+ declare class Agent<TInput, TOutput> {
154
+ readonly template: string;
155
+ readonly inputSchema: SchemaLike<TInput>;
156
+ readonly outputSchema: SchemaLike<TOutput>;
157
+ readonly maxDuration: number;
158
+ readonly dependencies: OsDependencies;
159
+ readonly files: FileDownload[];
160
+ readonly claudeDir?: string;
161
+ readonly envs: Record<string, string | undefined>;
162
+ readonly build: BuildOptions;
163
+ /** @internal Used by the sandbox runner - must be public for bundled code access */
164
+ _run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
165
+ private _sourceFile;
166
+ private _sandboxId?;
167
+ constructor(config: AgentConfig<TInput, TOutput>);
168
+ get sandboxId(): string | undefined;
169
+ /**
170
+ * Deploys the agent to an E2B sandbox.
171
+ *
172
+ * This method bundles the agent code using esbuild, creates a new E2B sandbox,
173
+ * installs any specified OS dependencies, downloads configured files, and
174
+ * uploads the agent code to the sandbox.
175
+ *
176
+ * @returns The sandbox ID, which can be used to reconnect via `run(input, { sandboxId })`
177
+ * @throws {ConfigurationError} If E2B_API_KEY environment variable is not set
178
+ * @throws {DeploymentError} If sandbox creation, dependency installation, or file upload fails
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const agent = new Agent({ ... });
183
+ * const sandboxId = await agent.deploy();
184
+ * console.log(`Deployed to sandbox: ${sandboxId}`);
185
+ * ```
186
+ */
187
+ deploy(): Promise<string>;
188
+ /**
189
+ * Executes the agent with the given input.
190
+ *
191
+ * The agent must be deployed before calling this method, or a sandboxId must
192
+ * be provided in the options. Input is validated against the input schema,
193
+ * then the agent runs in the sandbox with the validated input. Output is
194
+ * validated against the output schema before being returned.
195
+ *
196
+ * @param input - The input data for the agent, must conform to inputSchema
197
+ * @param options - Optional configuration for this run
198
+ * @param options.sandboxId - Sandbox ID to use, overrides the deployed sandbox
199
+ * @returns A result object indicating success or failure with output or error
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * // Using deployed sandbox
204
+ * const result = await agent.run({ prompt: 'Hello, world!' });
205
+ *
206
+ * // Using explicit sandboxId (for reconnecting)
207
+ * const result = await agent.run({ prompt: 'Hello!' }, { sandboxId: 'sbx_...' });
208
+ * ```
209
+ */
210
+ run(input: TInput, options?: {
211
+ sandboxId?: string;
212
+ }): Promise<AgentRunResult<TOutput>>;
213
+ }
214
+
215
+ export { Agent, type AgentConfig, type AgentRunContext, type AgentRunResult, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, DeploymentError, ExecutionError, type FileDownload, NeckbeardError, type OsDependencies, ValidationError };