> ## 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.

# E2B 兼容

PPIO Agent 沙箱服务提供了 E2B 兼容的 API，如果您已经在使用 E2B 沙箱并希望切换到 PPIO Agent 沙箱，您可以使用特定版本的 E2B SDK 和 CLI 来操控 PPIO Agent 沙箱。当然，我们建议使用 PPIO [Agent Sandbox SDK](/sandbox/sandbox-sdk-and-cli) 来访问所有功能。

## 安装

### Code Interpreter SDK

<CodeGroup>
  ```bash JavaScript & TypeScript icon="terminal" theme={null}
  npm i @e2b/code-interpreter@beta
  ```

  ```bash Python icon="terminal" theme={null}
  pip install e2b-code-interpreter==1.2.0b5
  ```
</CodeGroup>

### Core SDK

<CodeGroup>
  ```bash JavaScript & TypeScript icon="terminal" theme={null}
  npm i e2b@beta
  ```

  ```bash Python icon="terminal" theme={null}
  pip install e2b==1.2.0b6
  ```
</CodeGroup>

### Desktop SDK

<CodeGroup>
  ```bash JavaScript & TypeScript icon="terminal" theme={null}
  npm i @e2b/desktop@beta
  ```

  ```bash Python icon="terminal" theme={null}
  pip install e2b-desktop==1.7.1b1
  ```
</CodeGroup>

### CLI

<CodeGroup>
  ```bash Bash icon="terminal" theme={null}
  npm i -g @e2b/cli@v1.9.2
  ```
</CodeGroup>

## 配置环境变量

您需要在运行代码前设置如下环境变量，来指定使用 PPIO Agent 沙箱服务。

```bash Bash icon="terminal" theme={null}
export E2B_DOMAIN=sandbox.ppio.cn
export E2B_API_KEY="<Your PPIO API Key>"
```

## 示例

下面示例展示了如何通过 E2B SDK 来操控 PPIO Agent 沙箱。

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={null}
  import { Sandbox } from '@e2b/code-interpreter'
  // or import { Sandbox } from 'e2b'
  // or import { Sandbox } from '@e2b/desktop'

  const sbx = await Sandbox.create()
  const execution = await sbx.commands.run('ls -l')
  console.log(execution)

  await sbx.kill()
  ```

  ```python Python icon="python" theme={null}
  from e2b_code_interpreter import Sandbox
  # or from e2b import Sandbox
  # or from e2b_desktop import Sandbox

  sbx = Sandbox.create()
  execution = sbx.commands.run('ls -l')
  print(execution)

  sbx.kill()
  ```
</CodeGroup>

下面示例展示了如何使用 E2B CLI 来操控 PPIO Agent 沙箱。

<CodeGroup>
  ```bash Bash icon="terminal" theme={null}
  export E2B_DOMAIN=sandbox.ppio.cn
  # Authentication in CLI
  e2b auth login

  # Start sandbox and connect to terminal
  e2b sandbox spawn <template-id>

  # List sandboxes
  e2b sandbox list

  # Shutdown running sandboxes
  e2b sandbox kill <sandbox-id>
  ```
</CodeGroup>
