Skip to content

File I/O

Sandboxed file operations restricted to the project directory. Relative paths resolve from the project root. Absolute paths must be inside the project directory.

local content = pl.read_file("notes.txt")

Returns the file contents as a string. Errors if the file doesn’t exist or exceeds 1 MB.


pl.write_file("output/result.txt", "Hello from Lua!")

Writes content to a file. Creates parent directories if needed. Max 1 MB.


if pl.file_exists("config.json") then
local cfg = pl.read_file("config.json")
end

local entries = pl.list_dir(".")

Returns an array of entries:

FieldTypeDescription
namestringFile or directory name
isDirbooltrue for directories
local entries = pl.list_dir(".")
for _, e in ipairs(entries) do
local kind = e.isDir and "[dir]" or "[file]"
pl.log(kind .. " " .. e.name)
end

  • All paths are sandboxed to the project directory
  • Path traversal (../) is blocked after canonicalization
  • Maximum file size: 1 MB per read/write
  • Symlinks that escape the project directory are rejected