Skip to main content
Use the runCode/run_code method to run JavaScript and TypeScript code inside the sandbox. You’ll need to pass the language parameter with value javascript or js for JavaScript and typescript or ts for TypeScript.
The E2B Code Interpreter supports TypeScript, top-level await, ESM-style imports and automatic promises resolution.
import { Sandbox } from "@e2b/code-interpreter";

// Create a new sandbox
const sbx = await Sandbox.create();

// Install the axios package
await sbx.commands.run("npm install axios");

// Run the code
const execution = await sbx.runCode(`
  import axios from "axios";

  const url: string = "https://api.github.com/status";
  const response = await axios.get(url);
  response.data;
`,
  { language: "ts" }
);

console.log(execution);

// Execution {
//   results: [],
//   logs: {
//     stdout: [ "{ message: 'GitHub lives! (2025-05-28 10:49:55 -0700) (1)' }\n" ],
//     stderr: [],
//   },
//   error: undefined,
//   executionCount: 1,
//   text: [Getter],
//   toJSON: [Function: toJSON],
// }
I