Skip to main content
// template.ts
import { Template } from 'e2b'

export const template = Template()
  .fromNodeImage('24')
  .aptInstall(['curl', 'git', 'ripgrep'])
  // Claude Code will be available globally as "claude"
  .npmInstall('-g @anthropic-ai/claude-code@latest')

// build.ts
import { Template, defaultBuildLogger } from 'e2b'
import { template as claudeCodeTemplate } from './template'

Template.build(claudeCodeTemplate, {
  alias: 'claude-code',
  cpuCount: 1,
  memoryMB: 1024,
  onBuildLogs: defaultBuildLogger(),
})
// sandbox.ts
import { Sandbox } from 'e2b'

const sbx = await Sandbox.create('claude-code', {
  envs: {
    ANTHROPIC_API_KEY: '<your api key>',
  },
})

console.log('Sandbox created', sbx.sandboxId)

// Print help for Claude Code
// const result = await sbx.commands.run('claude --help')
// console.log(result.stdout)

// Run a prompt with Claude Code
const result = await sbx.commands.run(
  `echo 'Create a hello world index.html' | claude -p --dangerously-skip-permissions`,
  { timeoutMs: 0 }
)

console.log(result.stdout)

sbx.kill()
I