OpenSandbox README

项目的 README,来自 github.com/opensandbox-group/OpenSandbox。合并为一个 markdown 文件:README.md。

OpenSandbox logo

OpenSandbox

An Agentic AI Foundation (AAIF) Project

Latest Release Stars OpenSSF Best Practices Discord DingTalk Regression Test Status Full-Stack Test Status


Run AI agents in sandboxes on your own infrastructure.

OpenSandbox gives AI applications isolated environments to execute code, run commands, manage files, and operate browsers or desktops. Start locally with Docker and deploy on Kubernetes through a unified sandbox API.

Website · Quick Start · SDKs · Examples · Kubernetes · Fast Sandbox · Documentation

Features

Feature What it enables Learn more
Fast Sandbox runtime Fast, high-density Firecracker + OverlayBD sandboxes on Kubernetes: 65.3 ms P50 (serial) / 70.9 ms P50 (16 concurrent) create (t_api_ack), up to 800 concurrent live MicroVMs per Fastlet, ~10.2 MiB Firecracker PSS (~17.5 MiB host memory delta) per 2 GiB sandbox, and full memory + disk pause/resume. Integration · Benchmarks · Pause/resume
Multi-tier isolation & hardening Run workloads in standard containers or VM-isolated runtimes (Kata, confidential PeerPods), with default-on execd init mode, opt-in privilege reduction, and isolated in-sandbox sessions. Secure containers · Isolated sessions · Hardening
Agent working environments Execute commands, manage files, and run code with built-in APIs, or host coding agents, browsers, and full desktops inside sandboxes. Examples
Lifecycle, pools, and auto-pause Start locally with Docker and scale on Kubernetes through one lifecycle API, with warm client pools (including Redis coordination), snapshots, and idle auto-pause with wake-on-access. Kubernetes · Client Pool · Auto-pause
Network access control Route inbound traffic through a unified ingress gateway and enforce per-sandbox outbound policies or upstream proxy forwarding. Ingress · Egress · Forward mode
Credential Vault Let agents call external services through outbound TLS credential injection without exposing real credentials to sandbox workloads. Credential Vault
SDKs, CLI, MCP, and Console Integrate with Python, Java/Kotlin, TypeScript/JavaScript, C#/.NET, or Go SDKs; operate sandboxes from the osb CLI, MCP clients, or the optional Developer Console. SDKs · CLI · MCP · Console
Extensible sandbox protocol Build custom runtime integrations against defined OpenAPI contracts for lifecycle, execution, egress, and diagnostics. API specs

Architecture

OpenSandbox Architecture Overview

OpenSandbox separates lifecycle orchestration (FastAPI server + Docker, Kubernetes, or Fast Sandbox backends), direct data-plane execution (execd, workload ports, and optional ingress gateway), and outbound security controls (egress policy enforcement and Credential Vault). See the Architecture Overview for component boundaries and request flows.

Getting Started

Requirements:

Install and Configure the Sandbox Server

uvx opensandbox-server init-config ~/.sandbox.toml --example docker

# Start the local server. Because example.config.toml leaves server.api_key unset,
# type YES at the startup prompt (or pass OPENSANDBOX_INSECURE_SERVER=YES in
# non-interactive shells; if you set server.api_key in ~/.sandbox.toml, also
# export OPEN_SANDBOX_API_KEY=<your-api-key> for client calls).
uvx opensandbox-server

# Show help
# uvx opensandbox-server -h

Create a Sandbox and Execute Commands/Scripts

Save the script below as quickstart.py:

import asyncio

from opensandbox import Sandbox
from opensandbox.models import WriteEntry

async def main() -> None:
    # 1. Create a sandbox from the alpine image
    sandbox = await Sandbox.create("alpine")

    try:
        # 2. Execute a shell command
        execution = await sandbox.commands.run("echo 'Hello OpenSandbox!'")
        print(execution.logs.stdout[0].text)

        # 3. Write a script file
        await sandbox.files.write_files([
            WriteEntry(
                path="/tmp/hello.sh",
                data="echo \"Hello $1\"\necho '2 + 2 =' $((2 + 2))",
                mode=755,
            )
        ])

        # 4. Read the file back
        content = await sandbox.files.read_file("/tmp/hello.sh")
        print(f"Content: {content}")

        # 5. Execute the script
        execution = await sandbox.commands.run("sh /tmp/hello.sh OpenSandbox")
        for log in execution.logs.stdout:
            print(log.text)

    finally:
        # 6. Cleanup the sandbox
        await sandbox.destroy()

if __name__ == "__main__":
    asyncio.run(main())

Run it directly in an ephemeral environment with uv (no manual virtualenv setup required):

# If server.api_key is configured, export OPEN_SANDBOX_API_KEY=<your-api-key> first
uv run --with opensandbox python quickstart.py

Examples

Explore examples by what you want your agent to do. Runnable source code lives in examples/.

Use case What you can build Examples
Coding agents Run coding agents and frameworks in isolated environments to edit files, execute commands, and complete development tasks. Claude Code · Gemini CLI · Codex CLI · LangGraph · DeerFlow
Code execution and data analysis Execute model-generated code and work with results through the Code Interpreter SDK. Code Interpreter
Browser, desktop, and IDEs Automate web interactions and testing, or give agents and developers access to a browser IDE or desktop environment. Playwright · Chrome · Desktop · VS Code
Agent evaluation Run evaluations with a separate sandbox for each trial. Harbor Evaluation

