DaytonaDocs

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.

TypeScript
uploadFile(file: Buffer, remotePath: string, timeout: number = 30 * 60): Promise<void>
ParameterTypeDefaultDescription
fileBufferFile contents.
remotePathstringDestination path inside the sandbox.
timeoutnumber1800Request timeout in seconds.
TypeScript
await sandbox.fs.uploadFile(Buffer.from('hello\n'), '/workspace/hello.txt')

downloadFile()

Downloads a file's bytes from the sandbox.

TypeScript
downloadFile(remotePath: string, timeout: number = 30 * 60): Promise<Buffer>

Returns: the raw file contents as a Buffer.

TypeScript
const data = await sandbox.fs.downloadFile('/workspace/report.pdf')
await fs.promises.writeFile('report.pdf', data)

listFiles()

Lists the entries of a directory.

TypeScript
listFiles(path: string): Promise<FileInfo[]>

Returns: FileInfo[]{ name, isDir, size, modTime?, mode?, permissions?, owner?, group? }.

getFileDetails()

Fetches info for a single file or directory.

TypeScript
getFileDetails(path: string): Promise<FileInfo>

createFolder()

Creates a folder at the given path with the given permission mode.

TypeScript
createFolder(path: string, mode: string): Promise<void>
ParameterTypeDefaultDescription
pathstringDirectory to create.
modestringOctal permission string, e.g. '755'.
TypeScript
await sandbox.fs.createFolder('/workspace/data', '755')

deleteFile()

Deletes a file at the given path.

TypeScript
deleteFile(path: string): Promise<void>

moveFiles()

Moves (renames) a file or directory from source to destination.

TypeScript
moveFiles(source: string, destination: string): Promise<void>

findFiles()

Searches for text inside files under a path — grep-style. Compare searchFiles(), which matches file names.

TypeScript
findFiles(path: string, pattern: string): Promise<Match[]>

Returns: Match[]{ file, line, content }.

TypeScript
const matches = await sandbox.fs.findFiles('/workspace', 'TODO')

searchFiles()

Searches for files whose names match a pattern under a path.

TypeScript
searchFiles(path: string, pattern: string): Promise<SearchFilesResponse>

Returns: { files: string[] }.

replaceInFiles()

Replaces text across a set of files in one call.

TypeScript
replaceInFiles(files: string[], pattern: string, newValue: string): Promise<ReplaceResult[]>
ParameterTypeDefaultDescription
filesstring[]Paths of files to edit.
patternstringPattern to replace.
newValuestringReplacement 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.

TypeScript
setFilePermissions(path: string, permissions: FilePermissionsParams): Promise<void>
ParameterTypeDefaultDescription
pathstringTarget file.
permissions.modestringOctal permission string, e.g. '644'.
permissions.ownerstringNew owner user.
permissions.groupstringNew owner group.
TypeScript
await sandbox.fs.setFilePermissions('/workspace/run.sh', { mode: '755' })

On this page