mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-04-05 14:58:37 +07:00
---
title: DifySandbox
---
### 介绍
`DifySandbox` 是一个轻量、快速、安全的代码运行环境,支持多种编程语言,包括 `Python`、`Nodejs` 等,用户在 `Dify Workflow` 中使用到的如 `Code` 节点、`Template Transform` 节点、`LLM` 节点的 Jinja2 语法、`Tool` 节点的 `Code Interpreter` 等都基于 DifySandbox 运行,它确保了 `Dify` 可以运行用户代码的前提下整个系统的安全性。
### 特性
- **多语言支持**:`DifySandbox` 基于 `Seccomp`,这是一个系统层级的解决方案,从而确保了可以支持多种编程语言,目前支持了 `Python` 与 `Nodejs`。
- **系统安全**:使用白名单策略,只允许运行特定的系统调用,从而确保不会出现意外的绕过。
- **文件系统隔离**:用户代码将运行在一个独立的隔离的文件系统中。
- **网络隔离**:
- **DockerCompose**:独立网络 Sandbox 网络,并使用代理容器进行网络访问,确保内网系统的安全,同时提供了灵活的代理配置方案。
- **K8s**:直接使用 `Egress` 配置网络隔离策略即可。
### 安装依赖
在安装和部署 DifySandbox 项目前,请确保你的系统满足以下依赖要求:
1. **系统依赖**
根据 Linux 发行版,执行相应的命令安装必要的系统组件:
- Ubuntu/Debian
```bash
sudo apt-get update
sudo apt-get install pkg-config gcc libseccomp-dev git wget
```
- CentOS
```bash
sudo yum install pkgconfig gcc libseccomp-devel git wget
```
2. **Go 语言环境**
需要安装 Go 开发环境(建议 Go 1.20.6 或更高版本):
```bash
# 安装 Go 1.21
sudo apt-get install -y golang-1.20.6
```
验证安装:
```bash
go version # 显示安装的 Go 版本
```
3. **Python 环境配置**
**Sandbox 环境准备**
建议安装 Python 3.10 或以上版本。
**预装依赖管理**
DifySandbox 已预先配置了以下 Python 依赖:
- `http` - 基础网络请求库
- `jinja2` - 模板引擎,用于 LLM 提示词处理
- `requests` - HTTP 客户端库
**添加自定义依赖**
若需要额外的 Python 依赖,请遵循以下步骤
1. 找到项目根目录下的 `dependencies/python-requirements.txt` 文件。
2. 在文件中添加所需的依赖包名及版本。若涉及权限变更,请参考[常见问题](https://github.com/langgenius/dify-sandbox/blob/main/FAQ.md)。
3. 重新构建 DifySandbox。
<Warning>
添加新依赖可能引入额外权限需求,请谨慎评估安全影响。若未能完全掌控潜在安全风险,不建议更改权限配置。
</Warning>
### 贡献
你可以参考 [贡献指南](contribution) 来参与到 `DifySandbox` 的开发中。
{/*
Contributing Section
DO NOT edit this section!
It will be automatically generated by the script.
*/}
---
[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/zh-hans/development/backend/sandbox/README.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)