Skip to main content
Manage files and directories within sandboxes through the fs module of Blaxel SDK. This module provides essential operations for creating, reading, writing, copying, and deleting files and directories.
Complete code examples demonstrating all operations are available on Blaxel’s GitHub: in TypeScript, in Python, and in Go.

Basic file system operations

The Blaxel SDK requires two environment variables to authenticate:
VariableDescription
BL_WORKSPACEYour Blaxel workspace name
BL_API_KEYYour Blaxel API key
You can create an API key from the Blaxel console. Your workspace name is visible in the URL when you log in to the console (e.g. app.blaxel.ai/{workspace}).Set them as environment variables or add them to a .env file at the root of your project:
The Blaxel SDK does not accept credentials as constructor arguments. Credentials must come from environment variables, a .env file, or a local CLI login session (see below).When developing locally, you can also log in to your workspace with Blaxel CLI (as shown above). This allows you to run Blaxel SDK functions that will automatically connect to your workspace without additional setup. When you deploy on Blaxel, authentication is handled automatically — no environment variables needed.

Create directory

Create a new directory at a specific path in the sandbox:

List files

List files in a specific path:

Find files and directories

Blaxel’s Sandbox API uses an optimized find() method, which is faster than using the native find tool.
Find files and directories matching specified patterns:

Search for text content within files

Blaxel’s Sandbox API uses an optimized grep() method, which is faster than using the native grep tool.
Find files containing specified text content:

Read file

Read a file from a specific filepath:

Write file

Create a file in a specific path:
See down below for how to upload/write a binary, or multiple files at once.

Write multiple files

You can write multiple files or directories simultaneously. The second path parameter in writeTree specifies the base directory for writing the file tree, eliminating the need to repeat the full path for each file.

Read binary file

Read a binary file from the sandbox filesystem:
The binary content is returned as a Web API Blob object.

Write binary file

Write binary content to a file in the sandbox filesystem:
The binary content to write can be provided as:
  • Buffer: Node.js Buffer object
  • Blob: Web API Blob object
  • File: Web API File object
  • Uint8Array: Typed array containing binary data
If you’re calling the sandbox filesystem API directly over HTTP instead of using an SDK, a single request is capped at 5 MB. Requests larger than this are rejected with an HTTP 413 before they reach the sandbox. Therefore, if using HTTP, larger files must be uploaded in parts via the sandbox’s multipart upload endpoints rather than in a single request. Blaxel SDKs handle this automatically: SDK functions like write(), writeBinary(), and write_binary() automatically split files over 5 MB and send via multipart upload in 5 MB chunks.

Download file to host

Download a file from the sandbox filesystem to the host:

Copy file

Copy a file from a path to another path:

Delete file or directory

Delete a file or directory by specifying its path:

Watch filesystem for events

The watch function monitors all file system changes in the specified directory. You can also watch subdirectories by passing a /my/directory/** pattern. By default (when withContent: false), the events will only include metadata about the changes, not the actual file contents. Here’s what you’ll get in the callback events:
  1. For ALL operations (CREATE, WRITE, DELETE, etc.), you’ll receive:
    1. op: The operation type (e.g., “CREATE”, “WRITE”, “DELETE”)
    2. path: The directory path where the change occurred
    3. name: The name of the file/directory that changed
  2. You will NOT receive:
    1. The actual content of the files
    2. File contents for CREATE or WRITE operations

Watch sub-directories

Watch all sub-directories recursively with /**:

Ignore files or directories

You can ignore changes in certain files or directories by providing an array of filepaths to ignore:
Specify withContent: true so the events include the actual file contents.
Last modified on July 10, 2026