Vibengine
Code Interpreter

Code Interpreter

Run code in a sandboxed environment with the Code Interpreter SDK

Code Interpreter

The Code Interpreter is a pre-built sandbox template optimized for running code. It provides a streamlined API for executing Python and JavaScript code with built-in support for chart generation, streaming output, and package installation.

Overview

The Code Interpreter is ideal when you need to:

  • Execute user-provided or AI-generated code safely
  • Run data analysis and visualization tasks
  • Stream output from long-running scripts in real-time
  • Generate charts and return them as images

The Code Interpreter is built on top of regular Vibengine sandboxes. You can always use the base Sandbox class for full control, but the Code Interpreter provides a higher-level API for common code execution tasks.

Installation

npm i vibengine
pip install vibengine

Quick Example

import { CodeInterpreter } from "vibengine";

const sandbox = await CodeInterpreter.create({
  apiKey: process.env.VE_API_KEY,
});

const execution = await sandbox.runCode("print(1 + 1)");
console.log(execution.text); // "2"

await sandbox.kill();
from vibengine import CodeInterpreter

sandbox = CodeInterpreter.create(api_key=os.environ["VE_API_KEY"])

execution = sandbox.run_code("print(1 + 1)")
print(execution.text)  # "2"

sandbox.kill()

Supported Languages

LanguageRuntimePackage Manager
PythonPython 3.11pip
JavaScriptNode.js 20npm

Features

Execution Results

Every code execution returns a result object containing:

  • text — The captured stdout output as a string
  • error — Error information if the execution failed
  • results — Rich output including charts and images
  • logs — Detailed stdout and stderr logs
const execution = await sandbox.runCode(`
import sys
print("Hello from stdout")
print("Error message", file=sys.stderr)
`);

console.log(execution.text);         // "Hello from stdout"
console.log(execution.logs.stderr);  // ["Error message"]
console.log(execution.error);        // null (no error)
execution = sandbox.run_code("""
import sys
print("Hello from stdout")
print("Error message", file=sys.stderr)
""")

print(execution.text)         # "Hello from stdout"
print(execution.logs.stderr)  # ["Error message"]
print(execution.error)        # None (no error)

Timeouts

You can set a timeout for code execution to prevent runaway scripts:

const execution = await sandbox.runCode("import time; time.sleep(60)", {
  timeoutMs: 5000, // 5 second timeout
});

if (execution.error) {
  console.log("Execution timed out:", execution.error.message);
}
execution = sandbox.run_code("import time; time.sleep(60)", timeout=5)

if execution.error:
    print("Execution timed out:", execution.error.message)

On this page