> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/zh/xin/studio/unsloth-zhong-de-sha-he-ji-zhi.md).

# Unsloth 中的沙盒机制

Unsloth 在 Linux 上使用 bubblewrap，在 macOS 上使用 Seatbelt，在 Windows 上使用 MXC。

Unsloth 现在具备 OS 级沙箱，这意味着 Python 和 shell 命令可以在隔离的工作区中运行。Unsloth 有 2 种模式 - **“低”** 和 **“高”沙箱安全性** - 低模式采用 Unsloth 的软件沙箱方法，即对这些命令进行复杂的字符串、AST 和正则检查（禁用危险的 rm -rf、窃取 token 等）。高模式是真正的 OS 级沙箱，我们已为所有平台提供。

| 操作系统                                        | 沙箱软件                 | 每次调用的延迟 |
| ------------------------------------------- | -------------------- | ------- |
| <i class="fa-windows">:windows:</i> Windows | **MXC** （Windows 官方） | 164 毫秒  |
| <i class="fa-linux">:linux:</i> Linux       | Bubblewrap / Bwrap   | 50 毫秒   |
| <i class="fa-apple">:apple:</i> Mac         | Seatbelt（Mac 内置）     | 110 毫秒  |

要启用 OS 级沙箱：

* **Windows - MXC 已预装** 适用于 Windows 11 24H2 及更高版本。请选择 **高** 并在提示时按照设置说明操作。
* **Linux** - 需要安装 Bwrap - 请选择“高”，我们会为你安装
* **Mac - Seatbelt 已预装**，因此 Unsloth 会自动启用 Seatbelt

要检查 OS 沙箱是低还是高，请点击权限按钮：

<div align="left"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FBdWF0MbLoJLwTeFVhX7j%2FScreenshot%202026-10-08%20at%207.00.50%E2%80%AFAM.png?alt=media&amp;token=a592513a-9f45-4e0b-80d4-b8a6456e37ac" alt="" width="563"><figcaption></figcaption></figure></div>

如果你点击“了解更多”，你会进入沙箱设置页面，并且可以看到是否已启用软件沙箱，以及如何安装 bwrap、MXC：

<div align="left"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FfDEvjiXwBf1Fmftsp28q%2FScreenshot%202026-10-08%20at%206.56.34%E2%80%AFAM.png?alt=media&amp;token=b2c99b4c-67ea-4c50-bb98-4a710e0eafee" alt="" width="563"><figcaption></figcaption></figure></div>

对于这 3 个操作系统，你可以看到 OS 级沙箱是如何启用的：

{% columns %}
{% column %}
Windows：

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FLnxxpIwGpSjut6R6kLn8%2FScreenshot%202026-10-08%20at%206.53.26%E2%80%AFAM.png?alt=media&amp;token=85be4503-5279-4716-a1d0-1efbb8126129" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column %}
Mac：

<img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FRNZyuJL7xkrXJwYxofto%2FScreenshot%202026-10-08%20at%206.51.19%E2%80%AFAM.png?alt=media&amp;token=04ee3ff8-209c-41f6-bed2-8c64173ea77f" alt="" width="375">
{% endcolumn %}

{% column %}
Linux：

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FesfsF7INvYB1MpIQF3cn%2FScreenshot%202026-10-08%20at%206.53.20%E2%80%AFAM.png?alt=media&amp;token=33f9f7cd-df4e-4e74-89c4-0c482c64e3c5" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column width="50%" %}
你可以看到沙箱的实际效果，它会阻止访问工作区之外的内容：

### 沙箱延迟

我们对软件和硬件 OS 级沙箱做了大量优化，但 OS 级沙箱确实会带来一些延迟。见下表：
{% endcolumn %}

{% column width="50%" %}
![](https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FcyBycXfercRlu0iEttel%2Fnew%20sandbox.png?alt=media\&token=d9064a88-e5c8-4e1d-a261-e93f20739ea6)
{% endcolumn %}
{% endcolumns %}

| 操作系统                                        | 沙箱软件                 | 低沙箱   | 高沙箱    |
| ------------------------------------------- | -------------------- | ----- | ------ |
| <i class="fa-windows">:windows:</i> Windows | **MXC** （Windows 官方） | 8 毫秒  | 164 毫秒 |
| <i class="fa-linux">:linux:</i> Linux       | Bubblewrap / Bwrap   | 3 毫秒  | 50 毫秒  |
| <i class="fa-apple">:apple:</i> Mac         | Seatbelt（Mac 内置）     | 10 毫秒 | 110 毫秒 |

{% columns %}
{% column %}

### 禁用沙箱 / 绕过权限 / 完全访问

要禁用沙箱（包括软件低沙箱和 OS 级高沙箱），只需按“完全访问”，此时 Unsloth 就可以在没有任何限制的情况下访问你的整个电脑。
{% endcolumn %}

{% column %}

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F6YpMXm0gOsM7lPaygu4T%2FScreenshot%202026-10-08%20at%206.45.21%E2%80%AFAM.png?alt=media&amp;token=b7f308f5-ac0b-4852-9eeb-961e6cc575ef" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

### 软件沙箱方法

Unsloth 的软件沙箱是一堆正则表达式、字符串检查等——我们大约会增加 **1-2 毫秒的额外延迟** 每次工具调用，并且我们会阻止以下内容：

* 删除和磁盘工具： `rm、dd、mkfs、fdisk、mount、umount`
* 权限与提权：chmod、 `chown、sudo、su、doas、pkexec、passwd`
* 网络： `curl、wget、nc、ncat、netcat、socat、ssh、scp、sftp、rsync`
* 进程和电源： `kill、killall、pkill、shutdown、reboot、halt、poweroff`
* 在不被看见的情况下运行另一个脚本的内容： `eval、source`
* 仅限 Windows： `rmdir、takeown、icacls、runas、powershell、pwsh`

Python 代码，在运行前读取代码：

* Shell 转义： `os.system`，以及 `subprked` 命令，或非字面量命令（例如通过 su 执行 pip install）
* 网络调用： `requests、urllib`，原始套接字连接
* 某些敏感的系统读取，例如 `/etc/passwd`
* 操纵信号或超时以规避它们。

适用于两种模式下的每一次调用：

* 会清除秘密环境变量。
* 会拒绝 Studio 自己的凭据文件
* 对进程数、文件大小（100 MB）、内存（8 GB）和 CPU 时间（600 秒）的限制，因此 fork bomb 会触发进程限制，以及调用超时

#### Windows MXC 合作

感谢 Windows 团队与 Unsloth 合作，让 MXC 在 Unsloth 中运行良好！ [见此处](https://blogs.windows.com/windowsexperience/2026/10/07/building-windows-for-hybrid-intelligence/) 查看发布博文

#### 在 Unsloth 中获得沙箱功能

只需将 Unsloth 更新到最新版本，你就会获得沙箱功能！


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/zh/xin/studio/unsloth-zhong-de-sha-he-ji-zhi.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
