Skip to main content

Code Execution

VoidRun provides powerful code execution capabilities inside isolated MicroVMs. Execute shell commands, run scripts, or use the built-in code interpreter for multi-language code execution.
For a single reference of every shell and process path (sync exec, streaming, commands.*, runCode, PTY, session-exec), see Shell execution.

The Code Interpreter

VoidRun includes a built-in code interpreter that allows you to execute code in multiple programming languages without manually setting up runtimes. The interpreter handles:
  • Multiple languages: Python, JavaScript/Node.js, TypeScript, Bash
  • Automatic setup: Temporary files and cleanup are handled automatically
  • Output parsing: Results are parsed and returned in a structured format
  • Streaming support: Real-time output for long-running code

🐍 Python

Full Python 3 runtime with pip package installation support.

📦 JavaScript

Node.js runtime for executing JavaScript and TypeScript code.

🖥️ Shell

Bash shell for system commands and scripting.

Running Commands

Basic Command Execution

Execute any shell command inside the sandbox:

Running Python Code

Use the code interpreter to run Python code:

Running JavaScript/Node.js Code

Execute JavaScript code with the Node.js runtime:

Running Bash Scripts

Execute shell commands and scripts:

Handling Output

Response Structure

Every execution returns a structured response with stdout, stderr, and exit code:

Code Interpreter Response

The code interpreter returns additional structured data:

Streaming Output

For long-running commands, use streaming to get real-time output:

Execution Options

Timeout

Set execution timeouts to prevent hanging commands:
The default timeout is 30 seconds. For long-running commands, explicitly set a higher timeout value.

Working Directory

Execute commands in a specific directory:

Environment Variables

Pass custom environment variables to commands:

Background Processes

Run long-running processes in the background:

Best Practices

Security: Never execute untrusted user input directly. Always sanitize and validate code before execution. Consider using allowlists for acceptable commands.

Error Handling

Always handle execution errors gracefully:

Next Steps

File System

Learn how to upload, download, and manage files in sandboxes.

Custom Images

Create custom Docker images with pre-installed dependencies.