Appearance
Amp
amp is a prebuilt AI Agents runtime environment that includes the Amp CLI from Sourcegraph—a multi-model coding agent with built-in code intelligence. It runs headlessly in an isolated sandbox with full access to the filesystem, terminal, and git.
The template comes preinstalled with Node.js, git, ripgrep, vim, GitHub CLI, and frontend scaffolding tools like pnpm/tsx/vite. No API keys are baked into the image; authentication is injected via envs when creating the sandbox.
Template Contents
| Component | Description |
|---|---|
amp | Amp CLI |
| Base tools | Node.js 24.x, git, ripgrep, vim, GitHub CLI, pnpm/tsx/vite, etc. |
Creating a Sandbox
Obtain AMP_API_KEY from ampcode.com/settings and inject it via envs:
javascript
import { Sandbox } from 'e2b'
const sandbox = await Sandbox.create('amp', {
envs: { AMP_API_KEY: process.env.AMP_API_KEY },
})Common CLI Flags
| Flag | Description |
|---|---|
-x "<prompt>" | Headless (non-interactive) mode |
--dangerously-allow-all | Auto-approve tool calls; safe in sandbox isolation |
--stream-json | Output a real-time JSONL event stream (includes tool calls, token usage, reasoning, etc.) |
threads list --json | List current threads |
threads continue <id> | Continue on a specified thread |
Headless Execution
javascript
import { Sandbox } from 'e2b'
const sandbox = await Sandbox.create('amp', {
envs: { AMP_API_KEY: process.env.AMP_API_KEY },
})
const result = await sandbox.commands.run(
`amp --dangerously-allow-all -x "Create a hello world HTTP server in Go"`,
)
console.log(result.stdout)
await sandbox.kill()Git Repository Integration
javascript
await sandbox.git.clone('https://github.com/your-org/your-repo.git', {
path: '/home/user/repo',
username: 'x-access-token',
password: process.env.GITHUB_TOKEN,
depth: 1,
})
const result = await sandbox.commands.run(
`cd /home/user/repo && amp --dangerously-allow-all -x "Add error handling to all API endpoints"`,
{ onStdout: (data) => process.stdout.write(data) },
)
const diff = await sandbox.commands.run('cd /home/user/repo && git diff')
console.log(diff.stdout)Streaming JSON Output
--stream-json continuously outputs JSONL events, enabling real-time observation of token usage, tool calls, and decision-making:
javascript
const result = await sandbox.commands.run(
`amp --dangerously-allow-all --stream-json -x "Find and fix all TODO comments"`,
{
onStdout: (data) => {
for (const line of data.split('\n').filter(Boolean)) {
const event = JSON.parse(line)
if (event.type === 'assistant') {
console.log(`[assistant] tokens: ${event.message.usage?.output_tokens}`)
}
}
},
},
)Thread Management
Amp maintains persistent conversation threads that can be reused across multiple calls:
javascript
const initial = await sandbox.commands.run(
`cd /home/user/repo && amp --dangerously-allow-all -x "Analyze the codebase and create a refactoring plan"`,
)
const threads = await sandbox.commands.run('amp threads list --json')
const threadId = JSON.parse(threads.stdout)[0].id
const followUp = await sandbox.commands.run(
`cd /home/user/repo && amp threads continue ${threadId} --dangerously-allow-all -x "Now implement step 1 of the plan"`,
)References
- Amp website: https://ampcode.com