Skip to content

Next.js App (Bun) Example

Basic Next.js app with Tailwind and shadcn UI using Bun. Development server runs on port 3000 as soon as the sandbox is ready.

Template Definition (JavaScript/TypeScript):

typescript
// template.ts
import { Template, waitForURL } from 'e2b'

export const template = Template()
  .fromBunImage('1.3')
  .setWorkdir('/home/user/nextjs-app')
  .runCmd(
    'bun create next-app --app --ts --tailwind --turbopack --yes --use-bun .'
  )
  .runCmd('bunx --bun shadcn@latest init -d')
  .runCmd('bunx --bun shadcn@latest add --all')
  .runCmd(
    'mv /home/user/nextjs-app/* /home/user/ && rm -rf /home/user/nextjs-app'
  )
  .setWorkdir('/home/user')
  .setStartCmd('bun --bun run dev --turbo', waitForURL('http://localhost:3000'))

Build Configuration:

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

Template.build(nextJSTemplate, {
  alias: 'nextjs-app-bun',
  cpuCount: 4,
  memoryMB: 4096,
  onBuildLogs: defaultBuildLogger(),
})

E2B Documentation • Generated from e2b.dev/docs