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

# 文件下载

export const SandboxConfigHint = () => {
  if (typeof document === "undefined") {
    return null;
  } else {
    return <Note>在运行本文档中的示例代码前，请确保您已正确配置环境变量，详情请参考 <a href="/sandbox/get-start#配置环境变量">配置环境变量</a>。</Note>;
  }
};

我们可以将文件从沙箱内下载到本地。

<SandboxConfigHint />

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={null}
  import fs from 'fs'
  import { Sandbox } from 'ppio-sandbox/code-interpreter'

  const sandbox = await Sandbox.create()

  // 在沙箱内创建一个文件用于测试
  const filePathInSandbox = '/tmp/test-file'
  await sandbox.files.write(filePathInSandbox, "test-file-content")

  // 从沙箱读取文件内容
  const content = await sandbox.files.read(filePathInSandbox)

  // 将文件写入本地文件系统
  const localFilePath = './local-test-file'
  fs.writeFileSync(localFilePath, content)

  await sandbox.kill()
  ```

  ```python Python icon="python" theme={null}
  from ppio_sandbox.code_interpreter import Sandbox

  sandbox = Sandbox.create()

  # 在沙箱内创建一个文件用于测试
  file_path_in_sandbox = '/tmp/test-file'
  sandbox.files.write(file_path_in_sandbox, "test-file-content")

  # 从沙箱读取文件内容
  content = sandbox.files.read(file_path_in_sandbox)

  # 将文件内容写入本地文件系统
  local_file_path = './local-test-file'
  with open(local_file_path, 'w') as file:
    file.write(content)

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