e2b-dev / E2B

Secure cloud runtime for AI apps & AI agents. Fully open-source.
https://e2b.dev/docs
Apache License 2.0
6.32k stars 392 forks source link

sandbox.filesystem.rename() #386

Open jamesmurdza opened 2 weeks ago

jamesmurdza commented 2 weeks ago

Right now there is no method to move or rename a file or directory in a sandbox, like fs.rename.

I would suggest adding one. For example: rename(oldPath, newPath)

mlejva commented 2 weeks ago

Thanks @jamesmurdza! I think having fs.move(oldPath, newPath) that works for both files and dirs would make sense. @ValentaTomas we could add this to the new SDK we're working on. What do youthink?

jamesmurdza commented 1 week ago

That would be great! Much better than what I'm doing now:

const moveFile = async (filesystem: FilesystemManager, filePath: string, newFilePath: string) => {
  const fileContents = await filesystem.readBytes(filePath)
  await filesystem.writeBytes(newFilePath, fileContents);
  await filesystem.remove(filePath);
}
ValentaTomas commented 1 week ago

Sounds good — should be quick to add. I originally removed this from the new SDK proposal because I wanted to keep it minimal, but now seeing that @jamesmurdza already needs this validates it.

P.S. I think the workaround right now could be using process.startAndWait with mv command.

ValentaTomas commented 1 week ago

@jamesmurdza Are there any other operations that you had to use a workaround for?

jamesmurdza commented 1 week ago

@ValentaTomas Right, not sure why I'm not doing it that way now.

Yes, for the terminal SDK I'm using:

await terminal.sendData(`cd "${path}"\rclear\r`)

because

terminal.start({ ..., cwd: path }) doesn't set the working directory as expected.

However, I didn't create an issue for this because @mlejva mentioned you're already rewriting some of this.