Skip to main content

filesystem

Agent-optimized filesystem operations with constraint-based sandboxing.

PropertyValue
Module IDfilesystem
Version2.0.0
Typesystem
PlatformsLinux, macOS, Windows
DependenciesNone (stdlib only). Optional: ripgrep for faster grep.
Permissionsfs.read, fs.write, fs.delete, fs.list

Design Philosophy

This module is designed for AI agents, not humans. Key principles:

  • Line numbers everywhereread returns Nline format so the agent can reference exact locations.
  • Surgical editsedit replaces a specific text block, insert adds at a precise line. No need to rewrite whole files.
  • Fast searchgrep delegates to native tools (ripgrep -- grep -- Python fallback).
  • Constraint-aware — applications restrict paths and file sizes via YAML constraints.

Actions

read

Read a file with line numbers. Supports partial reads.

ParameterTypeRequiredDefaultDescription
pathstringyesPath to the file
start_lineintegerno1First line (1-indexed)
end_lineintegernolastLast line (1-indexed)
encodingstringno"utf-8"Text encoding

Returns:

{
"path": "/workspace/main.py",
"content": " 1import os\n 2import sys\n",
"total_lines": 42,
"start_line": 1,
"end_line": 2,
"size_bytes": 1024
}

Permissions: fs.read | Risk: Low | Constraints: paths, max_file_size


write

Create or overwrite a file.

ParameterTypeRequiredDefaultDescription
pathstringyesPath to write to
contentstringyesText content
create_dirsbooleannofalseCreate parent directories
encodingstringno"utf-8"Text encoding

Permissions: fs.write | Risk: Medium | Side effects: filesystem_write | Constraints: paths, max_file_size


edit

Replace a specific text block (old_string -- new_string). Returns a preview with line numbers.

ParameterTypeRequiredDefaultDescription
pathstringyesPath to the file
old_stringstringyesExact text to find
new_stringstringyesReplacement text
countintegerno1Occurrences to replace (0 = all)

Returns:

{
"path": "/workspace/main.py",
"replacements": 1,
"preview": "10 old_code\n11 NEW_CODE\n12 next_line\n"
}

Permissions: fs.read, fs.write | Risk: Medium | Side effects: filesystem_write | Constraints: paths


insert

Insert text at a specific line number.

ParameterTypeRequiredDefaultDescription
pathstringyesPath to the file
lineintegeryesLine number to insert before (1-indexed)
contentstringyesText to insert

Permissions: fs.read, fs.write | Risk: Medium | Side effects: filesystem_write | Constraints: paths


ls

List directory contents with type and size.

ParameterTypeRequiredDefaultDescription
pathstringno"."Directory to list
recursivebooleannofalseRecurse into subdirectories
patternstringnonullGlob filter (e.g. "*.py")
include_hiddenbooleannofalseInclude dotfiles

Permissions: fs.list | Risk: Low | Constraints: paths


grep

Search file contents for a regex pattern. Uses native tools for speed.

ParameterTypeRequiredDefaultDescription
patternstringyesRegex pattern
pathstringno"."File or directory to search
includestringnonullGlob filter (e.g. "*.py")
recursivebooleannotrueSearch subdirectories
max_resultsintegerno100Maximum matches
case_sensitivebooleannotrueCase-sensitive matching

Returns:

{
"matches": [
{"file": "/workspace/src/main.py", "line": 42, "text": " raise ValueError('invalid')"}
],
"count": 1
}

Performance: Tries rg (ripgrep) first, then grep, then Python re fallback.

Permissions: fs.read | Risk: Low | Constraints: paths


find

Find files by glob pattern.

ParameterTypeRequiredDefaultDescription
patternstringyesGlob pattern (e.g. "*.py")
pathstringno"."Root directory
typestringnonull"file" or "dir"
max_resultsintegerno100Maximum results

Permissions: fs.read | Risk: Low | Constraints: paths


mv

Move or rename a file or directory.

ParameterTypeRequiredDefaultDescription
sourcestringyesSource path
destinationstringyesDestination path
overwritebooleannofalseOverwrite if exists

Permissions: fs.read, fs.write | Risk: Medium | Side effects: filesystem_write | Constraints: paths (both)


cp

Copy a file or directory.

ParameterTypeRequiredDefaultDescription
sourcestringyesSource path
destinationstringyesDestination path
overwritebooleannofalseOverwrite if exists

Permissions: fs.read, fs.write | Risk: Medium | Side effects: filesystem_write | Constraints: paths (both)


rm

Delete a file or directory. Irreversible.

ParameterTypeRequiredDefaultDescription
pathstringyesPath to delete
recursivebooleannofalseRequired for directories

Permissions: fs.delete | Risk: High | Side effects: filesystem_delete | Constraints: paths


mkdir

Create a directory and parent directories.

ParameterTypeRequiredDefaultDescription
pathstringyesDirectory path

Permissions: fs.write | Risk: Low | Side effects: filesystem_write | Constraints: paths


file_stat

Get file or directory metadata.

ParameterTypeRequiredDefaultDescription
pathstringyesPath to inspect

Returns:

{
"path": "/workspace/main.py",
"name": "main.py",
"type": "file",
"size_bytes": 1234,
"modified": 1709942400.0,
"created": 1709856000.0,
"permissions": "0o644",
"is_symlink": false
}

Permissions: fs.read | Risk: Low | Constraints: paths


Constraints

Modules declare which constraints they support. Applications set values in their YAML definition. The runtime resolves template variables and passes constraints to the module via ExecutionContext.

ConstraintTypeScopeDefaultDescription
pathsstring_listUniversalAllowed path prefixes. All operations restricted.
max_file_sizesizeModule"100MB"Max file size for read/write/edit/insert/cp.

Example App YAML

modules:
- module: filesystem
actions: [read, write, edit, insert, ls, grep, find, mkdir, rm]
constraints:
paths: ["{{workspace}}"]
max_file_size: "50MB"

Enforcement

  • paths — Every action checks the resolved path against the allowed prefixes before any I/O. mv and cp check both source and destination.
  • max_file_sizeread checks file size before reading. write checks content size before writing.
  • No constraints — When no ExecutionContext is provided (dev mode, unit tests), all operations are allowed.

Security

All actions resolve paths via Path.resolve(strict=False) before any operation. This prevents write-through-symlink attacks where a symlink targets a location outside the allowed paths.

Path Constraint Enforcement

Agent requests: read("/workspace/../etc/passwd")

Path resolved: /etc/passwd

Constraint check: /etc/passwd not in ["/workspace"]

ActionResult(success=False, error="Path '/etc/passwd' is outside allowed paths")

Performance

StrategyDetail
Sync I/O thresholdFiles under 512 KB are read/written synchronously (no thread pool overhead)
Native grepgrep action uses subprocess to rg or grep for 10-100x faster search
No re-encodingwrite encodes once, writes bytes directly
Lazy globls and find use generators with early termination at max_results