This document describes the threat model and how each defense works. Nothing here is secret -- the LLM can read every file it is described in, including this one. The defenses are tamper-resistance, arranged so that the steps a model would need to take to defeat one are blocked by another.
The starting point. LIM runs as the dedicated $LIM_AI_USER account. Within that account the LLM is not confined: it can read, write, and execute anything the account can, and it has a shell and network access. Assume its input includes untrusted content -- web pages, cloned repositories, PDFs, whatever files you point it at -- any of which can carry prompt injection. The defenses below stop the LLM from reaching out of its account; they do not replace review. The code, commits, and commands it produces are for you to review before you run, commit, or push them.
- Modifying your files outside the trees you explicitly shared with
aishare. - Executing code as you via git. Git runs code from a gitdir's
config(core.hooksPath,credential.helper,core.sshCommand, ...) and from itshooks; a file planted at the right name in the right gitdir runs under your identity the next time you commit, fetch, or open the repo. - Outliving the session. Scheduled jobs (cron/at) that fire later, outside any session, and invisible to the suspension below.
- Racing the sharing mechanism. Changing ownership or planting files in the middle of an
aisharerun.
The binary checks getuid() at startup and refuses to run unless it is $LIM_AI_USER; the account is a regular user without sudo, with a locked password and key-based SSH only. This confines the LLM's direct access to that account.
You are a member of the $LIM_AI_USER group so that access inside shared trees is symmetric: the LLM creates files with umask 0002 (group read/write), and aishare group-shares your files in the trees it grants.
Cron and at are denied (/etc/cron.deny, /etc/at.deny), enforced by the crontab/at binaries themselves (root-owned files in /etc), which the LLM cannot bypass. Beyond "the LLM should not schedule jobs," there is a mechanical reason: a cron job is a child of crond, not of any exec_shell command tree, so aishare's suspension cannot see or stop it. A job the LLM planted could fire during an aishare run and race the ownership changes, or keep a foothold that outlives the session.
aishare grants a directory tree to the LLM: it sets ownership to $USER:$LIM_AI_USER (recursively over the shared trees, including any planted hook it re-owns before disabling it, and non-recursively over the home dir itself on a home-level run), grants group read/write and setgid, and clears the sticky bit. It refuses targets outside /home/$LIM_AI_USER and the store itself. When run on /home/$LIM_AI_USER, it fixes permissions on the home directory itself plus all top-level entries, skipping .ssh and .gitstore.
The chown needs root, so aishare works through aishare-helper, a small root-owned helper installed mode 0700 so the LLM user cannot modify its checks, invoked by a single passwordless sudo rule. A bare rule such as chown ... /home/$LIM_AI_USER/* is not safe: in sudoers, * matches / and .., so the glob does not confine the path. The helper re-validates every path itself -- refusing anything that leaves /home/$LIM_AI_USER lexically or has a symlink component -- and the chown identities it may set are fixed inside it.
The helper performs the operations aishare and the git wrapper need: the ownership changes above; handing each gitdir's state files (HEAD, index, ...) to $LIM_AI_USER with chown -h, so the chown acts on the name itself and cannot follow a symlink the LLM planted under one of those names; pinning and unpinning .git pointer files; and, during an aishare run, suspending the LLM's exec_shell command trees -- sweep-stop stops every LLM-user process carrying an exec_shell marker fd (the mechanism below) and prints the pids for aishare to resume, while stop/cont suspend/resume given PIDs by hand (only PIDs owned by the LLM user are accepted).
/var/tmp/lim.aishare.lock is created by aishare before any change and removed in its exit trap. It is pure mutual exclusion between aishare runs (lim never reads it); the sticky /var/tmp stops the LLM from removing or replacing it. An existing lock -- a concurrent aishare, or one left by an interrupted run -- aborts the run: wait for it to finish and re-run, or rm /var/tmp/lim.aishare.lock if no aishare is running.
While running, aishare blocks the LLM's exec_shell (the LLM's other tools keep working) and suspends the LLM's exec_shell command trees -- in-flight and previously backgrounded -- resuming them when done, so the LLM cannot race the ownership changes. The suspension has two parts, each covering the other's one blind spot.
(1) The marker sweep. Every process an exec_shell call started carries an open fd to that call's marker file (/tmp/lim_execfd_*, opened as the first line of the command script, before anything else runs): aishare asks the root helper to stop every $LIM_AI_USER process holding one (aishare-helper sweep-stop) and resumes them (SIGCONT) in its exit trap. The fd survives backgrounding, setsid, orphaning and exec, so the sweep catches in-flight and leftover trees alike -- including setsid'd members that left their process group -- and nothing outside an exec_shell command tree can carry the fd, so lim itself, your terminal, and the long-lived services keep running. Its one blind spot -- a process that explicitly closes the fd (a daemon that closes all fds) -- exists only once that process is orphaned, and while lim runs part (2) covers it.
(2) The LOCK. With a live lim, aishare also sends LOCK over lim's Unix socket (/var/tmp/lim.query): lim blocks new exec_shell calls at its in-memory gate (they wait, bounded by 15 minutes, after which they report the stale lock) and SIGSTOPs the exec_shell process groups it records in memory (idempotent), and the exit-trap UNLOCK reverses both. The record and the gate live in lim's memory -- any file lim writes is writable by the LLM's own commands, so a file cannot be trusted -- and the exchange is authenticated both ways: lim accepts only a peer whose kernel-attested SO_PEERCRED uid is the sharing user's (the owner of /home/$LIM_AI_USER, which the LLM cannot chown), and aishare accepts only a peer whose pid and uid are lim's and whose /proc starttime still matches the snapshot it took before locking -- a socket the LLM bound at the same path, or a recycled pid, cannot answer. Because the record and the gate are in lim's memory, the run requires kernel.yama.ptrace_scope of 1-3 (check: cat /proc/sys/kernel/yama/ptrace_scope; set, persistently: echo "kernel.yama.ptrace_scope = 1" | sudo tee /etc/sysctl.d/60-yama-ptrace.conf && sudo sysctl --system): at 0 the LLM could ptrace lim and rewrite them, so aishare refuses to run while lim is active, and lim warns at startup.
With no lim running there is nothing to lock: the sweep is the whole suspension, covering the trees a crashed lim left behind (its exit cleanup then did not run). When lim exits, its still-recorded exec_shell process groups are terminated (SIGTERM, so orphaned background jobs do not outlive the session) and it removes the socket.
Recovery. If aishare is killed while locked, rm /var/tmp/lim.aishare.lock and re-run it -- its LOCK is idempotent, its exit UNLOCK releases the group stop, and its sweep-and-resume covers the processes the killed run stopped. If lim is killed or restarted while aishare runs, the UNLOCK fails and aishare warns -- the trees stay suspended until the next aishare run (while lim is running) or sudo /usr/local/bin/aishare-helper cont <pids>.
The git wrapper lives in your ~/bin, ahead of the real git in PATH (it locates the real git automatically -- the first other git in your PATH, each entry resolved physically so a . or a symlink pointing at its own directory is skipped and it never invokes itself -- and LIM_GIT_BIN forces a specific binary if needed). Every invocation by the LLM user, and every invocation of yours that does not reach a shared gitdir, is a plain pass-through (never sudo). When your command reaches a shared repo -- its gitdir under /home/$LIM_AI_USER, in the store or an in-place bare/custom-named gitdir, however git is pointed at it (your working directory, git -C <dir>, --git-dir, or GIT_DIR from anywhere) -- the wrapper does three things.
1. It protects the gitdir for the duration of the command. It temporarily removes group write from the gitdir and deletes any symlinks the LLM planted. Git never creates symlinks in a gitdir; a planted one would let git's in-place writes (reflogs, MERGE_MSG, the index, ...) land in a file the LLM chose -- write-through to an arbitrary path under a name git will write. Removing group write first means the LLM cannot re-plant a symlink between the removal and git's in-place write. Group write is restored as soon as git exits -- except on the config, config.worktree, commondir, gitdir, and hooks names that aishare keeps not group-writable, which stay protected -- so the LLM is only blocked for the duration of your command.
The window is announced to the LLM with /var/tmp/lim.gw.lock (pid + starttime inside; the same mechanism as aishare's lock -- created before the removal, removed after the restore, on every exit path): /home/$LIM_AI_USER/bin/git keeps a concurrent LLM git write from failing with Permission denied on a git lock file as if the share were broken: a known read-only command runs straight through (GIT_OPTIONAL_LOCKS=0 also suppresses status' opportunistic index refresh), and every other command is run under a Landlock probe that allows writes only to a scratch dir, so it either completes (it wrote nothing to the repo) or -- if it would write -- waits for the window to close and then runs for real. Without Landlock it simply waits. A stale lock (dead or reused pid), or one held by a process that is not a live wrapper of yours, is taken over; only a lock naming a live wrapper of yours is joined -- so the run always proceeds protected, never unprotected.
2. It sandboxes your git with Landlock (set LIM_GIT_SANDBOX=0 to disable). Git and its children (editor, pager, hooks, credential helpers) can write only under /home/$LIM_AI_USER (plus /dev/null and /dev/tty), with no new privileges -- so code git is tricked into running cannot write your files or use your sudo. It can still read your files and reach the network; that is not contained, and is why sensitive material should not live in the AI's home. Inside the sandbox, writes by git and its children to anything outside /home/$LIM_AI_USER -- global config, editor history, credential caches -- fail; that is the point of the confinement. The sandboxed temp area is redirected to /home/$LIM_AI_USER/.git-tmp (the sandbox blocks /tmp), so subcommands that create scratch files, such as git difftool, keep working. The sandbox needs kernel >= 6.7 and setpriv from util-linux >= 2.40; on older systems the wrapper warns per invocation and runs git unsandboxed (the group-write window above still stops the discovered write-through class).
3. It re-shares the state files afterwards. When your git rewrites the gitdir's volatile state files (index, HEAD, ...), the wrapper hands them back to $LIM_AI_USER (via the helper's chown -h), so the LLM is never blocked waiting for an aishare re-run. If a rewrite bypassed the wrapper (your editor's own git, a script that calls the real git directly, ...), the next git command you run in the repo (even just git status) re-shares it.
Since git runs code from a gitdir's config (core.hooksPath, credential.helper, core.sshCommand, ...) and from its hooks, the LLM must never be able to swap a repo's gitdir for one of its own, or plant a file at a code-executing name in your gitdir.
- The gitdir is moved, the checkout is not. Each checkout's
.gitdirectory is moved into a store at/home/$LIM_AI_USER/.gitstore(mirroring the path) and replaced with thegitdir:pointer file git itself uses for worktrees, pinned immutable (sudo /usr/local/bin/aishare-helper chattr +i). The store is group-traversable but not group-writable, so the stored gitdir cannot be renamed or deleted; the.gitfile looks exactly like git's own worktree pointer, so anything that goes through git is unaffected. Ifchattris not available on the filesystem the pin fails and aishare warns. - Before re-owning anything, aishare checks that every
.gitpointer resolves to an existing gitdir owned by you, and it refuses to share (no chown, non-zero exit) if any gitdir it would re-own is not owned by you or the LLM and carries an executable hook or config directive -- a plant, left inert under git's ownership check until you remove it. A LLM-owned gitdir (e.g. a repo the LLM cloned) is shared, but itsconfig,config.worktree,commondir, andhooks/are reset (unlinked and recreated with fresh inodes) after the chown so any plant the LLM left -- and any file descriptors it still holds open -- are invalidated;remote.*andbranch.*settings are preserved (droppingext::URLs, which run a command). - Inside every gitdir,
configandhooksare owner-owned and not group-writable (pre-created if absent, so the LLM cannot create its own). The gitdir itself is group-writable and sticky (3770): the LLM can create new files (lockfiles, loose objects) -- so its commits keep working -- but the sticky bit lets it unlink or rename only entries it owns, so it cannot replace the owner-owned files. The state files (HEAD,index,packed-refs, ...) are kept owned by$LIM_AI_USER, so it can replace them as the committer. Two corollaries: LLM-side git commands that need to write the config (e.g.git submodule init) fail until you make the change yourself, and when you run a git command that rewrites the state files (commit, add, rebase, gc, fetch), thegitwrapper above re-shares them automatically; if a rewrite bypassed the wrapper (your editor's own git, a script that calls the real git directly, ...), the next git command you run in the repo (even justgit status) re-shares it. - Two more files in each gitdir are locked down. Besides
configandhooks, git reads a gitdir'scommondirandconfig.worktreefiles, and a file the LLM planted at either name would make your git run the LLM's config. aishare pre-creates both, owner-owned and not group-writable; if it finds a planted one it neutralizes it and warns you -- then remove the gitdir thecommondirnamed, or re-add any legitimate per-worktree config. aishare and the git wrapper also report any top-level file in a stored gitdir that is not owned by you -- if you see such a report, review and remove the file. - Planted hooks are disabled, not removed: an executable, non-sample hook not owned by you is warned about, stripped of its executable bit, and frozen; if it is legitimate restore it with
chmod +x. If aishare could not disable a hook, it reports that explicitly: the hook is still executable -- review it before your next commit. A symlink in a hooks dir that is not yours is flagged but left in place, since disabling it would act on whatever it points to, which might be your own script. - Re-run
aishareafter creating worktrees or submodules (new pointers are not yet pinned), and to re-pin after unpinning: a git operation that must rewrite or delete a pinned pointer (e.g.git submodule deinit,git worktree remove) fails until you unpin it (sudo /usr/local/bin/aishare-helper chattr -ion the.gitfile). Bare repos and custom-named gitdirs (git init --separate-git-dir) stay in place and get the in-place protection above; thegitwrapper protects their gitdir like a stored one (symlink pre-check, state-file re-share) when you run git in them. Store entries left behind by a move can be deleted by hand.
After any report. If aishare or the git wrapper reports anything -- a refused third-party gitdir, a neutralized planted commondir or config.worktree, a top-level file in a stored gitdir you do not own -- review and remove it, then re-run aishare in the directory so it re-validates the tree and the share is complete.
The dubious-ownership refusal is a security layer. Git's "detected dubious ownership" refusal is what keeps a gitdir the LLM created or swapped inert: git will not operate a repo whose gitdir it does not own, so a planted or swapped gitdir cannot run hooks as you even if something is pointed at it.
git addandgit cleanare restricted for the LLM./home/$LIM_AI_USER/bin/gitblocksgit add -A/--all/.andgit clean, so the LLM cannot stage untracked files in a shared repo -- which would sweep your untracked files into its commits -- or delete them. It is a script in the LLM'sPATH, so it is a guardrail rather than a boundary (a model that invokes the real git directly bypasses it); the boundary is that anything staged shows up in a commit you review.umask 0002in the LLM's~/.bashrcmakes everything it creates group-readable and group-writable, which is what makes the shared trees symmetric.- No push credentials. The LLM should clone public repos and commit locally, and should not be given the authentication to push to your remotes. If you choose to give it push access at all, use the narrowest scoped credential you can: it sits in a sandbox with network access, so treat it as exfiltratable.