Hi @wsmoak
I think another valid solution would be: Delete-then-write via execute()
If you control the agent setup (e.g. you’re injecting the credentials before the agent starts running), this is the cleanest pattern imho:
sandbox.execute("rm -f /tmp/.git-credentials")
sandbox.write("/tmp/.git-credentials", credentials_content)
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.
If you feel strongly about this, I’d encourage you to open a feature request on the Deep Agents GitHub repo. The system prompt inconsistency alone could justify either:
- Adding an
overwrite: bool = Falseparameter towrite(), or - Updating the system prompt to accurately describe the create-only behavior