mirror of
https://github.com/langgenius/dify-docs-archived.git
synced 2026-07-01 20:35:52 -04:00
Docs: update sandbox (#733)
* Docs: update sandbox * Docs: update sandbox * Update README.md --------- Co-authored-by: Hanqing Zhao <sherry9277@gmail.com>
This commit is contained in:
@@ -1,18 +1,78 @@
|
||||
# DifySandbox
|
||||
|
||||
### Introduction
|
||||
`DifySandbox` is a lightweight, fast, and secure code execution environment that supports multiple programming languages, including Python and Node.js. It serves as the underlying execution environment for various components in Dify Workflow, such as the Code node, Template Transform node, LLM node, and the Code Interpreter in the Tool node. DifySandbox ensures system security while enabling Dify to execute user-provided code.
|
||||
|
||||
`DifySandbox` is a lightweight, fast, and secure code execution environment that supports multiple programming languages, including Python and Node.js. It serves as the underlying execution environment for various components in Dify Workflow, such as the Code node, Template Transform node, Jinja2 syntax in LLM nodes, and the Code Interpreter in Tool nodes. DifySandbox ensures system security while enabling Dify to execute user-provided code.
|
||||
|
||||
### Features
|
||||
- **Multi-language Support**: DifySandbox is built on Seccomp, a low-level security mechanism that enables support for multiple programming languages. Currently, it supports Python and Node.js.
|
||||
- **Multi-language Support**: DifySandbox is built on Seccomp, a system-level solution that enables support for multiple programming languages. Currently, it supports Python and Node.js.
|
||||
- **System Security**: It implements a whitelist policy, allowing only specific system calls to prevent unexpected security breaches.
|
||||
- **File System Isolation**: User code runs in an isolated file system environment.
|
||||
- **Network Isolation**:
|
||||
- **DockerCompose**: Utilizes a separate Sandbox network and proxy containers for network access, maintaining intranet system security while offering flexible proxy configuration options.
|
||||
- **K8s**: Network isolation strategies can be directly configured using Egress policies.
|
||||
|
||||
### Project Repository
|
||||
You can access the [DifySandbox](https://github.com/langgenius/dify-sandbox) repository to obtain the project source code and follow the project documentation for deployment and usage instructions.
|
||||
### Installation Dependencies
|
||||
|
||||
Before installing and deploying the DifySandbox project, ensure your system meets the following dependency requirements:
|
||||
|
||||
1. **System Dependencies**
|
||||
|
||||
Execute the appropriate commands based on your Linux distribution to install necessary system components:
|
||||
|
||||
- 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 Environment**
|
||||
|
||||
Install Go development environment (recommended Go 1.20.6 or higher):
|
||||
|
||||
```bash
|
||||
# Install Go 1.20.6
|
||||
sudo apt-get install -y golang-1.20.6
|
||||
```
|
||||
|
||||
Verify installation:
|
||||
|
||||
```bash
|
||||
go version # Displays the installed Go version
|
||||
```
|
||||
|
||||
3. **Python Environment Configuration**
|
||||
|
||||
**Sandbox Environment Preparation**
|
||||
|
||||
Python 3.10 or higher is recommended.
|
||||
|
||||
**Pre-installed Dependency Management**
|
||||
|
||||
DifySandbox comes pre-configured with the following Python dependencies:
|
||||
|
||||
- `http` - Basic networking library
|
||||
- `jinja2` - Template engine for LLM prompt processing
|
||||
- `requests` - HTTP client library
|
||||
|
||||
**Adding Custom Dependencies**
|
||||
|
||||
If you need additional Python dependencies, follow these steps:
|
||||
|
||||
1. Locate the `dependencies/python-requirements.txt` file in the project root directory.
|
||||
2. Add the required package names and versions to the file. If permission changes are involved, refer to the [FAQ](https://github.com/langgenius/dify-sandbox/blob/main/FAQ.md).
|
||||
3. Rebuild DifySandbox.
|
||||
|
||||
|
||||
> Adding new dependencies may introduce additional permission requirements. Please carefully evaluate security implications. Do not change permission configurations if you cannot fully assess the potential security risks.
|
||||
|
||||
### Contribution
|
||||
Please refer to the [Contribution Guide](contribution.md) to learn how you can participate in the development of DifySandbox.
|
||||
|
||||
You can refer to the [Contribution Guide](contribution) to participate in the development of `DifySandbox`.
|
||||
|
||||
@@ -1,15 +1,79 @@
|
||||
`DifySandbox(ディファイサンドボックス)`は、PythonやNode.jsなど複数のプログラミング言語に対応した、軽量・高速・安全なコード実行環境です。Dify Workflowの様々な要素(コードノード、テンプレート変換ノード、LLMノード、ツールノードのコードインタプリターなど)の基盤となる実行環境として機能します。DifySandboxは、ユーザーが提供したコードを実行しつつ、システムのセキュリティを確保します。
|
||||
# DifySandbox
|
||||
|
||||
### はじめに
|
||||
|
||||
`DifySandbox(ディファイサンドボックス)`は、`Python`や`Node.js`など複数のプログラミング言語に対応した、軽量・高速・安全なコード実行環境です。`Difyワークフロー`に関する様々な要素(`コードノード`、`テンプレートノード`、`LLMノード`のJinja2構文、`ツールノード`の`コードインタプリター`など)の基盤となる実行環境として機能します。DifySandboxは、ユーザーが提供したコードを実行しつつ、システム全体のセキュリティを確保します。
|
||||
|
||||
### 特徴
|
||||
- **複数言語対応**:DifySandboxはSeccompをベースに構築され、複数のプログラミング言語をサポートする低レベルのセキュリティ機構を実現しています。現在はPythonとNode.jsに対応しています。
|
||||
- **システムセキュリティ**:予期せぬセキュリティ侵害を防ぐため、特定のシステムコールのみを許可する許可リストポリシーを採用しています。
|
||||
- **ファイルシステムの隔離**:ユーザーのコードは独立したファイルシステム環境で実行されます。
|
||||
- **ネットワーク隔離**:
|
||||
- **DockerCompose環境**:専用のSandboxネットワークとプロキシコンテナを使用してネットワークアクセスを提供します。これにより、内部ネットワークのセキュリティを保ちつつ、柔軟なプロキシ設定が可能になります。
|
||||
- **Kubernetes環境**:Egressポリシーを用いて直接ネットワーク隔離戦略を設定できます。
|
||||
- **多言語サポート**: `DifySandbox`は、システムレベルのソリューションである`Seccomp`(システムコールを制限するLinuxカーネルのセキュリティ機能)を基盤として構築されており、複数のプログラミング言語に対応しています。現在、PythonとNode.jsをサポートしています。
|
||||
- **システムセキュリティ**: 特定のシステムコールのみを許可するホワイトリスト方式を採用し、予期せぬセキュリティ侵害を防止します。
|
||||
- **ファイルシステムの分離**: ユーザーコードは、ユーザーごとに隔離されたファイルシステム環境で実行されます。
|
||||
- **ネットワーク分離**:
|
||||
- **Docker Compose環境**: 専用のSandboxネットワークとプロキシコンテナを活用してネットワークアクセスを制御し、内部システムのセキュリティを維持しつつ、柔軟なプロキシ設定オプションを提供します。
|
||||
- **Kubernetes(K8s)環境**: Egressポリシーを使用してネットワーク分離の設定を直接行うことが可能です。
|
||||
|
||||
### プロジェクトリポジトリ
|
||||
プロジェクトのソースコードの入手や、導入・使用方法に関する詳細な情報については、[DifySandbox](https://github.com/langgenius/dify-sandbox)リポジトリをご覧ください。
|
||||
### 依存関係のインストール
|
||||
|
||||
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.20.6をインストール
|
||||
sudo apt-get install -y golang-1.20.6
|
||||
```
|
||||
|
||||
インストールを確認します:
|
||||
|
||||
```bash
|
||||
go version # インストールされたGoバージョンを表示
|
||||
```
|
||||
|
||||
3. **Python環境設定**
|
||||
|
||||
**サンドボックス環境の準備**
|
||||
|
||||
Python 3.10以上を推奨します。
|
||||
|
||||
**事前インストール済みの依存関係管理**
|
||||
|
||||
DifySandboxには以下のPython依存関係があらかじめ設定されています:
|
||||
|
||||
- `http` - 基本的なネットワークライブラリ
|
||||
- `jinja2` - LLMプロンプト処理用のテンプレートエンジン
|
||||
- `requests` - HTTPクライアントライブラリ
|
||||
|
||||
**カスタム依存関係の追加**
|
||||
|
||||
追加のPython依存関係が必要な場合は、以下の手順に従ってください:
|
||||
|
||||
1. プロジェクトのルートディレクトリにある`dependencies/python-requirements.txt`ファイルを見つけます。
|
||||
2. 必要なパッケージ名とバージョンをファイルに追加します。権限変更が必要な場合は、[FAQ](https://github.com/langgenius/dify-sandbox/blob/main/FAQ.md)を参照してください。
|
||||
3. DifySandboxを再構築します。
|
||||
|
||||
<Warning>
|
||||
新しい依存関係を追加すると、追加の権限要件が発生する可能性があります。セキュリティへの影響を慎重に評価してください。潜在的なセキュリティリスクを完全に制御できない場合は、権限設定を変更しないことをお勧めします。
|
||||
</Warning>
|
||||
|
||||
### 貢献
|
||||
`DifySandbox`の開発に参加する方法については、[貢献ガイド](contribution.md)をご参照ください。
|
||||
|
||||
`DifySandbox`の開発に参加する方法については、[貢献ガイド](contribution)をご参照ください。
|
||||
|
||||
@@ -1,18 +1,78 @@
|
||||
# DifySandbox
|
||||
|
||||
### 介绍
|
||||
`DifySandbox`是一个轻量、快速、安全的代码运行环境,支持多种编程语言,包括`Python`、`Nodejs`等,用户在`Dify Workflow`中使用到的如`Code`节点、`Template Transform`节点、`LLM`节点的Jinja2语法、`Tool`节点的`Code Interpreter`等都基于DifySandbox运行,它确保了`Dify`可以运行用户代码的前提下整个系统的安全性。
|
||||
|
||||
`DifySandbox` 是一个轻量、快速、安全的代码运行环境,支持多种编程语言,包括 `Python`、`Nodejs` 等,用户在 `Dify Workflow` 中使用到的如 `Code` 节点、`Template Transform` 节点、`LLM` 节点的 Jinja2 语法、`Tool` 节点的 `Code Interpreter` 等都基于 DifySandbox 运行,它确保了 `Dify` 可以运行用户代码的前提下整个系统的安全性。
|
||||
|
||||
### 特性
|
||||
- **多语言支持**:`DifySandbox`基于`Seccomp`,这是一个系统层级的解决方案,从而确保了可以支持多种编程语言,目前支持了`Python`与`Nodejs`。
|
||||
- **多语言支持**:`DifySandbox` 基于 `Seccomp`,这是一个系统层级的解决方案,从而确保了可以支持多种编程语言,目前支持了 `Python` 与 `Nodejs`。
|
||||
- **系统安全**:使用白名单策略,只允许运行特定的系统调用,从而确保不会出现意外的绕过。
|
||||
- **文件系统隔离**:用户代码将运行在一个独立的隔离的文件系统中。
|
||||
- **网络隔离**:
|
||||
- **DockerCompose**:独立网络Sandbox网络,并使用代理容器进行网络访问,确保内网系统的安全,同时提供了灵活的代理配置方案。
|
||||
- **K8s**:直接使用`Egress`配置网络隔离策略即可。
|
||||
- **DockerCompose**:独立网络 Sandbox 网络,并使用代理容器进行网络访问,确保内网系统的安全,同时提供了灵活的代理配置方案。
|
||||
- **K8s**:直接使用 `Exgress` 配置网络隔离策略即可。
|
||||
|
||||
### 项目地址
|
||||
你可以直接访问[DifySandbox](https://github.com/langgenius/dify-sandbox)获取项目源码,并遵循项目文档进行部署和使用。
|
||||
### 安装依赖
|
||||
|
||||
在安装和部署 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。
|
||||
|
||||
|
||||
> 添加新依赖可能引入额外权限需求,请谨慎评估安全影响。若未能完全掌控潜在安全风险,不建议更改权限配置。
|
||||
|
||||
### 贡献
|
||||
你可以参考[贡献指南](contribution.md)来参与到`DifySandbox`的开发中。
|
||||
|
||||
你可以参考 [贡献指南](contribution) 来参与到 `DifySandbox` 的开发中。
|
||||
|
||||
Reference in New Issue
Block a user