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

# Read and write files

> Read a file from the sandbox filesystem with files.read(), and write one file or several files in a single call with files.write() in Python or Node.js.

The SDK reads and writes sandbox files through the `files` module. The read example first writes a test file to `/tmp/test-file`, then reads it back.

> [!NOTE]
>
> Install the SDK, or the CLI for `ppio` commands, and set the `PPIO_API_KEY` and `PPIO_DOMAIN` environment variables before running these examples. See [Quickstart](https://docs.ppio.ai/sandbox/quickstart.md) and [Install and authenticate](https://docs.ppio.ai/sandbox/cli/install.md).

## Read a file

Call `files.read()` to read a file from the sandbox filesystem.

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

ppio = PPIO()
sandbox = ppio.code_interpreter.create()

file_path_in_sandbox = '/tmp/test-file'
sandbox.files.write(file_path_in_sandbox, 'test-file-content')

file_content = sandbox.files.read(file_path_in_sandbox)
print(file_content)

sandbox.kill()
```

```javascript Node.js theme={null}
// index.mts
import { PPIO } from 'ppio-sandbox'

const ppio = new PPIO()
const sandbox = await ppio.codeInterpreter.create()

// Create a file in the sandbox for testing
const filePathInSandbox = '/tmp/test-file'
await sandbox.files.write(filePathInSandbox, 'test-file-content')

const fileContent = await sandbox.files.read(filePathInSandbox)
console.log(fileContent)

await sandbox.kill()
```

## Write a single file

Call `files.write()` to write a single file to the sandbox filesystem.

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

ppio = PPIO()
sandbox = ppio.code_interpreter.create()

file_path_in_sandbox = '/tmp/test-file'
result = sandbox.files.write(file_path_in_sandbox, 'test-file-content')
print(result)

sandbox.kill()
```

```javascript Node.js theme={null}
// index.mts
import { PPIO } from 'ppio-sandbox'

const ppio = new PPIO()
const sandbox = await ppio.codeInterpreter.create()

const filePathInSandbox = '/tmp/test-file'

const result = await sandbox.files.write(filePathInSandbox, 'test-file-content')
console.log(result)

await sandbox.kill()
```

## Write multiple files

`files.write()` also writes several files in one call. Pass a list of path and data pairs.

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

ppio = PPIO()
sandbox = ppio.code_interpreter.create()

result = sandbox.files.write_files([
    {"path": "/tmp/test-file-1", "data": "file content 1"},
    {"path": "/tmp/test-file-2", "data": "file content 2"},
])
print(result)

sandbox.kill()
```

```javascript Node.js theme={null}
// index.mts
import { PPIO } from 'ppio-sandbox'

const ppio = new PPIO()
const sandbox = await ppio.codeInterpreter.create()

const result = await sandbox.files.write([
  { path: '/tmp/test-file-1', data: 'file content 1' },
  { path: '/tmp/test-file-2', data: 'file content 2' },
])

console.log(result)

await sandbox.kill()
```


## Related topics

- [Work with files in a sandbox](https://docs.ppio.ai/sandbox/filesystem/overview.md)
- [Build a template with the CLI](https://docs.ppio.ai/sandbox/templates/build-cli.md)
- [Download files from a sandbox](https://docs.ppio.ai/sandbox/filesystem/download.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.