If the current working directory for the sandbox is not set, it will default to the home directory - /home/user.
Copy
Ask AI
import { Sandbox } from 'e2b'const sandbox = await Sandbox.create({ template: 'base', cwd: '/code',})// You can also change the cwd of an existing sandboxsandbox.cwd = '/home'await sandbox.close()
All filesystem operations with relative paths are relative to the current working directory.
Copy
Ask AI
import { Sandbox } from 'e2b'const sandbox = await Sandbox.create({ template: 'base', cwd: '/home/user/code',})await sandbox.filesystem.write('hello.txt', 'Welcome to E2B!')const proc = await sandbox.process.start({ cmd: 'cat /home/user/code/hello.txt',})await proc.wait()console.log(proc.output.stdout)// output: "Welcome to E2B!"await sandbox.filesystem.write('../hello.txt', 'We hope you have a great day!')const proc2 = await sandbox.process.start({cmd: 'cat /home/user/hello.txt'})await proc2.wait()console.log(proc2.output.stdout)// output: "We hope you have a great day!"await sandbox.close()