Skip to content
Agentmart
Submit a tool

code-sandbox

Secure sandboxed code execution for AI-generated scripts.

Skill by malue-ai

IndexedMIT★ 37
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/malue-ai-code-sandbox

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Secure sandboxed code execution for AI-generated scripts. Runs Python/JS in isolated environments (Docker or E2B) to protect the user's system.

Use cases: devops

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/code-sandbox

What's inside

Skill name
code-sandbox
Description
Secure sandboxed code execution for AI-generated scripts. Runs Python/JS in isolated environments (Docker or E2B) to protect the user's system.
License
MIT
Instructions
174 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# 安全代码沙箱

在隔离的沙箱环境中执行 AI 生成的代码,保护用户系统安全。支持 Docker 本地沙箱(免费)和 E2B 云沙箱两种模式。

## 使用场景

- 用户说「帮我写个脚本分析这个 CSV 文件」→ 在沙箱中执行,不污染主系统
- 用户说「帮我画个图表」→ matplotlib 在沙箱中运行,输出图片文件
- 用户说「运行一下这段代码看看结果」→ 安全隔离执行
- 数据分析、原型验证、临时脚本等不适合在主系统直接执行的场景
- 执行来历不明或复杂度高的代码片段

## 何时使用此 Skill(而非直接 system.run)

```
判断逻辑:

需要执行代码
  ├── 简单系统命令(ls, git, pip 等) → 直接 system.run
  ├── 用户提供的完整脚本 → code-sandbox ✅ 更安全
  ├── AI 生成的分析/处理代码 → code-sandbox ✅ 推荐
  ├── 需要安装额外依赖的代码 → code-sandbox ✅ 不污染主环境
  └── 需要网络访问的爬虫/API 调用 → code-sandbox ✅ 隔离风险
```

## 前置条件(二选一)

### 方式一:Docker 本地沙箱(推荐,免费)

1. 安装 Docker:https://www.docker.com/get-started
2. 确保 Docker 正在运行:`docker info`
3. 无需额外配置,首次使用时自动拉取基础镜像

### 方式二:E2B 云沙箱

1. 注册 E2B 账号:https://e2b.dev/
2. 设置环境变量:`export E2B_API_KEY="your-key"`
3. 提供免费额度,适合不想装 Docker 的用户

## 执行方式

### Docker 本地沙箱模式

#### 执行 Python 脚本

```python
import asyncio
import tempfile
import os

async def run_in_sandbox(code: str, files: dict = None, timeout: int = 60):
    """在 Docker 沙箱中执行 Python 代码"""

    # 创建临时工作目录
    work_dir = tempfile.mkdtemp(prefix="sandbox_")

    # 写入用户代码
    script_path = os.path.join(work_dir, "script.py")
    with open(script_path, "w") as f:
        f.write(code)

    # 如果有输入文件,复制到工作目录
    if files:
        for name, content in files.items():
            fpath = os.path.join(work_dir, name)
            if isinstance(content, bytes):
                with open(fpath, "wb") as f:
                    f.write(content)
            else:
                with open(fpath, "w") as f:
                    f.write(content)

    # Docker 执行命令
    cmd = [
        "docker", "run", "--rm",
        "--network=none",               # 默认禁用网络(需要时可开启)
        "--memory=512m",                 # 内存限制
        "--cpus=1.0",                    # CPU 限制
        "-v", f"{work_dir}:/workspace",  # 挂载工作目录
        "-w", "/workspace",
        "python:3.12-slim",
        "python", "script.py"
    ]

    proc = await asyncio.create_subprocess_exec(
        *cmd,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE,
    )
    stdout, stderr = await asyncio.wait_for(
        proc.communicate(), timeout=timeout
    )

    return {
        "success": proc.returncode == 0,
        "stdout": stdout.decode(),
        "stderr": stderr.decode(),
        "output_dir": work_dir,  # 检查输出文件
    }
```

#### 带依赖安装的执行

```python
async def run_with_deps(code: str, packages: list, files: dict = None):
    """安装依赖后执行"""
    pip_install = " ".join(packages)
    wrapper = f"""
import subprocess, sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", {', '.join(repr(p) for p in packages)}])

{code}
"""
    return await run_in_sandbox(wrapper, files, timeout=120)
```

### E2B 云沙箱模式

```python

From malue-ai/dazee-small, MIT.

More from malue-ai/dazee-small

Signals

Stars
37
Forks
2
Open issues
3
Last commit (this folder)
Feb 26, 2026 (8 months ago)
Last release
Feb 26, 2026 (8 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from malue-ai

Cite this page

code-sandbox skill. Agent Mart. https://agentmart.dev/skills/malue-ai-code-sandbox (last updated 2026-10-24)