devbox.fs to transfer files between the local machine and a Devbox, read and write bytes, and manage remote files and directories.
Filesystem operations start a stopped Devbox automatically. Relative remote paths are passed unchanged to the Devbox’s SFTP or command session. Use absolute paths when the location must be unambiguous. The SDK caches the connection and SFTP channel for reuse.
fs.upload()
Upload one local file to the Devbox. This method does not upload directories.
Example
API reference
Arguments and options
A path on the machine running the SDK. Relative paths resolve from that process’s current working directory.
fs.download()
Download one remote file to the local filesystem. This method does not download directories.
Example
API reference
Arguments and options
A local destination path. Relative paths resolve from the SDK process’s current working directory.
fs.copy()
Copy a file or directory within the Devbox. The operation invokes remote cp and rejects when it exits unsuccessfully.
Example
API reference
Arguments and options
fs.read()
Read a remote file, or a byte range within it, as UTF-8 text, buffered bytes, or a stream. Use the stream format for large files so the contents are not buffered in memory.
Example
API reference
Arguments and options
Invalidformat values reject with a TypeError. Invalid offset or length values, or a range that exceeds the maximum safe integer, reject with a RangeError.
Return value
Astring, Uint8Array, or ReadableStream<Uint8Array>, depending on format.
More examples
Read a byte range
Stream a large file
fs.readFile()
Read an entire remote file into memory as raw bytes. The SDK does not decode its contents. Use fs.read() to read text, a byte range, or a stream.
Example
API reference
Arguments and options
Return value
AUint8Array containing the file’s unmodified bytes.
fs.writeFile()
Write a string or raw bytes to a remote file. The file is created or truncated. Strings are written as UTF-8.
Example
API reference
Arguments and options
fs.exists()
Check whether a remote file, directory, or other filesystem object exists.
Example
API reference
Arguments and options
Return value
false only when the SFTP server reports that the path does not exist. Other failures reject the promise.
fs.rename()
Rename or move a file or directory within the Devbox.
Example
API reference
Arguments and options
fs.mkdir()
Create a remote directory, optionally creating each missing parent directory.
Example
API reference
Arguments and options
fs.remove()
Remove a remote file or directory. Without recursion, directories must be empty.
Example
API reference
Arguments and options
fs.readdir()
List the immediate children of a remote directory. It does not recurse and excludes . and ...
Example
API reference
Arguments and options
Return value
"symlink", not as the type of their target.
Errors and cancellation
All methods reject with the abort signal’s reason, or anAbortError, when cancelled. A finite, non-negative timeoutMs covers activation, connection, and the requested operation. Expiration rejects with DevboxTimeoutError. Invalid timeout values reject with RangeError; SFTP, transport, permission, and missing-path failures otherwise surface as their underlying errors. copy() and recursive remove() reject with Error when the remote command fails.
See Handle errors and timeouts for shared error handling guidance.