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

# API 秘钥

在执行 SDK 代码之前请配置好`PPIO_API_KEY`环境变量，或者在代码中显式指定 API Key。

你可以在 PPIO [API 密钥管理页面](https://ppio.com/settings/key-management)创建一个 API key，并妥善保存以备后用。

<Note>
  **安全提醒**
  请妥善保管您的 API Key，不要在代码中硬编码或提交到版本控制系统。建议使用环境变量或密钥管理服务。
</Note>

## 方式一：使用环境变量（推荐）

推荐通过环境变量配置 API Key，SDK 会自动读取 `PPIO_API_KEY` 环境变量。这种方式可以避免在代码中暴露敏感信息，适合在生产环境中使用。

**设置环境变量**

<CodeGroup>
  ```python Python theme={null}
  from ppio_sandbox import PPIO

  # SDK 会自动从环境变量 PPIO_API_KEY 读取
  ppio = PPIO()

  sandbox = ppio.sandbox.create()
  ```

  ```javascript JavaScript & TypeScript theme={null}
  import { PPIO } from 'ppio-sandbox'

  const ppio = new PPIO()

  // SDK 会自动从环境变量 PPIO_API_KEY 读取
  const sandbox = await ppio.sandbox.create();
  ```

  ```bash CLI theme={null}
  export PPIO_API_KEY=sk_your_api_key_here
  ```
</CodeGroup>

## 方式二：在代码中显式指定

也可以在创建 Sandbox 时直接传入 API Key。这种方式适合在开发测试环境中使用，但**不推荐在生产环境中使用**，因为会在代码中暴露敏感信息。

<CodeGroup>
  ```python Python theme={null}
  from ppio_sandbox import PPIO

  # 显式传入 API Key（不推荐用于生产环境）
  ppio = PPIO(api_key="sk_your_api_key_here")

  sandbox = ppio.sandbox.create()

  print(f"Sandbox ID: {sandbox.sandbox_id}")
  print(f"状态: {sandbox.get_info().state}")
  ```

  ```javascript JavaScript & TypeScript theme={null}
  import { PPIO } from 'ppio-sandbox'

  // 显式传入 API Key（不推荐用于生产环境）
  const ppio = new PPIO({
    apiKey: 'sk_your_api_key_here'
  })

  const sandbox = await ppio.sandbox.create();

  console.log(`Sandbox ID: ${sandbox.sandboxId}`);
  console.log(`状态: ${(await sandbox.getInfo()).state}`);
  ```
</CodeGroup>
