FileSystem
File operations inside the sandbox.
FileSystem performs file operations inside a sandbox via the toolbox. Obtain it as sandbox.fs. All paths are paths inside the sandbox. See the files guide for a task-oriented walkthrough.
uploadFile()
Uploads a Buffer to a path inside the sandbox. The default timeout is generous (30 minutes) to accommodate large uploads.
| Parameter | Type | Default | Description |
|---|---|---|---|
file | Buffer | — | File contents. |
remotePath | string | — | Destination path inside the sandbox. |
timeout | number | 1800 | Request timeout in seconds. |
downloadFile()
Downloads a file's bytes from the sandbox.
Returns: the raw file contents as a Buffer.
listFiles()
Lists the entries of a directory.
Returns: FileInfo[] — { name, isDir, size, modTime?, mode?, permissions?, owner?, group? }.
getFileDetails()
Fetches info for a single file or directory.
createFolder()
Creates a folder at the given path with the given permission mode.
| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Directory to create. |
mode | string | — | Octal permission string, e.g. '755'. |
deleteFile()
Deletes a file at the given path.
moveFiles()
Moves (renames) a file or directory from source to destination.
findFiles()
Searches for text inside files under a path — grep-style. Compare searchFiles(), which matches file names.
Returns: Match[] — { file, line, content }.
searchFiles()
Searches for files whose names match a pattern under a path.
Returns: { files: string[] }.
replaceInFiles()
Replaces text across a set of files in one call.
| Parameter | Type | Default | Description |
|---|---|---|---|
files | string[] | — | Paths of files to edit. |
pattern | string | — | Pattern to replace. |
newValue | string | — | Replacement text. |
Returns: ReplaceResult[] — { file, success?, error? } per file.
setFilePermissions()
Sets permissions and/or ownership on a file. Any subset of mode, owner, and group may be provided in the params object.
| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Target file. |
permissions.mode | string | — | Octal permission string, e.g. '644'. |
permissions.owner | string | — | New owner user. |
permissions.group | string | — | New owner group. |