Amp
Run Amp in a secure E2B sandbox with full filesystem, terminal, and git access.
Amp is a coding agent with multi-model architecture and built-in code intelligence. E2B provides a pre-built amp template with Amp already installed.
CLI
Create a sandbox with the E2B CLI.
e2b sbx create ampOnce inside the sandbox, start Amp.
ampRun headless
Use -x for non-interactive mode and --dangerously-allow-all to auto-approve all tool calls. The sandbox isolates the agent from your host machine, but sandboxes can reach the open internet by default — restrict outbound traffic with network rules. Amp uses its own API key from ampcode.com/settings.
Auto-approving tool calls is contained by the sandbox: the agent cannot touch your host machine, local files, or credentials. It can still make outbound network requests — internet access is enabled by default. To limit where an auto-approved agent can connect, configure outbound network rules (allowInternetAccess, plus allow/deny lists by CIDR or hostname). Hostname rules apply to HTTP(S) traffic only; use CIDR rules for other protocols.
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()Example: work on a cloned repository
import { Sandbox } from 'e2b'
const sandbox = await Sandbox.create('amp', {
envs: { AMP_API_KEY: process.env.AMP_API_KEY },
timeoutMs: 600_000,
})
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)
await sandbox.kill()Streaming JSON
Use --stream-json to get a real-time JSONL event stream with rich metadata — including tool calls, token usage, thinking blocks, and permission decisions.
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(
`cd /home/user/repo && 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}`)
} else if (event.type === 'result') {
console.log(`[done] ${event.message.subtype} in ${event.message.duration_ms}ms`)
}
}
},
}
)
await sandbox.kill()Thread management
Amp persists conversations as threads that can be resumed or continued with follow-up tasks.
import { Sandbox } from 'e2b'
const sandbox = await Sandbox.create('amp', {
envs: { AMP_API_KEY: process.env.AMP_API_KEY },
timeoutMs: 600_000,
})
// Start a new thread
const initial = await sandbox.commands.run(
`cd /home/user/repo && amp --dangerously-allow-all -x "Analyze the codebase and create a refactoring plan"`,
{ onStdout: (data) => process.stdout.write(data) }
)
// List threads and get the most recent thread ID
const threads = await sandbox.commands.run('amp threads list --json')
const threadId = JSON.parse(threads.stdout)[0].id
// Continue the thread with a follow-up task
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"`,
{ onStdout: (data) => process.stdout.write(data) }
)
const diff = await sandbox.commands.run('cd /home/user/repo && git diff')
console.log(diff.stdout)
await sandbox.kill()Build a custom template
If you need to customize the environment (e.g. pre-install dependencies, add config files), build your own template on top of the pre-built amp template.
// template.ts
import { Template } from 'e2b'
export const template = Template()
.fromTemplate('amp')// build.ts
import { Template, defaultBuildLogger } from 'e2b'
import { template as ampTemplate } from './template'
await Template.build(ampTemplate, 'my-amp', {
cpuCount: 2,
memoryMB: 2048,
onBuildLogs: defaultBuildLogger(),
})Run the build script to create the template.
npx tsx build.ts