Skip to content

shell ​

Use exec for an executable with separate arguments, or bash for shell syntax such as pipes and redirects. Use ls, grep, and glob to inspect files. These operations request approval. stat, exists, and which provide metadata without an approval interrupt.

ts
import { bash } from "std::shell"

node main() {
  const result = bash("ls -la") with approve
  print(result.stdout)
}

Types ​

ExecResult ​

Captured standard output, standard error, and exit code from a command.

ts
/** Captured standard output, standard error, and exit code from a command. */
export type ExecResult = {
  stdout: string;
  stderr: string;
  exitCode: number
}

(source)

Effects ​

std::exec ​

ts
@always(command)
@alwaysPrefix(args)
@alwaysUnder(cwd)
effect std::exec {
  command: string;
  args: string[];
  cwd: string;
  timeout: number;
  stdin: string
}

(source)

std::bash ​

ts
@always(command, cwd)
effect std::bash {
  command: string;
  cwd: string;
  timeout: number;
  stdin: string
}

(source)

std::bash::readonly ​

A shell line whose commands read no file and change nothing, such as pwd or which node; date. Every word in it is known before it runs.

ts
/** A shell line whose commands read no file and change nothing, such as
 `pwd` or `which node; date`. Every word in it is known before it runs. */
@always(command, cwd)
effect std::bash::readonly {
  command: string;
  cwd: string;
  timeout: number
}

(source)

std::ls ​

ts
@alwaysUnder(dir)
effect std::ls {
  dir: string;
  recursive: boolean;
  maxResults: number
}

(source)

std::grep ​

ts
@alwaysUnder(dir)
effect std::grep {
  pattern: string;
  dir: string;
  file?: string;
  flags: string;
  maxResults: number;
  ignoreCase: boolean;
  wholeWord: boolean;
  filesOnly: boolean;
  invert: boolean
}

(source)

std::glob ​

ts
@alwaysUnder(dir)
effect std::glob {
  pattern: string;
  dir: string;
  maxResults: number
}

(source)

Functions ​

exec ​

ts
exec(
  command: string,
  args: string[] = [],
  cwd: string = "",
  timeout: number = 2m,
  stdin: string = "",
  allowedExecutables: string[] = [],
  blockedCommands: string[] = [],
  allowedPaths: string[] = [],
  useAgentCwd: boolean = false,
): ExecResult raises <std::exec>

Run an executable with separate arguments and no shell expansion. Use this for commands whose arguments are already available as values.

Parameters:

NameTypeDefaultDescription
commandstringThe executable to run
argsstring[][]Arguments to pass
cwdstring""Working directory for the command
timeoutnumber2mTime limit in milliseconds (e.g. 30s), after which the command and everything it started is stopped. 0 means no limit.
stdinstring""Input to feed to the command
allowedExecutablesstring[][]Only allow running these executables (allow-list)
blockedCommandsstring[][]Block running these executables
allowedPathsstring[][]Only allow cwd values under these path prefixes
useAgentCwdbooleanfalseWhen true, a relative or empty cwd is resolved against the agent working directory if one is set; an absolute cwd is left unchanged

Returns: ExecResult

Throws: std::exec

Needs: fileRead, subprocess

(source)

bash ​

ts
bash(
  command: string,
  cwd: string = "",
  timeout: number = 2m,
  stdin: string = "",
  blockedCommands: string[] = [],
  allowedPaths: string[] = [],
  useAgentCwd: boolean = false,
): ExecResult raises <std::bash>

Run a bash command with pipes, redirects, and globbing. Use exec with separate arguments when values should remain literal.

allowedPaths restricts cwd, but bash cannot meaningfully restrict the shell command string itself, so prefer running an executable directly with structured arguments when capability narrowing matters.

Parameters:

NameTypeDefaultDescription
commandstringThe shell command to run
cwdstring""Working directory for the command
timeoutnumber2mTime limit in milliseconds (e.g. 30s), after which the command and everything it started is stopped. 0 means no limit.
stdinstring""Input to feed to the command
blockedCommandsstring[][]Block commands that start with these strings
allowedPathsstring[][]Only allow cwd values under these path prefixes
useAgentCwdbooleanfalseWhen true, a relative or empty cwd is resolved against the agent working directory if one is set; an absolute cwd is left unchanged

Returns: ExecResult

Throws: std::bash

Needs: fileRead, subprocess

(source)

ls ​

ts
ls(
  dir: string = ".",
  recursive: boolean = false,
  maxResults: number = 1000,
  allowedPaths: string[] = [],
  useAgentCwd: boolean = false,
  respectGitignore: boolean = true,
): Result raises <std::ls>

List directory entries, optionally including subdirectories. A recursive listing skips node_modules, .git, dist, build, .next, and .cache, and anything .gitignore ignores. To list an ignored folder, pass it as dir. Narrow dir or raise maxResults when the listing reaches its limit.

Recursive listings skip node_modules, .git, dist, build, .next, and .cache, plus paths ignored by .gitignore when respectGitignore is true. To list an ignored folder, pass it as dir. Non-recursive listings include every entry. Symlinked entries are omitted.

Parameters:

NameTypeDefaultDescription
dirstring"."
recursivebooleanfalse
maxResultsnumber1000
allowedPathsstring[][]Restrict searches to these directories, or leave empty for no restriction.
useAgentCwdbooleanfalseResolve a relative dir against the agent working directory when set.
respectGitignorebooleantrueSkip what .gitignore ignores in a recursive listing; false includes ignored files.

Returns: Result

Throws: std::ls

Needs: fileRead

(source)

grep ​

ts
grep(
  pattern: string,
  path | dir: string = ".",
  flags: string = "",
  maxResults: number = 200,
  allowedPaths: string[] = [],
  useAgentCwd: boolean = false,
  ignoreCase: boolean = false,
  wholeWord: boolean = false,
  filesOnly: boolean = false,
  invert: boolean = false,
  respectGitignore: boolean = true,
): Result raises <std::grep>

Search a file or directory recursively with a JavaScript regular expression. A directory search skips node_modules, .git, dist, build, .next, and .cache, and anything .gitignore ignores. To search an ignored folder, pass it as path. Narrow path or refine the pattern when results reach maxResults.

Directory searches skip common build and dependency directories, plus paths ignored by .gitignore when respectGitignore is true. A directly named file is always searched. To search an ignored folder, pass it as path. Symlinked entries are omitted.

Match paths are relative to the searched directory. For a single-file search, they contain the filename. Use filesOnly when you only need matching paths.

Parameters:

NameTypeDefaultDescription
patternstring
path (also dir)string"."Directory or single file to search. The path from a "saved as a file" notice can be searched too, and needs no approval.
flagsstring""Regex flags i, m, s, or u; use the named options for whole-word and inverted searches.
maxResultsnumber200
allowedPathsstring[][]Restrict searches to these directories, or leave empty for no restriction.
useAgentCwdbooleanfalseResolve a relative path against the agent working directory when set.
ignoreCasebooleanfalse
wholeWordbooleanfalseMatch only whole words.
filesOnlybooleanfalseReturn matching file paths instead of lines.
invertbooleanfalseReturn nonmatching lines.
respectGitignorebooleantrueHonor .gitignore during directory searches; false includes ignored files.

Returns: Result

Throws: std::grep

Needs: fileRead

(source)

glob ​

ts
glob(
  pattern: string,
  dir: string = ".",
  maxResults: number = 500,
  allowedPaths: string[] = [],
  useAgentCwd: boolean = false,
  respectGitignore: boolean = true,
): Result raises <std::glob>

Find files matching a glob such as "src/**/*.ts". The search skips node_modules, .git, dist, build, .next, and .cache, and anything .gitignore ignores. To search an ignored folder, pass it as dir or start the pattern with it. Symlinked entries are omitted.

Searches skip node_modules, .git, dist, build, .next, and .cache, plus paths ignored by .gitignore when respectGitignore is true. To search an ignored folder, pass it as dir or start the pattern with it. Symlinked entries are omitted.

Parameters:

NameTypeDefaultDescription
patternstring
dirstring"."
maxResultsnumber500
allowedPathsstring[][]Restrict searches to these directories, or leave empty for no restriction.
useAgentCwdbooleanfalseResolve a relative dir against the agent working directory when set.
respectGitignorebooleantrueSkip what .gitignore ignores; false includes ignored files.

Returns: Result

Throws: std::glob

Needs: fileRead

(source)

stat ​

ts
stat(
  filename: string,
  dir: string = "",
  allowedPaths: string[] = [],
  useAgentCwd: boolean = false,
): StatInfo

Return metadata about a filesystem entry: whether it exists, its type ("file", "dir", "other", or "missing" if absent), size in bytes, and mtime in ms. A symlink below dir is reported as missing. With no dir, the path itself is resolved the way you spelled it.

Parameters:

NameTypeDefaultDescription
filenamestringThe path to stat
dirstring""Directory to resolve a relative filename against; filename cannot escape it. When empty, filename resolves against the process cwd and absolute paths are accepted
allowedPathsstring[][]Only allow paths under these prefixes
useAgentCwdbooleanfalseWhen true, resolve a relative filename against the agent working directory if one is set; absolute filenames are unaffected

Returns: StatInfo

Needs: fileRead

(source)

exists ​

ts
exists(
  filename: string,
  dir: string = "",
  allowedPaths: string[] = [],
  useAgentCwd: boolean = false,
): boolean

Return true if a file or directory exists at the given path. A symlink below dir is reported as missing. Probing a path outside allowedPaths raises an error rather than silently returning false.

Parameters:

NameTypeDefaultDescription
filenamestringThe path to check
dirstring""Directory to resolve a relative filename against; filename cannot escape it. When empty, filename resolves against the process cwd and absolute paths are accepted
allowedPathsstring[][]Only allow paths under these prefixes
useAgentCwdbooleanfalseWhen true, resolve a relative filename against the agent working directory if one is set; absolute filenames are unaffected

Returns: boolean

Needs: fileRead

(source)

which ​

ts
which(command: string): string

Find an executable in PATH, or return an empty string if absent.

Parameters:

NameTypeDefault
commandstring

Returns: string

Needs: subprocess

(source)