Skip to content

Run Python

Python is the default Code Interpreter language. Variables and imports remain available in the same context between calls.

mjs
const sandbox = await Sandbox.create("code-interpreter");

try {
  const execution = await sandbox.runCode("sum([2, 3, 5])");
  console.log(execution.text);
} finally {
  await sandbox.kill();
}

execution.text contains the text representation of the last expression. Printed output is available separately in execution.logs.stdout.