See the full example catalog for more coding agents, framework integrations, remote development environments, Kubernetes deployment, and storage patterns.

SDKs

Pick your language:

Python
pip install opensandbox
Java/Kotlin (Gradle Kotlin DSL)
dependencies {
    implementation("com.alibaba.opensandbox:sandbox:{latest_version}")
}
Java/Kotlin (Maven)
<dependency>
    <groupId>com.alibaba.opensandbox</groupId>
    <artifactId>sandbox</artifactId>
    <version>{latest_version}</version>
</dependency>
JavaScript/TypeScript
npm install @alibaba-group/opensandbox
C#/.NET
dotnet add package Alibaba.OpenSandbox
Go
go get github.com/alibaba/OpenSandbox/sdks/sandbox/go

CLI

OpenSandbox also provides osb, a terminal CLI for the common sandbox workflow: create sandboxes, run commands, move files, inspect diagnostics, and manage runtime egress policy.

Install:

pip install opensandbox-cli
# or
uv tool install opensandbox-cli

Quick start:

osb config init
osb config set connection.domain localhost:8080
osb config set connection.protocol http
# Required when server.api_key is configured (omit for local no-auth testing):
# osb config set connection.api_key <your-api-key>

osb sandbox create --image python:3.12 --timeout 30m -o json
osb command run <sandbox-id> -o raw -- python -c "print(1 + 1)"
osb sandbox kill <sandbox-id> -o json

See the CLI README for the full command reference.

MCP

The OpenSandbox MCP server exposes sandbox creation, command execution, and text file operations to MCP-capable clients such as Claude Code and Cursor.

Install and run:

pip install opensandbox-mcp
opensandbox-mcp --domain localhost:8080 --protocol http

Minimal stdio config:

{
  "mcpServers": {
    "opensandbox": {
      "command": "opensandbox-mcp",
      "args": ["--domain", "localhost:8080", "--protocol", "http"]
    }
  }
}

See the MCP README for client-specific setup.

Official Container Images

OpenSandbox release images are published under the same component name in three official registries:

Pin production images by digest and check the release verification guide for signing coverage before deployment. Legacy per-component releases support Cosign signatures and provenance attestations; current umbrella releases have a tracked signing and provenance gap and must not be assumed to provide the same verification evidence.

Documentation

Contact and Discussion

About

OpenSandbox is a project of the Agentic AI Foundation (AAIF), governed under its Technical Charter and Project Governance (see Maintainers).

Code is licensed under the Apache 2.0 License. See the contribution guide for documentation licensing and contribution terms, and SECURITY.md for vulnerability reporting.

OpenSandbox (opensandbox-group/OpenSandbox)

正在搜索数据库…

这是什么?OpenSandbox 是一个面向 AI 应用的通用沙箱平台,提供多语言 SDK、统一的沙箱 API,以及 Docker/Kubernetes 运行时,适用于编程智能体、GUI 智能体、智能体评测、AI 代码执行和强化学习训练等场景。
这是我可以导入的库,还是我需要运行的服务器?两者都是:一个基于 Python FastAPI 的沙箱生命周期服务器,你可以用 Docker 在本地部署,也可以在 Kubernetes 上大规模部署;另外还有 Python、Java/Kotlin、JS/TS、C#/.NET 和 Go 的 SDK、一个 'osb' 命令行工具,以及一个 MCP 服务器,它们都与该服务器通信。
我该如何让沙箱跑起来?安装 Docker 和 Python 3.10+,启动 OpenSandbox 服务器,然后使用 Code Interpreter SDK 创建沙箱并执行命令或代码;同样的流程也可以扩展到 Kubernetes 运行时,以实现分布式调度。
试用它需要 Kubernetes 吗?不需要,仅靠 Docker 就能在本地运行沙箱。只有高性能、大规模的分布式运行时才需要 Kubernetes。
沙箱与宿主机之间的隔离程度如何?在标准 Docker/Kubernetes 容器之上,OpenSandbox 还支持 gVisor、Kata Containers 和 Firecracker microVM 等安全运行时,以便在沙箱工作负载与宿主机之间提供更强的隔离。
沙箱内部如何保证 API 密钥和机密信息的安全?凭据保险库(Credential Vault)会把凭据注入到沙箱的出站请求中,而不会向工作负载内运行的代码暴露真实的密钥值。
哪些编程智能体可以通过 MCP 服务器连接?MCP 服务器向支持 MCP 的客户端开放沙箱创建、命令执行和文件操作功能,例如 Claude Code 和 Cursor。
我可以在沙箱内运行 GUI 或基于浏览器的智能体吗?可以,内置示例包括带 VNC 和 DevTools 访问的 Chromium 沙箱、Playwright 无头浏览器自动化,以及可通过 VNC 访问的完整桌面环境。
官方容器镜像发布在哪里?镜像发布在 Docker Hub、GitHub Container Registry 和 Alibaba Cloud Container Registry 上,通过 Cosign 进行无密钥签名,并附带来源证明(provenance attestations)。
osb 命令行工具是做什么的?osb 是 OpenSandbox 的终端命令行工具,用于常见的沙箱工作流:创建沙箱、运行命令、传输文件、查看诊断信息,以及管理运行时的出站流量策略。
有哪些类似的项目?daytona, substrate, strix, ax, labtether, smolvm, astron-rpa, arcbox
大小
122.6 MB
星标
18K
时长
11个月
提交 · 90 天