> ## Documentation Index
> Fetch the complete documentation index at: https://ppio.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Proxy 网络加速

PPIO Sandbox 可以提供 proxy 网络加速服务以访问github、huggingface等资源下载网站。我们将提供网络加速服务，不同[区域](/docs/sandbox/overview#区域)对应的加速服务地址如下，以方便进行 proxy 环境变量的设置。

| 区域名称          | 加速服务地址                     |
| ------------- | -------------------------- |
| cn-shanghai-1 | `http://10.1.80.46:1181`   |
| cn-beijing-1  | `http://10.97.197.11:1081` |

**被加速的域名：**

* github.com
* githubusercontent.com
* github.io
* githubassets.com
* huggingface.co

此环境变量默认不会注册到 Sandbox 中，需要人为手动注册。请根据所使用的[区域](/docs/sandbox/overview#区域)选择对应的加速服务地址，以下示例以 cn-shanghai-1 区域为例，若使用 cn-beijing-1 区域请将地址替换为 `http://10.97.197.11:1081`。

```bash theme={null}
export HTTP_PROXY=http://10.1.80.46:1181
export HTTPS_PROXY=http://10.1.80.46:1181
```

## 创建 Sandbox 时配置全局加速

在 create Sandbox 时会提供 env 环境变量的设置入口，在此设置环境变量会在整个 Sandbox 生命周期内生效。

```Python theme={null}
from ppio_sandbox import PPIO

ppio = PPIO()

sandbox = ppio.sandbox.create(envs={
    "http_proxy": "http://10.1.80.46:1181",
    "https_proxy": "http://10.1.80.46:1181",
})

result = sandbox.commands.run("curl ipinfo.io")

print(result.stdout)
```

## 运行指令是配置加速

若不想让此配置全局生效，也可以单独在执行某一条 bash 指令时设置环境变量。

```Python theme={null}
from ppio_sandbox import PPIO

ppio = PPIO()

sandbox = ppio.sandbox.create()

result = sandbox.commands.run("curl ipinfo.io", envs={
    "http_proxy": "http://10.1.80.46:1181",
    "https_proxy": "http://10.1.80.46:1181",
})

print(result.stdout)
```

## 运行代码时配置加速

Sandbox 提供了 Code Interpreter 的预设模板以快速执行 python 等脚本代码，这里也可以在执行代码时配置好环境变量。

```Python theme={null}
from ppio_sandbox import PPIO

ppio = PPIO()

sandbox = ppio.code_interpreter.create()

result = sandbox.run_code("""
import requests

res = requests.get("https://ipinfo.io")
print(res.json())
""", envs={
    "http_proxy": "http://10.1.80.46:1181",
    "https_proxy": "http://10.1.80.46:1181",
})

print(result.logs.stdout[0])
```
