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

# Read & Write files

## Reading files

You can use the `files.read()` method to read files from the sandbox filesystem.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Novita } from 'novita-sandbox'

  const novita = new Novita()
  const sandbox = await novita.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()
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox import Novita

  novita = Novita()
  sandbox = novita.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()
  ```
</CodeGroup>

## Writing single files

You can use the `files.write()` method to write single files to the sandbox filesystem.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Novita } from 'novita-sandbox'

  const novita = new Novita()
  const sandbox = await novita.codeInterpreter.create()

  const filePathInSandbox = '/tmp/test-file'

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

  await sandbox.kill()
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox import Novita

  novita = Novita()
  sandbox = novita.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()
  ```
</CodeGroup>

## Writing multiple files

You can also use the `files.write()` method to write multiple files to the sandbox filesystem.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Novita } from 'novita-sandbox'

  const novita = new Novita()
  const sandbox = await novita.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()
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox import Novita

  novita = Novita()
  sandbox = novita.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()
  ```
</CodeGroup>
