Workspace Sandbox Configuration
The LLM4S workspace subsystem provides powerful capabilities (read/write files, execute commands, search) that require explicit sandboxing and security configuration.
Overview
- WorkspaceSandboxConfig: Explicit configuration describing allowed paths, resource limits, shell access, and timeouts
- Validation at startup: the runner reads
WORKSPACE_SANDBOX_PROFILEwhen it starts. Unset or empty, it usespermissive; an unknown profile name makesRunnerMainfail and the runner stop. Only a known profile that fails validation (which the built-in profiles cannot) is logged and replaced bypermissive - Enforcement: Runner enforces limits and shell allowance; file path boundaries are enforced via
resolvePath;executeCommandchecks each command’s executable, options, path arguments and environment (see Command policy), whether it arrives over the WebSocket protocol (ContainerisedWorkspace) or through a direct call
Configuration
Environment Variables (Runner)
When running the workspace runner (e.g. in Docker):
| Variable | Description | Default |
|---|---|---|
WORKSPACE_PATH |
Workspace root directory | /workspace |
WORKSPACE_SANDBOX_PROFILE |
Sandbox profile: permissive or locked; any other value stops the runner |
permissive |
WORKSPACE_SANDBOX_CONFIG |
The whole WorkspaceSandboxConfig as JSON, used in place of the profile; setting it with WORKSPACE_SANDBOX_PROFILE, or an invalid one, stops the runner. ContainerisedWorkspace(..., sandboxConfig = Some(...)) sets it |
none |
WORKSPACE_EXTRA_COMMANDS |
Programs added to the profile’s allowedCommands, separated by commas or whitespace (for example sbt); a name that is not a bare program name, is a .bat / .cmd batch file, or is a shell, interpreter, launcher, loader or other program that runs another (in any case, with or without .exe / .com or a version), stops the runner, as does any name with the locked profile, which runs no command |
none |
These variables are the only things that decide what the runner enforces.
Adding programs to the allowlist
A program the agent needs that is not on the profile’s list, such as a build tool, is added with
WORKSPACE_EXTRA_COMMANDS. ContainerisedWorkspace (and CodeWorker) take it as extraAllowedCommands and start
the container with it; CodeGenExample adds sbt this way so its agent can run sbt compile and sbt run:
1
2
new ContainerisedWorkspace(workspaceDir, imageName, hostPort, extraAllowedCommands = Set("sbt"))
// docker run ... -e WORKSPACE_EXTRA_COMMANDS=sbt ...
An added program means trusted code execution. It is held to every check below (no shell, forbidden characters,
path arguments inside the workspace, the environment allowlist), but, bar the few option rules below, it has no
per-program option rules, so it can do anything its own arguments allow: sbt run runs the project’s code, and so
can the agent that wrote it. Add only what the agent needs, and only a program you would let run any code in the
container. In particular, the policy does not model a program
that makes links or unpacks an archive (ln, tar, unzip, rsync, install): each of its arguments is checked
against the file system as it is before the command runs, but not the link text it writes, the names in an archive,
or a later argument that goes through a name an earlier one of its operations made (see
Several sources in one command).
These cannot be added (WorkspaceSandboxConfig.NeverAllowedCommands), as any of them would bring back the shell
#1756 removed (#1761,
#1792, #1805,
#1845):
| Kind | Refused |
|---|---|
| Shells | sh, bash, rbash, zsh, dash, ash, ksh, mksh, yash, csh, tcsh, fish, elvish, nu, xonsh, busybox, toybox, cmd, powershell, pwsh, and the cmd.exe built-ins call and start |
| Interpreters | python, py, pyw, pypy, jython, perl, ruby, irb, node, nodejs, deno, bun, php, lua, luajit, tclsh, wish, awk (gawk, mawk, nawk), java, javaw, jshell, jjs, jrunscript, scala, kotlin, kotlinc, groovy, r, rscript, julia, guile, racket, swipl, sbcl, clisp, erl, escript, iex, elixir, ghci, runghc, ocaml, osascript, dc, make, gmake, expect |
| Interpreter families, by prefix | every name starting python, pypy, jython, lua, ipython, bpython or jupyter (python3.7m, python3-dbg, pypy3.10, luajit-2.1, ipython3, jupyter-lab, jupyter-nbconvert) |
| Python front-ends and notebook tooling | ipython, bpython, ptpython, ptipython, pydoc, pdb, idle, jupyter, papermill, voila, marimo |
| Package and project runners, version managers | npx, pnpx, bunx, pipx, uv, uvx, poetry, pipenv, pdm, hatch, rye, conda, mamba, micromamba, pixi, tox, nox, pyenv, rbenv, nodenv, asdf, mise, volta, fnm (each runs the command or package named in its arguments: npx, uv run, conda run, pyenv exec) |
| Editors that run a command | sed (GNU e, s///e), vi, vim, nvim, ex, view, emacs |
| Launchers | env, xargs, nohup, nice, timeout, exec, eval, setsid, stdbuf, chroot, ionice, flock, watch, script, time, systemd-run, parallel, prlimit, numactl, unbuffer, tini, tmux, screen, fakeroot, proot |
| The dynamic loader | ld.so, ld-linux*.so*, ld-musl*.so*, ld64.so*, and musl’s loader under its C library names libc.musl-*.so* and libc.so* |
| Schedulers | at, batch, crontab |
| Debuggers, profilers, remote and container tools | strace, ltrace, gdb, lldb, valgrind, perf, ssh, docker, podman |
| Privilege, scheduling and namespace tools | sudo, su, runuser, doas, pkexec, gosu, su-exec, setpriv, capsh, nsenter, unshare, bwrap, firejail, taskset, chrt |
| Windows programs that run another | wsl, cscript, wscript, mshta, rundll32, regsvr32, forfiles, conhost, explorer, msbuild, wmic, schtasks, runas, msiexec, pcalua, bitsadmin, hh, installutil, regasm, regsvcs, cmstp |
A name is matched ignoring case, a .exe / .com extension and a trailing version (Python3.12.EXE is python,
scala3 is scala). A .bat or .cmd name is refused too: Windows runs a batch file through cmd.exe, outside the
runner’s cmd.exe checks. A name may hold only ASCII letters, digits, ., _, + and -, so no Unicode spelling of
a refused name (fullwidth letters, a Kelvin sign that lower-cases to k, a character Windows best-fits to a
letter) is accepted. Build tools (sbt, mvn, gradle, scala-cli, cargo, npm) are not refused: they run the
project’s code by design, which is what an operator adds them for. Note that npm exec, yarn dlx and pnpm dlx
(and every package’s lifecycle scripts) fetch and run arbitrary packages, so allowing npm, yarn, pnpm or
corepack means allowing that.
The list is a speed bump, not a boundary. No list names every program that can run another: most tools with a
hook, plugin, pager, editor or helper-program option can, and catalogues such as
GTFOBins and LOLBAS list hundreds - man -P,
sqlite3 -cmd .shell, psql and mysql shell escapes, ssh-keygen -D lib.so, an openssl engine, gpg’s exec
options, wget --use-askpass, cmake -P, gcc -wrapper and -fplugin, and every package manager’s install
scripts (npm, yarn, pnpm, pip, cargo, go, and the runners above). That is why an added program must be one you trust to
run any code. For the archive and copy tools operators most often add, the runner refuses the options that run a
program, as it does for sort and cp (see Command policy): tar --to-command, -I /
--use-compress-program, --checkpoint-action, -F / --info-script; zip -TT / --unzip-command; rsync -e /
--rsh / --rsync-path, and rsync’s daemon mode (--daemon, --config, --dparam, -M / --remote-option),
whose configuration runs commands and whose server outlives the command; scp and sftp -S, -o, -F and -D,
and sftp’s -b batch file, whose !command runs a local shell.
Network-reaching modes. tar and rsync read an argument with a : after a part holding no / as a file on
another host (host:a.tar, user@host:dir, host::module, rsync://host/module, tar -f host:a.tar,
--files-from=host:list) and start the system’s ssh or rsh to reach it. The runner refuses such an argument
(ARGUMENT_NOT_ALLOWED); name a local file with a : as ./a:b. Over-blocking is accepted: an option value or a
member name holding a : with no / before it (--transform=s:a:b:) is refused too. On Windows a drive letter
(C:\x) is not a host. scp and sftp reach another host by design, so their operands are not refused: added, they
connect wherever their arguments say, through the system’s ssh and its configuration. On Linux a command has no
network unless networkAllowed = true (Landlock and seccomp); elsewhere, and with the network allowed, nothing but
these rules stands between an added scp, sftp, tar or rsync and the network.
With WORKSPACE_SANDBOX_PROFILE=locked, which refuses every command, any WORKSPACE_EXTRA_COMMANDS name stops the
runner with a message saying so, rather than logging programs added that could never run.
Profiles
- permissive: Current behavior—shell allowed with the read-write command allowlist (
ReadWriteCommands), standard limits (1MB file size, 500 dir entries, 30s command timeout) - locked: Shell disabled; strict limits (10s timeout). File writes and modifications remain allowed; this profile does not enforce a read-only filesystem.
Client configuration
The workspace client has no sandbox setting: what the runner enforces is decided only by the two variables above,
set on the runner’s container. WorkspaceConfigSupport.loadSandboxConfig(), which read an
llm4s.workspace.sandbox.profile that nothing passed to the container, was removed
(#1730). To lock a runner down, start its container with
WORKSPACE_SANDBOX_PROFILE=locked (see the example below); to turn a profile name into a config in your own code,
use WorkspaceSandboxConfig.fromProfileName.
WorkspaceSandboxConfig Structure
| Field | Type | Description |
|---|---|---|
limits |
WorkspaceLimits | maxFileSize, maxDirectoryEntries, maxSearchResults, maxOutputSize |
excludePatterns |
List[String] | Glob patterns excluded from explore/search (e.g. node_modules, .git) |
shellAllowed |
Boolean | Whether executeCommand is allowed |
defaultCommandTimeout |
FiniteDuration | Default timeout for shell commands (more than zero, at most 1 hour) |
readOnlyPaths |
List[String] | Paths under workspace that are read-only; bind commands too on Linux (Command confinement) |
allowedPaths |
List[String] | If non-empty, only these paths accessible; bind commands too on Linux (Command confinement) |
networkAllowed |
Boolean | Whether commands may open network sockets (default false). Enforced on Linux by the runner’s seccomp filter, and for the whole container by its firewall (Container egress) |
allowedCommands |
Set[String] | Executable names executeCommand may run; field default ReadOnlyCommands; the permissive profile (the default profile) uses ReadWriteCommands, which adds write-capable ones (cp, mv, rm, mkdir, …). Arguments are checked too: see Command policy |
Command policy
The policy applies to every command the runner executes, by either path: a direct executeCommand on
WorkspaceAgentInterfaceImpl, and the WebSocket protocol’s ExecuteCommandCommand, which is how
ContainerisedWorkspace.executeCommand and executeCommandWithStreaming reach the runner in its container. Both go
through one function, so they share the checks, the codes and the way the program is started
(#1756). Before that fix, the WebSocket path ran the raw command string
through sh -c (cmd.exe /c on Windows) with the client’s environment copied in, and none of the checks below
applied to it.
No shell is involved on either path. The command is split into words (single and double quotes group a word, a
backslash escapes the next character), the first word names the program, and the program is started with the other
words as its arguments. Pipes, redirection, ;, &&, $(...), backquotes and variable expansion are not
interpreted; a word holding one of their characters is refused. Write each command as one program and its arguments,
and run a second command as a second request.
executeCommand runs a command only when every check passes, in this order, and otherwise fails with the code shown:
| Check | Code |
|---|---|
Shell turned off (shellAllowed = false) |
SHELL_DISABLED |
| Working directory, as written, outside the workspace, or not a directory | PATH_ESCAPE_ATTEMPT, INVALID_DIRECTORY |
| Command with no words | EMPTY_COMMAND |
| Executable given as a path | EXECUTABLE_PATH_NOT_ALLOWED |
Executable not in allowedCommands |
EXECUTABLE_NOT_ALLOWED |
A shell metacharacter (&, \|, <, >, ^, ;, `, $, %) in any word |
FORBIDDEN_CHARACTERS |
| Working directory really outside the workspace (a symbolic link out of it) | PATH_ESCAPE_ATTEMPT |
environment sets a variable other than LANG, LANGUAGE, LC_*, TZ, TERM, COLUMNS, LINES, NO_COLOR |
ENVIRONMENT_NOT_ALLOWED |
| An option the program refuses (below) | ARGUMENT_NOT_ALLOWED |
| An argument longer than 4096 characters, or paths that need more than 20000 lookups to check | ARGUMENT_NOT_ALLOWED |
An argument holding a NUL character, on Windows one holding ", or one whose check fails with an error |
ARGUMENT_NOT_ALLOWED |
On Windows, an argument or the working directory holding a character a program may receive as another ASCII character (“best fit”, see On Windows); an environment value holding one is ENVIRONMENT_NOT_ALLOWED |
ARGUMENT_NOT_ALLOWED |
| On a double-byte Windows host (code page 932, 936 or 950), an argument the JDK puts in quotes holding a character whose second byte is 0x5C (see On Windows) | ARGUMENT_NOT_ALLOWED |
On Windows, a cmd.exe built-in’s argument holding a character cmd.exe splits or parses (, = ( ) @ !, a control character, a non-ASCII space) |
ARGUMENT_NOT_ALLOWED |
git with a .git file or link between the working directory and the workspace root |
PATH_ESCAPE_ATTEMPT |
A program other than the read-only ones naming .git or a path inside one (see git’s own files) |
ARGUMENT_NOT_ALLOWED |
An argument that names a location outside the workspace (an rm / unlink operand or mv source naming a link itself: its directory, see Removing a link) |
PATH_ESCAPE_ATTEMPT |
On Windows, a form listed under On Windows (a device name, a trailing . or space, @, ~, glob syntax) |
ARGUMENT_NOT_ALLOWED |
cp only: a name it would write leads outside, or a recursive copy’s destination holds a link that does |
PATH_ESCAPE_ATTEMPT |
mv or cp of several sources: a path goes through a name another source’s operation creates, replaces or removes, or mv moves the working directory (see Several sources in one command) |
ARGUMENT_NOT_ALLOWED |
The program is found only where the runner never starts one from: the workspace, the runner’s own working or Java directory, or an empty or relative PATH entry (see Program resolution) |
EXECUTABLE_NOT_ALLOWED |
| The program is found nowhere the runner looks | EXECUTABLE_NOT_FOUND |
git only: the repository’s configuration has an include.path / includeIf, a hook.* key, or a driver name that is not printable ASCII (see git’s own files) |
GIT_CONFIG_NOT_ALLOWED |
writeFile and modifyFile refuse a path naming .git or a path inside one with PATH_NOT_ALLOWED.
Program resolution
The runner never starts a program by its bare name: it looks the program up itself and starts the absolute path it
finds (#1790). Started by a bare name, a program was looked up by the
platform in places an agent can reach. On Windows, CreateProcess
(reference)
searches the directory of the runner’s java.exe and then the runner’s current directory before the system
directory, appending .exe, so a git.exe or cat.exe an agent wrote there - the runner started in the workspace,
or in any directory the agent could write - ran in place of the allowlisted program. On POSIX the JDK searches PATH
after changing to the command’s working directory, so an empty or relative PATH entry (., bin) - or an entry
inside the workspace - found a program the agent wrote there.
The runner searches:
| Host | Where, in order | File names |
|---|---|---|
| Windows | the system directory (%SystemRoot%\System32), the Windows directory (%SystemRoot%), then each PATH entry |
<name>.exe, then <name>.com (as CreateProcess, it does not use PATHEXT: no .bat or .cmd) |
| POSIX | each PATH entry |
<name>, a regular file that is executable |
and never:
- the runner’s current directory, even when it is on
PATH(unless it is the system directory, where a Windows service starts); - the directory of the runner’s
javaexecutable, unless it is onPATH; - an empty or relative
PATHentry, which would be read from the command’s working directory; - a directory inside the workspace, as written or after following links, nor a file whose real path is inside the workspace (a link from a trusted directory into it).
A program found only in one of those places is refused with EXECUTABLE_NOT_ALLOWED, and the message names where it
was found; one found nowhere with EXECUTABLE_NOT_FOUND. A cmd.exe built-in (echo, dir, type, …) runs through
the system directory’s cmd.exe, by its absolute path and never one from PATH, as cmd /d /c (/d: no AutoRun
command from the registry runs first, #1792), and is named to it without
an extension. The PATH the runner was started with is the one searched; a command cannot set PATH
(ENVIRONMENT_NOT_ALLOWED).
The program the runner starts may itself start another by name - a #!/usr/bin/env x script, sbt starting java,
git a helper - searching the PATH it inherits from the workspace as its working directory. So the command’s
process gets only the PATH entries the runner itself would search: an empty or relative entry, an entry inside the
workspace (as written or after following links, and for an entry that does not exist yet, through its nearest
existing ancestor’s links) and the runner’s own working directory are dropped, the rest kept in order
(#1792). With none left the process gets the system directories -
/usr/bin:/bin on POSIX, the system and Windows directories on Windows - rather than no PATH, for which bash and sh
use a built-in default ending in ., the workspace (#1805); only if
even those lie in the workspace (a workspace at the file system’s root) has it no PATH, never an empty one, which
is read as the current directory. Directories are vetted, not the files in them: a program in a kept directory that
is itself a link into the workspace is followed by a child, though the runner never starts one through it. Making
such a link needs a write outside the workspace, or an operator who made it. On Windows every command, not only a built-in, runs with
NoDefaultCurrentDirectoryInExePath=1, so neither cmd.exe nor CreateProcess in a child looks a program up in the
working directory.
On Windows a command’s first word and the allowlist’s entries are matched by program name: ignoring case and a
.exe or .com extension, so git.exe status runs git, an allowlist entry sort.exe allows sort, and either is
held to sort’s rules below (an entry spelled with the extension used to escape them,
#1761). WORKSPACE_EXTRA_COMMANDS refuses a shell, interpreter or
launcher under either spelling (bash.exe, CMD.COM, wsl.exe).
Over the WebSocket protocol a refused command gets a WorkspaceAgentErrorResponse carrying the code above, then a
CommandCompletedMessage with exit code 1, and no CommandStartedMessage or output; ContainerisedWorkspace
throws it as a WorkspaceAgentException whose message begins with the code. A command that runs streams its output
as before, and is stopped at its timeout, or at the sandbox’s defaultCommandTimeout when the request sets none.
A command that passes every check runs with its standard input read from the null device (/dev/null, or NUL
on Windows), as nothing can write to it: a program that reads standard input when given no file (cat, cat -,
sort, wc, grep x, findstr x) sees an empty input and finishes at once instead of waiting until the command
timeout (#1728).
An allowlist names programs; these rules stop a listed program from writing, deleting, running another program or following links out of the workspace through its own options:
| Program | Refused |
|---|---|
find |
-delete, -exec, -execdir, -ok, -okdir, -fprint, -fprint0, -fprintf, -fls, -files0-from, -follow, -L (also in -HL) |
git |
any subcommand but status, log, show, diff, ls-files, ls-tree, grep, blame, rev-parse, branch; any global option but --version, --no-pager, --no-optional-locks, --literal-pathspecs, --no-replace-objects (so -c, -C, --exec-path, --git-dir, --work-tree, -p); --output, --ext-diff, --textconv, --show-signature on log/show/diff; -O, --open-files-in-pager, --textconv on grep; --textconv on blame; an argument starting with : (pathspec magic, index paths); branch with anything but listing options, or with a name unless --list/-l makes it a pattern (the values of --merged, --no-merged, --contains, --no-contains, --points-at, --sort and --format are values, not names) |
sort |
-o, --output, --compress-program, --files0-from; on POSIX an operand after -- starting with -t (see below); on Windows also /O, /T, -O, -T, -t, --temporary-directory, and any argument starting with / that is not a native sort.exe switch (see On Windows). The value of -t / --field-separator is not path-checked only when it really is that value: see Option values |
findstr (Windows) |
a switch with F among its letters (/F:list), a /D: value holding , or ;, any argument starting with / that is not a native findstr.exe switch (see On Windows) |
uniq |
a second operand (the output file); every argument after the first operand counts as one, as BSD uniq does not reorder its arguments, so write options before the file (uniq -c a.txt, not uniq a.txt -c) |
wc |
--files0-from |
ls |
-L, --dereference |
grep |
-R, --dereference-recursive, -S (BSD) |
cp |
-L, --dereference, -H, -s, --symbolic-link; with -R, -r, -a, -P or -d (or their long forms) anywhere in the arguments, two sources with the same name (letter case and Unicode normalisation ignored; on Windows a name with ~ matches any), or several sources and one that names a directory’s contents (src/., src/) |
chmod |
-L, -H, --dereference |
hostname |
an operand, -F, --file, -b, --boot |
tar (when added) |
--to-command, -I, --use-compress-program, --checkpoint-action, -F, --info-script, --new-volume-script, --rsh-command, --rmt-command; I or F in a first argument without a dash (the traditional tar cIf form); an argument naming a file on another host (host:a.tar, -fhost:a.tar, --file=host:a.tar, see Adding programs to the allowlist) |
zip (when added) |
-T (and so -TT), --unzip-command |
rsync (when added) |
-e, --rsh, --rsync-path, --daemon, --config, --dparam, -M, --remote-option; an argument naming a file on another host (host:dir, host::module, rsync://host/module) |
scp, sftp (when added) |
-S, -o, -F, -D; sftp’s -b |
mv, rm, mkdir and touch have no option that follows a link out of the workspace, so they get the path rule
only (with the exception for a link itself under Removing a link).
Every argument is scanned for these options, including those after --, because an option that takes a value can
consume the -- itself. A short option is refused anywhere in a cluster (sort -ro out), and a long one under any
abbreviation of at least one letter (sort --outp=out), as GNU programs and git accept an unambiguous prefix.
On POSIX, sort also refuses an operand after -- that starts with -t (sort -- -tNAME,
#1774). GNU and BSD sort open a file named -tNAME, but uutils
coreutils (the Rust implementation that Ubuntu 25.10 and later ship as coreutils) rewrites, in its development
line though not yet in a release (0.8.0, 0.10.0), every argument starting with -t into --field-separator=<rest> before it parses
its options, including after --, and would then open a file literally named --field-separator=NAME, which the path
rule never sees. The -- counts wherever it is, even as another option’s value (sort -k -- -t, is refused too).
Name such a file ./-tNAME, or give -t before the --. Other option-looking operands after -- need no rule of
their own: -o, --output, --compress-program and --files0-from are refused there as anywhere, and every other
operand is path-checked as the file it names (sort -- -T/../.. is refused as a path out of the workspace). The rule
stays although the runner image runs GNU coreutils (below), since a runner on another host or image may not.
The option tables model GNU and BSD sort and cp, so the runner image runs GNU coreutils (#1774).
Its base, eclipse-temurin:21-jdk, is Ubuntu 26.04, which ships coreutils-from-uutils: sort, ls, cat, ln
and most other programs are uutils (rust-coreutils 0.10.0), and only cp, mv, rm, df and true are GNU. The
image installs coreutils-from-gnu, which points every name at GNU coreutils (9.7), and its build fails if any
program in /usr/bin or /usr/sbin is still a uutils one or if sort or cp does not report (GNU coreutils).
WorkspaceCoreutilsIntegrationSpec (the @Workspace tier) checks the built image’s coreutils and runs the sort
and cp refusals against them. An image of your own built on another base should do the same, or be checked
against these rules.
Every argument of every program except echo, pwd, whoami and hostname is then held to the workspace. Each
candidate path is resolved from the real working directory the way the kernel resolves it, one component at a time,
following each symbolic link where it is met (so link/.. is the parent of the link’s target), and must stay inside
the real workspace root. It must also stay inside under the reading Windows uses, which removes . and .. as text
before following any link (so link/.. is the directory holding the link): a path is refused on every platform
unless both readings are inside, so with l -> a/b, l/../../x (a/x on POSIX, x beside the workspace on
Windows) is refused. Only a .. after a symbolic link makes the two differ. That applies to programs added to a custom allowlist too. The candidates are:
- a positional argument, or an option’s value given as the next argument: the whole argument;
- a long option
--name=value: the whole argument and the value, sogit log --since=2024/01/01,--grep=feat/x,git ls-files --exclude=*/target/*,grep --include=sub/*.scalaandls --hide=x/yrun, while--exclude-from=../xor a value through a link out of the workspace is refused; - a short option: the whole argument and every tail after its dash, so an attached value at any position (
-f/x,-rf/x) is checked, and so is the name a program opens when it reads the argument as a file (BSD programs stop reading options at their first operand, socat a.txt -fopens-f); sort -tand--field-separatortake a separator, not a path:sort -t/ -k2,sort -t / -k2andsort --field-separator=/run (POSIX only; see Option values).- on Windows, the
/Xswitches ofdir,findstr,copy,moveandsortare switches, not paths, but a value after:(findstr /G:file) is checked, and forfindstrandsortonly the native tool’s switches are accepted (see On Windows); - on Windows, a string the platform cannot parse as a path is judged by the part before the first character a path
cannot hold (
HEAD:src/xbyHEAD,..\*by..\); one that starts with\or/and has no such part (\\?\C:\x,\??\C:\x) is refused, and so is a drive-relative path on a drive other than the workspace’s (D:x, which the program would resolve from that drive’s own working directory). Windows removes..as text before it opens a name or matches a wildcard, so such a string is also refused when it has a..component after that character (x*\..\..\outside\f,x?\..\..,ab:c\..\.., which open..\outside\falthough their prefix is inside), or when, with each such character replaced by_, it leads outside;dir *.txt,type a?.txtandfindstr /C:x a.txtrun; - on Windows, an argument holding
"is refused (ARGUMENT_NOT_ALLOWED) before any path or option check: the C runtime’s argument parser and cmd.exe delete"as a quote, so"..\outside\fopens..\outside\fand"C:\outside\fan absolute path, and a Windows file name cannot hold one. Quote an argument in the command string instead (findstr "/C:two words" a.txt): that quoting is removed before the checks; - on Windows, the built-ins the runner starts through
cmd.exe /d /c(dir,type,copy,move,echo, …) refuse (ARGUMENT_NOT_ALLOWED) an argument holding,,=,(,),@,!, a control character (VT, FF, a line feed) or a space other than U+0020 (NBSP, U+00FF):ProcessBuilderquotes an argument only for a space, a tab,",<or>, and cmd.exe splits a built-in’s arguments on,,;,=, VT, FF and 0xFF as well, sotype a.txt,..\outside\ftypeda.txtand then..\outside\falthough the argument checked was one name inside.echomay still print,,=and parentheses. Programs that are not built-ins (findstr) get their arguments from the C runtime, which splits on space and tab only, sofindstr x a,b.txtruns. A wildcard in the last component (dir .*) can match the..entry, butdironly lists it andtypeandfindstrcannot read a directory, so it is not refused.
A working directory, or a file operation’s path, that is not a valid path (a NUL character, or on Windows a : or
wildcard in it) is refused with PATH_ESCAPE_ATTEMPT rather than failing with an exception.
A relative value with no .. component can only leave the workspace through a link, so the over-blocking is limited
to text that is absolute or climbs out with ..: a grep pattern /api or ../x, or an option value such as
git log --grep=/x or --grep /x, is refused although it is not a path (write [/]api, [/]x).
cp writes through a symbolic link it finds at the name it writes, so its destinations are checked as well. Any
operand may be the target, so for every pair of operands the name the source takes under the target (and, for
src/ or src/., the target itself; with --parents, the target joined with the source) must resolve inside the
workspace. A recursive copy also writes below those names, so each that is an existing directory is searched, without
following links, for a link that leads outside.
What these checks do not cover:
- A repository that arrives with a
.git/configcore.worktree, a.git/commondiror.git/objects/info/alternatespoints git at files outside; see git’s own files. diff -rfollows symbolic links it meets inside the tree it walks; no portable option stops it.- A relative link moved or copied to another depth by the read-write list (
mv a/b/rel rel) can come to point outside. Paths through it in a later command are refused, and so is a recursivecpinto its directory; within the same command, see Several sources in one command. The agent can remove it (rm rel, see Removing a link), but the runner does not. - The checks run before the program starts, so a link made at a checked name by a concurrent command is not seen.
Windows
copygets the path rule but notcp’s destination checks.
Removing a link
Removing or renaming a symbolic link never touches what it points to: rm reads its operand without following a
link at its last component, unlink and rename act on the name itself. So on POSIX, an operand of rm or unlink,
or a source of mv, whose last component is itself a symbolic link is judged by the directory holding it rather than
by where the link leads, and an agent can clean up a link that points out of the workspace, a dangling one, or the
first of a chain of links (#1730):
1
2
3
4
5
rm outlink # removes the link; its target is untouched
rm -f outlink # likewise
mv outlink sub/ # moves the link itself to sub/outlink
mv outlink renamed
unlink outlink # where unlink is added with WORKSPACE_EXTRA_COMMANDS
Such an operand is allowed only when all of these hold; otherwise it gets the path rule, which follows the link and refuses it:
- Its last component is a name with no trailing
/(notoutlink/,outlink/.,.or..). With a trailing slash the kernel follows the link:mv outlink/ xmoves the directory the link points to, andrm -r outlink/deletes what is in it. - The directory holding it is inside the workspace under both readings of the path rule (the kernel’s, following
links, and the one that removes
..as text), and both name the same directory:rm escape/linkwithescapea link out of the workspace,rm ../outside/linkandrm l/../linkwithla link to a deeper directory are refused. - In that directory, the last component is a symbolic link, read without following it.
rmis not recursive (-r,-R,--recursive). GNU and BSDrm -rremove a link operand and not its target, but not every implementation has been checked, and removing a link needs no-r.- For
mv, it is a source, not the destination. The destination keeps the path rule, links followed:mv a.txt outlinkmovesa.txtinto the directory the link points to and is refused, as aremv -t outlink a.txtandmv --target-directory=outlink a.txt. - The arguments read the same to every
rm/mv/unlink: they are parsed by GNU’s option table (with and withoutPOSIXLY_CORRECT) and by macOS / FreeBSD’s, and every parse must know every option and agree on which arguments are operands and which is the destination. An option only GNU has (rm --force,mv -T,mv -t dir, any long option) or only BSD has (mv -h) keeps the link refused; writerm -f outlink,mv outlink dir/. An operand starting with-is never exempted.
On Windows a link or junction is not exempted: the policy does not model how del, rd, move or an MSYS rm
treat them, so such an operand keeps the path rule and is refused when it leads outside. cp is unchanged: it
copies what a link points to unless told otherwise, so its sources keep the path rule.
A link moved by an mv of several sources cannot be used by a later source of the same command:
mv evil d/evil/secret.txt d, with evil a link out of the workspace and d empty, is refused, since once evil
is in d, d/evil/secret.txt names the file outside (#1776). Move
the link on its own: mv evil d.
Several sources in one command
mv and cp handle several sources one at a time, so each operation changes the file system the next resolves its
paths in, but every path is checked before the command starts. With sub/l -> ../outside, which names a missing
entry of the workspace while the link sits in sub, mv sub/l l/secret.txt . first moves the link to ./l, where
it names the real directory outside, and then moves outside/secret.txt into the workspace
(#1776). GNU cp -P, -d, -R and -a likewise copy a link as a link
and then read a later source through the copy.
So for an mv or cp of two sources or more (under any of the GNU and macOS / FreeBSD parses of its options), each
source’s operation is taken to change:
- in the destination directory, the source’s last name and any name starting with it (
--backupkeeps a replaced entry asname~orname.~1~), or any name at all when that is not known (src/.,cp --parents); - for
mv, the source’s own entry in the directory holding it.
Every other path argument (the other sources, the destination, a -t value) is walked as the path rule walks it,
under both readings, links’ targets included, and the command is refused (ARGUMENT_NOT_ALLOWED) when the walk looks
up one of those entries. Names are compared without regard to letter case or Unicode normalisation, as on macOS and
Windows file systems (NFKD decomposition, as APFS decomposes before it case-folds, then case mapping, repeated until
the name stops changing, so ẞ, ß, ss and SS are one name, as are ᾳ̃ and α̃ι, as on APFS), and directories by identity, so another spelling of the destination (alias/evil/... with
alias -> d) is caught. Windows also takes x. and x (trailing dots and spaces) for x; these are not folded,
which matters only for a native Win32 cp. An mv is also refused when the working directory lies inside a source it moves, since a
relative path’s .. then climbs from the source’s new place. Argument order is not modelled: a path through a name a
later source creates is refused too. Run one command per source instead; each is then checked against the file
system the previous one left.
1
2
3
4
5
6
7
8
mv sub/l l/secret.txt . # refused: l/secret.txt goes through the ./l the first move makes
mv evil d/evil/secret.txt d # refused, also through another name for d, or d/EVIL, or d/evil~
mv sub sub/Main.scala d # refused: sub/Main.scala goes through the sub the first move removes
cp -P sub/l l/secret.txt . # refused: GNU cp reads l/secret.txt through the copied link
cp -P a/b/x c/X d # refused: on macOS d/X is the link d/x, and cp writes c/X through it
cp -P a/b/ẞ c/ss d # refused: the same on macOS, where ẞ and ss are one name
mv a.txt b.txt d # runs
mv outlink dangling d/ # runs: several links moved, nothing reached through them
The other programs of the lists need no such rule: rm (and unlink) only remove entries, so a later operand
through one fails rather than leading elsewhere; mkdir and touch make directories and files, never links, and the
path rule already takes a missing component as a directory to be made; chmod changes no name; the read-only programs
and the read subcommands of git change nothing; Windows copy and move take one source argument (a wildcard’s
matches go into the destination, which no other argument goes through, and copy a+b dest concatenates into one
file; the , of move a,b dest is refused). A program added with WORKSPACE_EXTRA_COMMANDS is not modelled (see
Adding programs to the allowlist).
Option values
An option that takes a value takes the next argument whatever it is, so the argument after a -t is a separator
only if that -t is an option and not another option’s value: in sort -T -t /etc/passwd and
sort --random-source -t /etc/passwd, -T and --random-source take -t, and /etc/passwd is a file sort reads
(#1763). On POSIX the runner therefore parses sort’s arguments as
getopt does, each option’s value consumed exactly once, for the options of both GNU and BSD sort:
| Takes a value | Short | Long |
|---|---|---|
| always | -k, -o, -S, -t, -T |
--batch-size, --buffer-size, --compress-program, --field-separator, --files0-from, --key, --output, --parallel, --random-source, --sort, --temporary-directory |
only after = |
--check |
|
| GNU only: attached, or a next argument of digits | -y |
A value is attached (-Tdir, -rTdir, --temporary-directory=dir) or the next argument (-T dir, -rT dir,
--temporary-directory dir, and any unambiguous abbreviation such as --temp dir); a -- an option takes as its
value does not end the options. Every operand and every other option’s value is checked whole. The separator is
left out only when:
- every option is one GNU or BSD sort has, unambiguously abbreviated, with its value where it needs one;
- no argument starts with
+(BSD sort rewrites the obsolete+POS1 -POS2into-kbefore it reads options, even inside another option’s value, sosort -T +0 -1t /etc/passwdreads/etc/passwd); - the
-tcomes before the first operand (withPOSIXLY_CORRECTin the runner’s environment, GNU sort reads every argument after its first operand as a file; writesort -t / a.txt, notsort a.txt -t /).
Otherwise the separator is checked like any other value, so -t / is refused there. cp is parsed the same way
(GNU’s -S / --suffix and -t / --target-directory take a value; macOS cp takes none and stops at its first
operand), so a -- that -S takes does not hide a later -R (cp -S -- -R src dst), and --path, GNU’s old
name for --parents, gets the --parents destination check. uniq (its -f, -s, -w values) and git branch
(the values of --merged, --contains, --sort, --format, …) already consume each value once. Windows keeps
its own sort rules (see On Windows); there the argument after --field-separator is checked.
On Windows
On Windows the policy refuses (ARGUMENT_NOT_ALLOWED) every form below rather than reasoning about what Win32, cmd.exe
or a program’s runtime makes of it. Over-blocking is accepted there: only the forms the rest of this section allows
are supported. Each rule runs after the path rule, so an argument that leads outside is still PATH_ESCAPE_ATTEMPT.
- Best-fit characters (#1766), for every program and before
the option and path checks. A program that reads its command line in an ANSI code page (
mainrather thanwmain) gets each argument converted from UTF-16 with “best fit”: a character the code page cannot hold may become a similar ASCII one, so../../outside(U+FF0F) reaches it as../../outside,..\x(U+FF3C) as..\x,¥(U+00A5) and₩(U+20A9) as\on the Japanese and Korean code pages,-oas-o, and an ideographic space (U+3000) as a space that splits the argument in two (the “WorstFit” research, Orange Tsai, 2025). Every check here reads UTF-16, so an argument, the working directory below the workspace root (ARGUMENT_NOT_ALLOWED) and an environment value (ENVIRONMENT_NOT_ALLOWED) are refused when they hold:- a character that one of the common ANSI code pages (874, 932, 936, 949, 950, 1250 to 1258) best-fits to an ASCII
character other than a letter or digit - a separator,
",:, a wildcard,%,^,&,|,<,>, a space, a control character,-,.or any other punctuation; - in an argument starting with
-or/, a character best-fitted to any ASCII character, since a letter there may be an option (-öis-oon code pages 932 and 1251); - a character the host’s own ANSI code page cannot hold exactly, which a program reading its arguments in it
would receive as a best fit or as
?.
Accented letters that only best-fit to a letter (
é,ü) stay allowed in an operand when the host’s code page holds them, sofindstr x résumé.txtruns on a Western European host. The table is generated from Microsoft’s best-fit files (unicode.org) byscripts/generate-windows-best-fit.py. POSIX hosts are unchanged: nothing converts an argument there. - a character that one of the common ANSI code pages (874, 932, 936, 949, 950, 1250 to 1258) best-fits to an ASCII
character other than a letter or digit - a separator,
- Quoted arguments on a double-byte host (#1807), for every
program. Code pages 932, 936 and 950 encode some characters they hold exactly with a second byte of 0x5C, the byte
of
\: 50 on 932 (表0x95 0x5C,―,ソ,予,十), 126 on 936 and 126 on 950 (功0xA5 0x5C,許); 949 has none. The JDK puts an argument in quotes when it is empty or holds a space or whitespace character, and, outside its default mode,",<or>(&,|,^too for a batch file), soa 表reaches the command line as"a 表", whose bytes end5C 22. A program that splits its ANSI command line byte by byte, without knowing the code page’s lead bytes, reads\"as a literal quote: the argument does not end there, and the ones after it split differently, so an operand the checks saw may become an option. The C runtime’s parser knows the lead bytes; a hand-written one may not. So on a host whose ANSI code page is 932, 936 or 950, an argument holding such a character and any of the characters above is refused (ARGUMENT_NOT_ALLOWED);表.txtandsub\表, which the JDK leaves unquoted, stay allowed. The characters are found through the JDK’s encoder for the host’s code page. - Device names, for every program but
echo,pwd,whoamiandhostname: a path component that isCON,PRN,AUX,NUL,COM0-COM9,LPT0-LPT9,COM¹²³,LPT¹²³,CONIN$orCONOUT$, in any case, with any extension and ignoring trailing dots and spaces (nul,sub\con,NUL.txt,aux .txt,aux:s). A device is opened whatever directory precedes it, so it bypasses the path rule;copy a.txt nulis refused too. - Trailing dots and spaces, for the same programs: a component, other than
.and.., that ends in.or a space (outside.,a.txt). Win32 strips them, sooutside.opensoutside. This also refuses git’s open rangeHEAD..(writeHEAD..HEAD) and afindstrpattern ending in.. - Programs that are not cmd.exe built-ins (
findstr,sort,git,grep, …), which may run under a runtime that re-parses the command line itself (MSYS2, Cygwin, Git for Windows):- an argument starting with
@(a response file whose lines become arguments:grep x @args.txt,git log @{1}) or~(a home directory); - an argument holding
{,},[,],',(or)(glob and quoting syntax):grep [ab] a.txtis refused on Windows, so the[/]apiform suggested below for a pattern starting with/is not available there; - a string the program might open as a path that starts with
/(/sub/a.txt,-f/x,--file=/x), which such a runtime reads from its own root rather than the workspace’s drive;findstrandsortkeep their native switches (see below), and on Windows a path of the form/x/...is also judged as drivex:’s path (/c/UsersasC:\Users), as such a runtime reads it; - a wildcard (
*,?) anywhere but the last component (*/a.txt,--exclude=*/target/*), in an absolute string or one with a..component, or in a last component with no literal character other than.(*,.*,??,*.*), which can match...grep x *.txt,grep x sub/*.scalaandfindstr /S /I x *.txtrun. The built-insdirandtypekeep the wildcard rule above (dir *runs).
- an argument starting with
findstr: a switch withFamong its letters (/F:list,-F:list,/SIF:list;/OFF[LINE]is allowed), which reads the names of the files to search from a file the path rule cannot see into; and a/D:value holding,or;(a directory list)./D:dirwith a single directory is held to the workspace like any path. An argument starting with/must be a switch of the nativefindstr.exe(reference), ignoring case: the flags/B /E /L /R /S /I /X /V /N /M /O /P, alone or combined (/SIN),/OFF[LINE], and/C:string,/G:file,/D:dir,/A:color(one or two hex digits), which may follow flags (/IC:x). The value of/G:and/D:is held to the workspace like any path. Anything else starting with/is refused (findstr x /etc,findstr /c:foo /c/x/secret,/Cwithout:) (#1738).sort:/O[UTPUT],/T[EMPORARY](any switch whose letter isOorT), a short-option cluster holdingo,O,torT, and--temporary-directory, which write the output or temporary files (a GNUsortearlier on thePATHtakes-tas its field separator; it is refused rather than guessed). An argument starting with/must be, whole and ignoring case, a switch of the nativesort.exe(reference):/R,/REVERSE,/+n(digits),/Lor/LOCALE,/Mor/MEMORY,/RECor/RECORD_MAXIMUM(each of these three takes the next argument as its value), and the undocumented/C,/CASE_SENSITIVEand/UNIQUE(ss64). Anything else starting with/is refused:sort /secret.txt,sort /c/Users/me/outside/secret.txt,sort /M:100(#1738).- Which
sortandfindstrrun (#1738). The/rules above read arguments as the native tools in the system directory read them; a GNU or MSYS2 build would open/c/Users/...asC:\Users\.... The runner searches the system directory beforePATHand never its own working or Java directory (see Program resolution, #1790), so it starts the system directory’ssort.exeandfindstr.exewhenever that directory has them. On a host whose system directory lacks them (some minimal images),PATHis reached; the switch rules still hold there. - Not refused, by reasoning:
- 8.3 short names (
PROGRA~1). A short name aliases an entry of the directory it is in, so it cannot climb out of that directory, and the path rule’s final step resolves the existing part of a path withtoRealPath, which expands short names before the comparison with the real root. A short name that does not exist names nothing, and refusing~followed by a digit would refuseHEAD~1. - Alternate data streams (
file:stream). The part before the:is judged, so..\outside\f:sis refused anda.txt:sruns.
- 8.3 short names (
git’s repository
git looks for its repository in the working directory and then in each directory above it, so a workspace that is a
subdirectory of a larger repository ran git on that repository: git show HEAD:secret, git diff, git log -p
and git status read files outside the workspace. The runner therefore starts git with GIT_CEILING_DIRECTORIES
set to the workspace root’s parent and without any GIT_* variable the runner’s own environment may carry - those
that point git at another repository or object store (GIT_DIR, GIT_WORK_TREE, GIT_COMMON_DIR,
GIT_INDEX_FILE, GIT_OBJECT_DIRECTORY, GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_NAMESPACE,
GIT_DISCOVERY_ACROSS_FILESYSTEM), add configuration (GIT_CONFIG_*, GIT_CONFIG_PARAMETERS, GIT_CONFIG_COUNT
with GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n) or name a program (GIT_EXEC_PATH, GIT_EXTERNAL_DIFF): a workspace
without a repository of its own gets not a git repository. GIT_CEILING_DIRECTORIES is a list split on the
path-list separator (: on POSIX, ; on Windows) with no escaping, so where the workspace root’s parent path - as
configured or with links resolved - holds that character, git is refused (PATH_ESCAPE_ATTEMPT) rather than run
with a ceiling it would misread. On every platform, git is also refused (PATH_ESCAPE_ATTEMPT) when the nearest
.git between the working directory and the workspace root is not a directory, or is one whose real path lies
outside the workspace (a gitdir: file, a link or a Windows junction points git at a repository elsewhere), and an
argument starting with : is refused (ARGUMENT_NOT_ALLOWED): pathspec magic (:/, :(top), :!x) and index
paths (:a.txt) are resolved from the repository’s top level, not the working directory.
git’s own files
git reads the repository’s .git/config, its attributes (.gitattributes, .git/info/attributes) and its hooks,
and runs the programs they name. Before #1721 an agent that could write
files, or a repository cloned into the workspace already hostile, made an allowed read run a program:
| Route | Run by | Defence | Test (GitConfigRoutesSpec) |
|---|---|---|---|
core.fsmonitor |
status, diff, ls-files, blame |
-c core.fsmonitor=false |
not run core.fsmonitor |
.git/hooks/post-index-change, core.hooksPath |
status, diff (index refresh) |
-c core.hooksPath=<empty dir>, GIT_OPTIONAL_LOCKS=0 |
not run a hook |
diff.external, diff.<driver>.command |
diff |
--no-ext-diff, -c diff.external=, driver blanked |
not run diff.external |
diff.<driver>.textconv |
diff, log -p, show, blame |
--no-textconv, driver blanked |
not run a textconv driver |
diff.<driver>.textconv on the staged diff |
status -v / -vv / --verbose (no --no-textconv) |
-v / --verbose refused for status (ARGUMENT_NOT_ALLOWED) |
refuse git status -v |
A driver whose name is not printable ASCII ([filter "\xE9vil"], [diff "é"]), which a -c override could miss |
status, diff, ls-files -m, blame, status -v |
refused (GIT_CONFIG_NOT_ALLOWED) |
refuse a filter or textconv driver whose name is not printable ASCII |
filter.<driver>.clean / smudge / process via .gitattributes or .git/info/attributes |
status, diff, ls-files -m, blame, log -p, show |
driver blanked (required=false) |
clean/smudge filter; process filter |
merge.<driver>.driver via a merge attribute (.gitattributes, .git/info/attributes), or merge.default |
log / show re-merging a merge commit: --remerge-diff, --diff-merges=r / remerge, or -m / --diff-merges=on with log.diffMerges=remerge |
driver blanked (-c merge.<name>.driver=), -c merge.default=, -c log.diffMerges=separate; --remerge-diff and --diff-merges refused (ARGUMENT_NOT_ALLOWED) |
not run a merge driver; not run merge.default’s driver |
gpg.program (log.showSignature) |
log, show |
-c log.showSignature=false, gpg.*.program a directory |
not run gpg.program |
Partial clone lazy fetch (remote.<n>.url ext::, core.sshCommand, a remote helper) |
show, log -p, blame |
GIT_ALLOW_PROTOCOL naming none, GIT_NO_LAZY_FETCH=1 |
not fetch a missing object |
A submodule’s own configuration (diff.submodule=diff, a gitlink’s drivers) |
status, diff, log -p, show |
--ignore-submodules=all, -c diff.ignoreSubmodules=all; the agent’s --ignore-submodules refused |
not start git in a submodule |
| A bare repository written into the workspace | any | -c safe.bareRepository=explicit |
not use a bare repository |
$HOME/.gitconfig, $XDG_CONFIG_HOME/git/config, system config |
any | GIT_CONFIG_GLOBAL the null device, GIT_CONFIG_NOSYSTEM, GIT_ATTR_NOSYSTEM, HOME / XDG_CONFIG_HOME an empty directory |
GitSandboxUnitSpec |
core.pager, pager.<cmd> |
a terminal only | --no-pager, GIT_PAGER=cat |
every route at once |
include.path / includeIf, hook.* |
any | refused (GIT_CONFIG_NOT_ALLOWED) |
refuse a repository whose configuration includes another file |
core.editor, sequence.editor, alias.* (which cannot shadow a built-in subcommand), credential.helper and
core.askPass are not reached by the allowed subcommands with no transport; the test with every route planted at
once includes them. Nothing else the allowed subcommands read names a program they run: difftool and mergetool
are not allowed; credential.*, url.*, remote.*, http.* and core.sshCommand are reached only by a transport;
submodule.<name>.update is read only by git submodule; and trailer.<token>.command runs only in
git interpret-trailers, never for a %(trailers) format. A %G? or %(signature) format, which would also verify a signature, is refused for its %.
So every git the runner starts has:
- Environment:
GIT_CONFIG_NOSYSTEM=1,GIT_CONFIG_GLOBALthe null device (/dev/null,NULon Windows),GIT_ATTR_NOSYSTEM=1,HOMEandXDG_CONFIG_HOMEan empty directory the runner made outside the workspace (git is refused,EXECUTION_FAILED, if it is not empty or lies inside the workspace),GIT_TERMINAL_PROMPT=0,GIT_PAGER=cat,PAGER=cat,GIT_OPTIONAL_LOCKS=0,GIT_NO_LAZY_FETCH=1andGIT_ALLOW_PROTOCOLnaming no transport, which overrides anyprotocol.<name>.allowthe repository sets. The system and global configuration of whoever runs the runner no longer apply, so asafe.directoryset there does not either; the runner passes its own (below). - Before the subcommand:
--no-pagerand-c core.fsmonitor=false,-c core.hooksPath=<empty dir>,-c diff.external=,-c log.showSignature=false,gpg.program,gpg.openpgp.program,gpg.x509.programandgpg.ssh.programset to the empty directory (which cannot be run),-c diff.ignoreSubmodules=all,-c safe.bareRepository=explicit,-c protocol.allow=never,-c log.diffMerges=separate(git’s default, so-mand--diff-merges=ondiff a merge against its parents rather than re-merging it) and-c merge.default=(a path with nomergeattribute uses the built-in merge), and-c safe.directory=<root>and-c safe.directory=<root>/*with the workspace root’s real path (see below). The empty name is used because no driver name is safe by itself: a repository’s[merge "text"]replaces git’s built-intextdriver (andunion,binary) just as it defines any other, while a[merge ""]it could select is refused (below). Command-line configuration wins over every file. - After the subcommand:
--no-ext-diff --no-textconv --ignore-submodules=allfordiff,logandshow;--ignore-submodules=allforstatus;--no-textconvforblameandgrep. The agent cannot undo them:--ext-diff,--textconvand--ignore-submodulesare refused, and so are--remerge-diffand--diff-merges(any value), which re-merge a merge commit and run the merge driver its attributes name;-m,-c,--cc,--ddand--no-diff-mergesstay allowed.git status -v(-vv,--verbose,-sv) is refused too: its staged diff runs textconv drivers andstatustakes no--no-textconv, while a blankedtextconv=would make it fail rather than skip the conversion. - Drivers: a filter, diff or merge driver is named by an attribute, which can be anywhere in the tree, and defined in
the configuration. Just before the command the runner lists that configuration (
git config --list --no-includes --show-scope -z, same directory and environment) and, for every driver it defines, adds-c filter.<name>.clean= -c filter.<name>.smudge= -c filter.<name>.process= -c filter.<name>.required=false(git then passes content through),-c diff.<name>.textconv= -c diff.<name>.command=, or-c merge.<name>.driver=(git cannot start an empty command, and keeps its own side of the merge). Aninclude.pathorincludeIf(an included file may sit in the work tree and change after the listing), ahook.*key, or afilter,difformergedriver name with any byte other than printable ASCII (0x21-0x7E) or with=or"refuses the command (GIT_CONFIG_NOT_ALLOWED), as do more than 200 filter, diff and merge drivers together, which bounds the command line the runner builds. The listing is read as bytes, so a name that is not UTF-8 (\xE9vil) is not decoded into U+FFFD and blanked under a name git does not use, and a non-ASCII name is never re-encoded for the command line in the JVM’ssun.jnu.encoding; only a name that reaches git byte for byte is blanked. A listing that fails, takes more than ten seconds or is over 1 MB refuses it too (EXECUTION_FAILED).
Ownership (#2014). git refuses a repository owned by another user
than its own (detected dubious ownership), and a workspace bind-mounted from a Linux host keeps the host user’s uid
while the runner’s container runs as root. git’s safe.directory check exists to stop a repository’s configuration
running a program as a user who does not own it, which the layers above already prevent, so the runner names the
workspace root - exactly, and with the /* suffix that git 2.46 and later reads as a prefix, for a repository in a
subdirectory - and never *: a repository outside the workspace is still refused (git’s repository discovery stops
at the workspace anyway). The configuration listing gets the same values, since without them git config --list
silently leaves out the local configuration of a repository it refuses.
Writes into .git are refused as well, which keeps an agent from planting any of this in a repository that is not
hostile to begin with: writeFile and modifyFile refuse (PATH_NOT_ALLOWED), and every program but the read-only
ones (ls, cat, grep, find, head, tail, wc, sort, uniq, diff, git, dir, type, findstr,
…) is refused (ARGUMENT_NOT_ALLOWED) when an argument names .git or a path inside one - as written, or where it
really leads through links. Names are matched as a file system may take them for .git: ignoring case and Unicode
normalisation, the code points HFS+ ignores, an NTFS stream suffix, trailing dots and spaces, and 8.3 short names
(GIT~1); .gitignore, .gitattributes and .github are ordinary names. A .git file anywhere (gitdir:) is
refused the same way.
Limits: a repository that arrives with core.worktree, .git/commondir or .git/objects/info/alternates still
points git at files outside (git reads them, runs nothing). A program added with WORKSPACE_EXTRA_COMMANDS that
writes files without naming them can still write into .git; the layers above still keep git from running what it
writes. The configuration is listed just before the command, so a concurrent command that swaps in another
repository between the two is not seen.
Command confinement
On Linux every execute command runs under llm4s-confine (built into the image at /usr/local/bin/llm4s-confine),
which applies a Landlock ruleset and, with networkAllowed = false, a seccomp filter before it starts the program.
Both are inherited by everything the command starts. A command that breaks a rule fails as any command does
(“Permission denied”); the runner does not refuse it. Design: §4.39.
What a command is granted:
- read and execute on
/usr,/bin,/sbin,/lib,/lib32,/lib64,/libx32,/etc,/optand the JDK; - read only on
/proc,/sys,/dev/urandom,/dev/randomand/dev/zero; read and write on/dev/null; - read, write and execute on the runner user’s home (
/rootin the image), where build tools keep their caches; - read and write on its own temporary directory (
TMPDIR), removed when it ends; - read and write on
/tmp, shared by every command, only when the runner’s JVM runs with both-XX:+DisableAttachMechanismand-XX:+PerfDisableSharedMem(the image’s does). The JVM attach socket lives in/tmp, so a command that could write there could otherwise attach to the unconfined runner. Without both flags the runner warns at startup and JVM tools such assbt, which write/tmpwhateverTMPDIRsays, fail confined. The runner keeps its own temporary files out of/tmp: the image sets itsjava.io.tmpdirto the owner-only/var/tmp/llm4s-runner. A runner started otherwise, whosejava.io.tmpdirlies in a path commands may write, refuses git commands (EXECUTION_FAILED, namingjava.io.tmpdir); - in the workspace, read and write on the root, or on each
allowedPathsentry instead, and read only on eachreadOnlyPathsentry; areadOnlyPathsentry that does not exist yet cannot be created.
Nothing in the workspace or TMPDIR is executable: a binary built there, or ./gradlew run as a program, fails with
exit status 126. A home or system grant that contains the workspace, or lies inside it, is dropped, so a workspace
under the home directory gets no home grant, and build tools run there cannot write their caches. With
networkAllowed = false, socket fails for every family but AF_UNIX.
Limits. With a read-only path, a command cannot create, delete or rename entries directly in the directories
above it (with readOnlyPaths = ["ro"], in the workspace root); the runner’s own file operations still can. Landlock
has no metadata rights, so chmod, chown and timestamps on a read-only path are not refused, only its content. An
existing hard link into a read-only file can write it, and a read-only symlink protects its target, not the link.
/proc is readable: another process’s environ and mem are not, but its cmdline and status are. Below
Landlock ABI v6 (kernel 6.12), abstract Unix sockets stay reachable without network and a command can signal the
runner; from v6 a command reaches only abstract sockets, and signals only processes, inside its own sandbox
(#2009). The runner logs at startup which of these apply. A daemon a command starts (setsid)
stays confined, and outlives the command unless the container gives commands cgroups (below,
#2008). The runner’s own
helper programs (the git configuration lister, getfacl, setfacl) run unconfined, so on Linux they are taken from
/usr/bin or /bin only, never from PATH, which includes the writable home directory.
When it cannot confine (no helper, Landlock below ABI v3, or a failing call), the command is refused with
SANDBOX_UNAVAILABLE and never starts. Off Linux (macOS, Windows) commands run unconfined, under the command
policy only, and the runner logs this once. An amd64 image run under emulation (Docker Desktop’s Rosetta on Apple
silicon) refuses every command SANDBOX_UNAVAILABLE, since Landlock is unavailable there; a local
sbt workspaceRunner/Docker/publishLocal builds for the host architecture, which confines.
A cgroup per command (#2008). The runner kills a command’s process
group when it ends, times out or is cancelled, but a daemon (setsid) has left the group. Where the container’s
cgroup v2 hierarchy is writable, each confined command instead joins a cgroup of its own before it starts, and the
runner kills that cgroup whole (cgroup.kill, Linux 5.14): nothing the command started outlives it. Docker mounts
the hierarchy read-only, so the container must be started with
1
docker run --cgroupns=private --cap-add SYS_ADMIN --security-opt apparmor=unconfined ...
which ContainerisedWorkspace(..., commandCgroups = true) does. The image’s entry point uses SYS_ADMIN only to remount
the container’s own cgroup (its private namespace) read-write, and drops it from the bounding set before the runner
starts, so neither the runner nor a command holds it; AppArmor’s docker-default profile is off because it refuses
every mount. The runner logs at startup whether commands get cgroups and, if not, why; without them it behaves as
before. Off by default. A program that calls clone3 with CLONE_INTO_CGROUP itself can still start a process in
another cgroup of the container; no allowlisted program does.
Container egress
With networkAllowed = false (the default, and every built-in profile’s) the container has no network out
(#870), not just its commands: nothing in it, the runner included, can
open a connection to another host or container. ContainerisedWorkspace starts it with
1
docker run --cap-add NET_ADMIN -e LLM4S_NO_EGRESS=1 ...
and the image’s entry point sets the container’s firewall (IPv4 and, where the container has it, IPv6): only
loopback and the replies to connections the container accepted (the runner’s published port) may leave. It then
drops NET_ADMIN, as it drops SYS_ADMIN, before the runner starts, so neither the runner nor a command can undo
the firewall. When the firewall cannot be set, the entry point exits (status 78) and the container does not start:
the sandbox asked for no network. A runner started without LLM4S_NO_EGRESS=1 (a docker run by hand) logs at
startup that only its commands are kept off the network. With networkAllowed = true none of this applies.
To set these fields in a container, pass the whole config; the runner receives it as WORKSPACE_SANDBOX_CONFIG:
1
2
3
4
5
val workspace = new ContainerisedWorkspace(
dir, image, 8080,
extraAllowedCommands = Set("sbt"),
sandboxConfig = Some(WorkspaceSandboxConfig.Permissive.copy(readOnlyPaths = List("docs"), networkAllowed = true))
)
Security Gaps Addressed
| Gap | Phase 1 | Phase 2 |
|---|---|---|
| Explicit config | ✓ WorkspaceSandboxConfig | |
| Validation at startup | ✓ | |
| Shell allow/block | ✓ shellAllowed | |
| Resource limits | ✓ limits configurable | |
| Read-only areas | Config present | Enforced (file operations; commands on Linux, Landlock) |
| Allowed/blocked paths | Config present | Enforced (file operations; commands on Linux, Landlock) |
| Network restrictions | Documentation only | Enforced on Linux (seccomp), and the container’s egress blocked (Container egress) |
Example: Locked-Down Sandbox
Run the minimal demo (local filesystem, no Docker):
1
sbt "workspaceSamples/runMain org.llm4s.samples.workspace.LockedDownSandboxDemo"
Run the containerized runner with locked sandbox:
- After
sbt workspaceRunner/docker:publishLocal, get the image tag:1
docker images llm4s/workspace-runner --format "{{.Tag}}"
Use that tag (for example
0.3.2or a dynver snapshot such as0.3.2+abc123-SNAPSHOT) in place ofTAGbelow. - Run the container (replace
TAGand the host path to your workspace):1
docker run --rm -e WORKSPACE_SANDBOX_PROFILE=locked --cap-add NET_ADMIN -e LLM4S_NO_EGRESS=1 -v /path/to/workspace:/workspace -p 8080:8080 llm4s/workspace-runner:TAG
On Windows with Docker Desktop, use a path Docker can mount (e.g.
C:\Users\you\workspaceor//c/Users/you/workspacedepending on your setup).
Phased Implementation Plan
Phase 1: Config + docs + sample ✓
- Affected: workspaceShared, workspaceRunner, workspaceClient, workspaceSamples, docs
- Complexity: Low
- Risks: Minimal; backward compatible (default = permissive)
Phase 2: Enforcement ✓
- Done (#1906): the runner refuses any file operation, and a command’s
working directory, outside
allowedPaths(PATH_NOT_ALLOWED), and any mutation (writeFile,modifyFile,deleteFile) underreadOnlyPaths(PATH_READ_ONLY). A write overmaxFileSizeisSIZE_LIMIT_EXCEEDED, and a command keeps at mostmaxOutputSizebytes of each stream, UTF-8 and JSON-escaped (or the client’s smallermaxOutputBytes), while it reads, whatever its lines. - Done (#1983): on Linux the kernel confines every command, so
allowedPathsandreadOnlyPathsbind what a command and its children touch, whatever its arguments, andnetworkAllowed = false(the default) leaves commands no network. See Command confinement. - Done (#870): with
networkAllowed = falsethe container itself has no egress (Container egress), and the path policy is one value,WorkspacePathPolicy, whose checks resolve every..and symbolic link before comparing a path withallowedPathsandreadOnlyPathsand return a refusal naming the path, which the runner reports asPATH_ESCAPE_ATTEMPT,PATH_NOT_ALLOWEDorPATH_READ_ONLY. - Compare-and-set.
fileSnapshot(path)returns what is at a path with the SHA-256 of its bytes (sha256:<hex>,absentordirectory);writeFile(..., expectedHash)anddeleteFile(path, expectedHash)apply only if the hash is still that one (HASH_MISMATCHotherwise, changing nothing), under one lock every file operation of the runner takes, and the write replaces the file atomically. The harness’sWorkspaceFileBackendis built on them.
Phase 3: Advanced policies (optional)
- Affected: New policies module, profiles (dev/staging/prod)
- Complexity: High
- Risks: Over-engineering; maintenance burden