Watch sandbox directory for changes

You can watch a directory for changes using the files.watchDir() method in JavaScript and files.watch_dir() method in Python.

import { Sandbox, FilesystemEventType } from '@e2b/code-interpreter'

const sandbox = await Sandbox.create()
const dirname = '/home/user'

// Start watching directory for changes
const handle = await sandbox.files.watchDir(dirname, async (event) => { 
  console.log(event) 
  if (event.type === FilesystemEventType.WRITE) { 
    console.log(`wrote to file ${event.name}`) 
  } 
}) 

// Trigger file write event
await sandbox.files.write(`${dirname}/my-file`, 'hello')