Security Model
PicoClaw implements a multi-layered security model for filesystem access:- Sandboxed mode (
restrict=true): Operations are confined to the workspace directory usingos.Root - Unrestricted mode (
restrict=false): Direct host filesystem access - Path whitelisting: Allow specific paths outside the workspace even in sandboxed mode
- Symlink protection: Validates that symlinks don’t escape the workspace
- Atomic writes: All write operations use atomic file writes with explicit sync for data durability
read_file
Read the contents of a file from the filesystem.Parameters
Path to the file to read. Can be absolute or relative to the workspace.
Returns
The complete contents of the file as a string.
Error Handling
- Returns error if file does not exist:
"failed to read file: file not found" - Returns error if permission denied:
"failed to read file: access denied" - Returns error if path is outside workspace (in sandboxed mode):
"access denied: path is outside the workspace"
Usage Example
Implementation Notes
- In sandboxed mode, paths are validated against the workspace boundary
- Symlinks are resolved and checked to prevent workspace escape
- Relative paths are resolved relative to the workspace directory
write_file
Write content to a file, creating parent directories if needed.Parameters
Path to the file to write. Will be created if it doesn’t exist.
Content to write to the file.
Returns
Confirmation message:
"File written: {path}"Safety Features
- Atomic writes: Uses temporary file + rename to ensure atomic operations
- Explicit sync: Calls
fsync()before rename to ensure data is physically written - Parent directory creation: Automatically creates parent directories in sandboxed mode
- Secure permissions: Files are created with 0600 (owner read/write only)
Usage Example
Implementation Notes
The atomic write process:- Create temporary file with unique name (
.tmp-{pid}-{timestamp}) - Write content to temporary file
- Call
Sync()to flush to disk - Rename temporary file to target path (atomic operation)
- Sync parent directory to ensure rename is durable
list_dir
List files and directories in a specified path.Parameters
Path to the directory to list. Defaults to current directory if empty.
Returns
Formatted list of directory entries, one per line:
- Directories:
"DIR: {name}" - Files:
"FILE: {name}"
Usage Example
edit_file
Edit a file by replacing old text with new text. The old text must match exactly.Parameters
The file path to edit.
The exact text to find and replace. Must appear exactly once in the file.
The text to replace with.
Returns
Confirmation message:
"File edited: {path}"Error Handling
- If
old_textis not found:"old_text not found in file. Make sure it matches exactly" - If
old_textappears multiple times:"old_text appears {count} times. Please provide more context to make it unique"
Usage Example
Best Practices
- Include enough context in
old_textto make it unique - Preserve exact whitespace and formatting
- For multiple replacements, use multiple edit operations
- Consider using
read_filefirst to verify the exact text
append_file
Append content to the end of a file.Parameters
The file path to append to. Will be created if it doesn’t exist.
The content to append.
Returns
Confirmation message:
"Appended to {path}"Usage Example
Implementation Notes
- If file doesn’t exist, creates it with the appended content
- Uses atomic write operations for safety
- Does not add automatic newlines - include
\nin content if needed
Path Resolution
All filesystem tools follow consistent path resolution rules:Absolute Paths
- Used as-is
- Validated against workspace in sandboxed mode
Relative Paths
- Resolved relative to workspace directory
- Automatically prefixed with workspace path
Path Validation
In sandboxed mode, paths are validated to ensure:- No directory traversal (
../) outside workspace - Symlinks don’t resolve outside workspace
- Absolute paths are within workspace