FileWriterTool
Description
FileWriterTool writes text content to a file. Missing directories are created
automatically. The default text encoding is UTF-8.
Writes are confined to a sandbox directory. By default that directory is the
current working directory. Pass base_dir to change it.
Installation
Example
Code
Arguments
The agent supplies these at runtime:filename: Name of the file to write, relative todirectory. May include subdirectories. Those subdirectories are created if they do not exist.content: Text content to write.directory(optional): Directory to write into. A relative path resolves inside the tool’s allowed directory (base_dirwhen set, otherwise the current working directory) and defaults to that directory’s root (./). Created if it does not exist.overwrite(optional): Whether to replace an existing file. Accepts a boolean or the stringsy/yes/t/true/on/1andn/no/f/false/off/0. Defaults tofalse. Whenfalseand the file already exists, the tool returns an error and does not modify the file.
base_dir(optional): Directory that writes must stay inside. Defaults to the current working directory. A relative path is resolved when the tool is constructed, so a later change of working directory does not move the sandbox.encoding(optional): Text encoding used to write the file. Defaults toutf-8.
Allowed paths
Runtimedirectory and filename values are usually chosen by an LLM. The
tool rejects paths that escape the sandbox:
- The resolved
directorymust be insidebase_dir(the current working directory by default). - The resolved file path must be inside that
directory. ..segments, absolute paths, and symlinks are resolved before both checks.
base_dir:
Code
Previously, an absolute
directory could write anywhere the process had
permission. If you relied on that, set base_dir to the tree you want to
allow. Setting CREWAI_TOOLS_ALLOW_UNSAFE_PATHS=true restores the old
behavior, but it disables path and URL checks process-wide for every
crewai-tools tool. Prefer base_dir.