Skip to content

feat: add OpenSandbox as secure code execution backend#1710

Open
hellomypastor wants to merge 1 commit intoopeninterpreter:mainfrom
hellomypastor:feat/opensandbox-backend
Open

feat: add OpenSandbox as secure code execution backend#1710
hellomypastor wants to merge 1 commit intoopeninterpreter:mainfrom
hellomypastor:feat/opensandbox-backend

Conversation

@hellomypastor
Copy link
Copy Markdown

Describe the changes you have made:

Integrate [OpenSandbox](https://github.com/alibaba/OpenSandbox) as an optional secure code execution backend. When enabled, Python, Shell, and JavaScript code runs inside isolated containers instead of directly on the host machine.

New files:

  • interpreter/core/computer/terminal/languages/sandbox/sandbox_manager.py — Manages OpenSandbox lifecycle: lazy sandbox creation, per-language execution contexts, streaming output via queue-based generator (mirrors SubprocessLanguage pattern), interrupt support, and cleanup.
  • interpreter/core/computer/terminal/languages/sandbox/sandbox_language.pySandboxLanguage base class extending BaseLanguage, delegates execution to the shared SandboxManager.
  • interpreter/core/computer/terminal/languages/sandbox/__init__.py — Concrete subclasses: SandboxPython, SandboxShell, SandboxJavaScript.

Modified files:

  • terminal.py — Conditionally swaps Python/Shell/JavaScript handlers with sandbox variants when sandbox_mode=True; adds sandbox-aware instantiation in _streaming_run; skips local import_computer_api in sandbox mode; calls sandbox_manager.terminate() on cleanup.
  • core.py — Adds sandbox_mode, sandbox_api_key, sandbox_domain constructor parameters.
  • start_terminal_interface.py — Adds --sandbox, --sandbox_api_key, --sandbox_domain CLI arguments.
  • pyproject.toml — Adds opensandbox + opensandbox-code-interpreter as optional [sandbox] extras.

Usage:

# CLI
interpreter --sandbox --sandbox_api_key "your-key" --sandbox_domain "localhost:8080"

# Python API
interpreter.sandbox_mode = True
interpreter.sandbox_api_key = "your-key"
interpreter.sandbox_domain = "localhost:8080"

Design decisions:

  • Opt-in onlysandbox_mode defaults to False, zero impact on existing behavior.
  • Shared sandbox instance — A single SandboxManager owns one sandbox container; multiple languages share it via separate execution contexts, minimizing resource overhead.
  • Lazy initialization — Sandbox is created on first code execution, not at startup.
  • Graceful degradation — Unsupported languages (Ruby, R, AppleScript, etc.) continue using local execution even in sandbox mode. Missing SDK packages produce a clear ImportError message.

Reference any relevant issues (e.g. "Fixes #000"):

N/A

Pre-Submission Checklist (optional but appreciated):

  • I have included relevant documentation updates (stored in /docs)
  • I have read docs/CONTRIBUTING.md
  • I have read docs/ROADMAP.md

OS Tests (optional but appreciated):

  • Tested on Windows
  • Tested on MacOS
  • Tested on Linux

Integrate OpenSandbox SDK as an optional execution backend so that
Python, Shell and JavaScript code can run in isolated containers
instead of directly on the host machine.  Enabled via --sandbox flag
or interpreter.sandbox_mode = True.

New files:
- SandboxManager: owns sandbox lifecycle, streaming execution, contexts
- SandboxLanguage base + SandboxPython/Shell/JavaScript subclasses

Modified:
- Terminal: conditionally routes to sandbox language handlers
- OpenInterpreter: sandbox_mode, sandbox_api_key, sandbox_domain config
- CLI: --sandbox, --sandbox_api_key, --sandbox_domain arguments
- pyproject.toml: opensandbox optional dependency group

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant