Skip to content

ob:fs, ob:path, ob:env & ob:process

Built-in modules for filesystem access, path manipulation, environment variables, and subprocess execution.

ob:fs

Function Permission Description
fs.read_file(path) --allow-read Reads a UTF-8 file to string.
fs.write_file(path, content) --allow-write Writes text to a file (creates parent directories automatically).
fs.exists(path) --allow-read Returns boolean indicating whether the path exists.
fs.read_dir(path) --allow-read Returns an array of entry names in the directory.
fs.mkdir(path) --allow-write Recursively creates a directory.
fs.remove(path) --allow-write Removes a file or directory recursively.
fs.stat(path) --allow-read Returns { size, is_file, is_dir }.
local fs = require("ob:fs")

fs.write_file("tmp/hello.txt", "Hello Orbita!")
print(fs.read_file("tmp/hello.txt"))

ob:path

Pure path utilities (no permissions required):

  • path.join(...) — joins path segments.
  • path.dirname(p) — returns the parent directory.
  • path.basename(p) — returns the file name.
  • path.ext(p) — returns the file extension without the leading dot.

ob:env

  • env.get(key) (requires --allow-env) — returns the environment variable value or nil.
  • env.all() (requires --allow-env) — returns a table of all environment variables.
  • env.cwd() (requires --allow-read) — returns the current working directory.

ob:process

  • process.args — array of extra CLI arguments passed to the script.
  • process.exec(cmd, args?) (requires --allow-run) — executes a subprocess and returns { code, ok, stdout, stderr }.
  • process.exit(code?) — exits the process with the given status code.
local process = require("ob:process")

local res = process.exec("git", { "status", "--short" })
if res.ok then
    print(res.stdout)
end