Manage files and directories within sandboxes through theDocumentation Index
Fetch the complete documentation index at: https://docs.blaxel.ai/llms.txt
Use this file to discover all available pages before exploring further.
fs module of Blaxel SDK. This module provides essential operations for creating, reading, writing, copying, and deleting files and directories.
Basic file system operations
Learn more about authentication on Blaxel
Learn more about authentication on Blaxel
The Blaxel SDK requires two environment variables to authenticate:
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. The Blaxel SDK does not accept credentials as constructor arguments. Credentials must come from environment variables, a
| Variable | Description |
|---|---|
BL_WORKSPACE | Your Blaxel workspace name |
BL_API_KEY | Your Blaxel API key |
app.blaxel.ai/{workspace}).Set them as environment variables or add them to a .env file at the root of your project:.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.Search for text content within files
Blaxel’s Sandbox API uses an optimized
grep() method, which is faster than using the native grep tool.Read file
Read a file from a specific filepath:Write file
Create a file in a specific path:Write multiple files
You can write multiple files or directories simultaneously. The second path parameter inwriteTree 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:Write binary file
Write binary content to a file in the sandbox filesystem:- Buffer: Node.js Buffer object
- Blob: Web API Blob object
- File: Web API File object
- Uint8Array: Typed array containing binary data
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
Thewatch 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:
- For ALL operations (CREATE, WRITE, DELETE, etc.), you’ll receive:
- op: The operation type (e.g., “CREATE”, “WRITE”, “DELETE”)
- path: The directory path where the change occurred
- name: The name of the file/directory that changed
- You will NOT receive:
- The actual content of the files
- 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:withContent: true so the events include the actual file contents.