Skip to content

Conversation

ymx10086
Copy link

@ymx10086 ymx10086 commented Sep 29, 2025

Sandbox for dbgpt code execute in future

Description

This PR introduces a sandbox environment for code execution in dbgpt, based on Docker containers.
It provides an asynchronous, multi-language, stateful execution environment that allows safe execution of untrusted code inside isolated Docker containers.

Key features:

  • Multi-language support: Python, JavaScript, Java, C++, Go, Rust, and VNC-based environments.
  • Asynchronous runtime: All Docker API calls are wrapped with asyncio.to_thread to avoid blocking the event loop.
  • Stateful sessions: Each session maps to a dedicated container with persistent working directory and environment.
  • Dependency installation: Supports runtime installation of Python (pip) and JavaScript (npm) dependencies.
  • File operations: Upload, download, and retrieve container file contents in base64 format.
  • Execution monitoring: Collects stdout, stderr, exit code, execution time, and container resource usage.
  • Session management: Lifecycle management (create, destroy, cleanup expired sessions).
  • VNC/NoVNC support: For interactive GUI-based languages/environments.
  • This lays the foundation for safe, reproducible, and extensible code execution in dbgpt.

How Has This Been Tested?

  • Start the Docker daemon and ensure required language images exist (python:3.11-slim, node:lts-slim, etc.).
  • Create a session via DockerRuntime.create_session.
  • Execute code (execute with Python/JS code).
  • install dependencies dynamically.
  • Fetch file content with get_file_content.
  • Run health_check to verify Docker runtime state.

Snapshots:

微信图片_20250929181524_29

Checklist:

  • My code follows the style guidelines of this project
  • I have already rebased the commits and make the commit message conform to the project standard.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • Any dependent changes have been merged and published in downstream modules

@ymx10086 ymx10086 closed this Sep 29, 2025
@ymx10086 ymx10086 deleted the dbgpt-sandbox branch September 29, 2025 13:38
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