A simple file system interface for managing files in sandboxes.
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.
Set up authentication to Blaxel
The Blaxel SDK authenticates with your workspace using credentials from these sources, in priority order:
.env
file (BL_WORKSPACE
and BL_API_KEY
, or see this page for other authentication options).When developing locally, the recommended method is to just log in to your workspace with Blaxel CLI. This allows you to run Blaxel SDK functions that will automatically connect to your workspace without additional setup. When you deploy on Blaxel, this connection persists automatically.
When running Blaxel SDK from a remote server that is not Blaxel-hosted, we recommend using environment variables as described in the third option above.
Create a new directory at a specific path in the sandbox:
List files in a specific path:
Read a file from a specific filepath:
Create a file in a specific path:
See down below for how to upload/write a binary, or multiple files at once.
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.
Write binary content to a file in the sandbox filesystem:
The binary content to write can be provided as:
Copy a file from a path to another path:
Delete a file or directory by specifying its path:
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:
Watch all sub-directories recursively with /**
:
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.
A simple file system interface for managing files in sandboxes.
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.
Set up authentication to Blaxel
The Blaxel SDK authenticates with your workspace using credentials from these sources, in priority order:
.env
file (BL_WORKSPACE
and BL_API_KEY
, or see this page for other authentication options).When developing locally, the recommended method is to just log in to your workspace with Blaxel CLI. This allows you to run Blaxel SDK functions that will automatically connect to your workspace without additional setup. When you deploy on Blaxel, this connection persists automatically.
When running Blaxel SDK from a remote server that is not Blaxel-hosted, we recommend using environment variables as described in the third option above.
Create a new directory at a specific path in the sandbox:
List files in a specific path:
Read a file from a specific filepath:
Create a file in a specific path:
See down below for how to upload/write a binary, or multiple files at once.
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.
Write binary content to a file in the sandbox filesystem:
The binary content to write can be provided as:
Copy a file from a path to another path:
Delete a file or directory by specifying its path:
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:
Watch all sub-directories recursively with /**
:
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.