Skip to main content
The writeFile() method allows you to create or overwrite files inside your sandbox’s isolated filesystem. It supports both text and binary content, making it flexible enough for handling scripts, configuration files, and assets like images or compiled binaries. All file paths must begin with either the tilde (~) shortcut or the absolute sandbox path /home/damner/code.

writeFile(options)

Description: Writes a file to the sandbox filesystem. Supports both text and binary content. Parameters:
ParameterTypeRequiredDescription
pathstringYesFile path (must start with ~ or /home/damner/code)
contentstring | ArrayBufferYesFile content (text string or binary data)
Returns: Promise<void> - Resolves when write is complete Example:
// Text file
await sandbox.writeFile({
  path: '~/script.js',
  content: 'console.log("Hello World")'
})

// Multi-line content
await sandbox.writeFile({
  path: '~/config.json',
  content: JSON.stringify({
    name: 'my-app',
    version: '1.0.0'
  }, null, 2)
})
Path Handling:
// Valid paths
await sandbox.writeFile({ path: '~/file.txt', content: '...' })
await sandbox.writeFile({ path: '/home/damner/code/file.txt', content: '...' })
await sandbox.writeFile({ path: '~/nested/dir/file.txt', content: '...' })

// Invalid paths
await sandbox.writeFile({ path: '/tmp/file.txt', content: '...' })
await sandbox.writeFile({ path: 'relative/file.txt', content: '...' })
await sandbox.writeFile({ path: './file.txt', content: '...' })