zylon-ai/private-gpt · error · RuntimeError
Unable to create file
Error message
Unable to create file
What it means
RuntimeError from the create tool: session.create(path, file_text) returned success=False. Message is result.error when available, otherwise 'Unable to create file'. The session-side create fails on unwritable/invalid paths, existing files (providers commonly refuse to overwrite), or sandbox permission limits.
Source
Thrown at private_gpt/components/tools/builders/text_editor_tool_builder.py:181
},
),
)
async def build_create_tool(
self,
config: CodeExecutionSessionConfig,
name: str = TEXT_EDITOR_CREATE_TOOL_NAME,
type: str = TEXT_EDITOR_CREATE_TOOL_NAME + "_v1",
description: str = TEXT_EDITOR_CREATE_TOOL_FN.metadata.description,
) -> ToolSpec:
async def create(
path: str,
file_text: str,
) -> list[ResultContentBlockType]:
session = await self._session(config)
result = await session.create(path, file_text)
if not result.success:
raise RuntimeError(result.error or "Unable to create file")
return [TextEditorCodeExecutionCreateResultBlock(is_file_update=False)]
return ToolSpec.from_defaults(
name=name,
type=type,
runtime="server",
event_adapter=TextEditorCodeExecutionEventAdapter,
description=description,
async_fn=create,
requirements=[ToolRequirements.SANDBOX],
execution_metadata=build_rebuild_metadata(
rebuild_text_editor_create_tool,
{
"config": config,
"name": name,
"type": type,
"description": description,
},View on GitHub (pinned to 4a030776a3)
Solutions
- Check result.error in the exception message for the session's specific reason; if generic, wrap and log it.
- Ensure the parent directory exists (create it via bash tool or use an existing directory) and the path is within the sandbox workspace.
- If the file already exists, use the appropriate edit/replace command rather than create.
- Recreate the session if the TTL expired and retry.
Defensive patterns
Strategy: try-catch
Validate before calling
# before create: ensure it is a new file inside an existing directory
import posixpath
assert not path_exists_in_sandbox(path), f"{path} already exists; use an edit command"
assert posixpath.dirname(path), "create files inside an existing directory" Try / catch
try:
blocks = await create(path=path, file_text=text)
except RuntimeError as e:
detail = str(e) if str(e) != "Unable to create file" else "create failed without detail"
if "exists" in detail:
# switch to str_replace/edit flow instead of create
pass
raise Prevention
- Treat create as new-file-only; route edits through the replace/view commands.
- Create parent directories first (bash tool) for nested paths.
- Stay inside the sandbox's writable workspace directory.
When it happens
Trigger: Calling create for a path whose parent directory does not exist, a path that already exists (tool semantics are create-new, note is_file_update=False in the success block), or a location outside the sandbox's writable area.
Common situations: Agent calls create for a file that already exists instead of using an edit command; missing parent directories in deep paths; read-only mount in the sandbox container; expired session.
Related errors
- Unable to view file
- Unable to replace text
- Path '{canonical_path}' does not match any session mount.
- Code execution failed: {message}
- Execution failed: {result.error or 'Unknown error'}
AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15).
Data as JSON: /api/errors/eb4ab1097bf75b38.
Report an issue: GitHub.