Running your first Sandbox
This guide will show you how to start your first E2B Sandbox.
Create E2B account
Every new E2B account get $100 in credits. You can sign up here.
Set your environment variables
- Navigate to the E2B Dashboard.
- Copy your API key.
- Paste your E2B API key into your .env file.
E2B_API_KEY=e2b_***Install E2B SDK
Install the E2B SDK to your project by running the following command in your terminal.
npm i @e2b/code-interpreter dotenvWrite code for starting sandbox
We’ll write the minimal code for starting Sandbox, executing Python inside it and listing all files inside the root directory.
// index.ts
import 'dotenv/config'
import { Sandbox } from '@e2b/code-interpreter'
const sbx = await Sandbox.create() // Creates a persistent sandbox session
const execution = await sbx.runCode('print("hello world")') // Execute Python inside the sandbox
console.log(execution.logs)
const files = await sbx.files.list('/')
console.log(files)Start your first E2B sandbox
Run the code with the following command:
npx tsx ./index.tsWas this page helpful?Suggest editsRaise issue