I’m using BaseSandbox.write() (via a custom DevPodBackend subclass) and running into an issue where write() fails when the target file already exists. The preflight check in _WRITE_CHECK_TEMPLATE (sandbox.py line 68) explicitly rejects existing files.
My use case: I need to write a git credentials file (/tmp/.git-credentials) into the sandbox before clone/pull operations. This file may already exist from a previous operation in the same sandbox session (e.g., when working with multiple repos, or when a sandbox is reused across invocations).
Currently I work around this by using execute() with printf … > /path to overwrite the file directly. This works, but it means the file content passes through shell arguments rather than the cleaner write() API path.
Would it be possible to add an overwrite parameter to BaseSandbox.write(), or a separate method like write_or_replace(), that skips the existence check? Alternatively, is there a recommended pattern for this kind of repeated-write scenario that I’m missing?
This keeps you on the write() API while handling the “may already exist” case. The -f flag means rm won’t fail if the file doesn’t exist.
Should an overwrite parameter be added?
As for me, yes.
There’s a reasonable argument for it. The write() method’s docstring says “Create a new file, failing if it already exists” - which is clear, but the system prompt shown to the agent says “Create or overwrite files” (system_prompt.md), creating a mismatch between what the LLM is told and what actually happens.