Skip to contents

gptr runs language model agents in your current R session. An agent reads files, writes files, evaluates R code written by the model in the environment you give it and starts processes on your behalf. This page describes what gptr does to keep those actions under your control and where its protections end. gptr_egress describes what is sent to model providers.

Everything happens because you asked

When the package is loaded, it only stops the child processes that an earlier gptr session left running after it was killed or crashed, and removes their records in tools::R_user_dir("gptr", "cache"). A model is contacted only when you call peter() (or a function that you give a prompt), and model-written code is evaluated only in the environment you pass as envir (by default the frame that called peter()); gptr never assigns into the global environment by itself. Files are written only into paths you pass to a gptr function (for example to in gptr_export() or paths in gptr_scrub() with dry_run = FALSE), inside the project's .gptr/ directory once it exists (see gptr_init()), inside tools::R_user_dir("gptr"), inside the session temporary directory, into files you bound with gptr_doc() or confirmed, and by tool calls that the permission mode allowed.

Permission modes

Every tool call passes a permission gate. The default mode is auto: the agent runs R code and changes files and objects without asking, and gptr asks only for level-4 actions (for example deleting the project directory or a file outside the project, where a system temporary directory such as /tmp counts as outside, moving R's working directory out of the project, or changing gptr's own configuration) and for reads of registered secrets. The static classifier that sets these levels is advisory, not a security boundary (see below). In manual, actions that the classifier labels read-only run without asking; every other action it recognizes, including a change to a file or an object, asks first with a one-line prompt. edits also allows file edits inside the project and still asks before R code that is not known to be read-only. Choose another default with gptr_config(mode = "manual", .scope = "user"), one call's mode with peter(mode = ), and switch in the console with /mode. yolo, which only you can select (a project setting or model code in another mode cannot), also runs gptr's own configuration functions, writes to R startup files such as ~/.Rprofile (which can change gptr's options in the next R process) and secret reads without asking, and still asks before deleting protected files, files outside the project or the project itself, moving the working directory out of the project, rm(list = ls()), options(gptr.*) and sending a secret over the network (see Secrets below); plan changes nothing, though a call it reads as read-only can still use the network or start a process: gptr_models(refresh = TRUE) downloads the model catalog or, with provider =, asks that provider for its models with its credential (starting the claude or codex tool for those), and gptr_providers() with check = TRUE or check_login = TRUE contacts the providers or starts the claude and codex status commands. In every mode r code that calls q(), readline() or another function that would end, pause or hang your R session is refused without a question. In auto and yolo mode a system(), system2(), pipe(), processx::run() or data.table::fread(cmd =) call (on Windows also shell() or shell.exec()) whose command the code computes is refused (see below). When nobody can answer a question (Rscript, knitr, a scheduled job) the run stops with status blocked and a gptr_error_permission condition that says how to allow the action, unless you set options(gptr.noninteractive_ask = "deny"). Model code cannot switch the gate off or loosen it during a run: the safety options are copied when the run starts. Only the option gptr.unsafe_no_permissions, set by you outside a run, removes the gate, and it is meant for disposable sandboxes.

Changing gptr's own configuration includes model code that sets or unsets an environment variable gptr reads as configuration: a key or base-URL variable of a provider gptr has registered (such as AWS_REGION, which places Bedrock's endpoint), a variable gptr keeps for the claude or codex command-line tool (its login, its folder or the path of Git Bash, such as CODEX_HOME), or one that moves its configuration folder or your home directory, such as HOME; gptr_options lists them. The classifier reads such a change in Sys.setenv(), Sys.unsetenv(), withr::local_envvar() and withr::with_envvar(), where a name it cannot read counts as one (also one built with paste0() or another helper of base R whose bare name the code binds with =, <- or <<-, as a function's argument or as a for variable, or that your session holds as other than base R's, and the names passed to a setter handed to lapply(), Map(), do.call() or another function the classifier knows calls it, such as sapply() or purrr::map(); do.call() of a list() or c() written out and rlang::exec() are read as the call they make, so do.call(Sys.setenv, list(TZ = "UTC")) is Sys.setenv(TZ = "UTC")), in readRenviron() and dotenv::load_dot_env(), and in an os.environ write in the code of peter$py() or peter$knit("python", code) that names one in a string or an upper-case word, or whose name (a subscript, or the first argument of putenv(), unsetenv() or pop()) is not a plain string literal. It does not read code in a file R runs (source(), sys.source(), eval(parse(file = ))); Sys.setenv(), Sys.unsetenv(), withr::local_envvar() or withr::with_envvar() reached by a computed name, through a list or an environment, or handed to a function the classifier does not know calls it (get("Sys.unsetenv"), baseenv()$Sys.setenv, asNamespace("withr")$local_envvar, with(list(f = withr::with_envvar), ...), assign("f", Sys.unsetenv), identity(withr::local_envvar)); a name built with a helper the code binds otherwise (with assign(), delayedAssign(), makeActiveBinding(), list2env() or attach(), in a list given to with() or within(), or into an environment, e$paste0 = f or .GlobalEnv[["paste0"]] = f), which is read as base R's helper builds it; a Python write that reaches os.environ by another name (e = os.environ, getattr(os, "environ")) or through ctypes, or that passes os.environ.update() a mapping the code computes, a mapping whose names are not plain string literals ({'\x48OME': d}, {'H' 'OME': d}) or keyword names not all in upper case (on Windows os.environ.update(home = d) sets HOME); or Python run through 'reticulate': such code is level 3 or lower, which auto runs without asking.

What the gate cannot do

The risk levels come from a static classifier (gptr_risk()). It is advisory and it is not a security boundary: R code can compute function names, call compiled code or load packages whose effects the classifier cannot see, and R has no sandbox for code that runs inside your session. The classifier reads code as written and does not run it, so code that builds a call, a name, a path or a command at run time, or reaches a function by another name, is read only as far as the classifier can see. Each form this page names as not read is of that kind, or is code in a file or a package, code another interpreter runs, or a call or argument the classifier has no rule for. A function it has no row for, such as gptr_step() or gptr_wait(), reads level 1, which manual asks about and auto runs (gptr_export() called from model code is refused when it runs). The code in the braces of a 'glue' or 'cli' template (glue::glue("{unlink(d)}"), stringr::str_glue(), cli::cli_text()) runs when the text is formatted and is not read. Deny and ask sh: rules see a command computed at run time only in a peter$sh() or peter$bg() call, which checks the command when it runs. So in auto and yolo mode a system(), system2(), shell(), shell.exec(), pipe(), processx::run() or data.table::fread(cmd =) call whose command (for system2() also its arguments and env) is not a string the classifier can read, such as cmd = paste("rm", "-rf", "build"); system(cmd), is refused, and the model is told to run the command with peter$sh(); manual and edits ask. An allow rule such as r(fn:system) lets such calls run, unchecked by sh: rules. Neither the rules nor the refusal read what a shell reads when it runs: its standard input (system("sh", input = cmd), peter$sh("sh", input = cmd)), variables it expands (sh -c "$X", eval $X) or a script file. The refusal covers only calls the classifier resolves to these functions: a function reached by a computed name or through a list or an environment (get("system")(cmd), baseenv()$system(cmd)) or handed to a function of your own (g(system)), eval(parse()), a sourced file, package code and other command runners such as processx::process$new() or sys::exec_wait() still run a computed command unchecked. A literal command is read when it is given to system(), system2(), peter$sh(), processx::run() (also as callr::run()), sys::exec_wait(), sys::exec_internal() or sys::exec_background(), not when it is given to processx::process$new(), which is level 3. A command line in a quoted string is read as one the code runs, so system("echo 'rm -rf /'") reads level 4, as system("ssh host 'rm -rf ~'") does.

Paths are placed in the project: a relative path in R code is read in the project directory, and a command in the directory it runs in (after a cd or env -C, or the wd of peter$sh() or processx::run()), the code a shell or Python runs there (sh -c, cmd /c, pwsh -Command, python3 -c) included; running a command in a directory outside the project reads that directory, so manual asks. setwd(), withr::local_dir(), withr::with_dir() and xfun::in_dir() to a directory outside the project and R's session temporary directory (which tempdir(), tempfile(), withr::local_tempdir() and withr::local_tempfile() name), and setwd() and withr::local_dir() to one the code computes (such as here::here(d); here::here() of literal parts is read in the project), are level 4, because a relative path would then name a file outside the project, and so are file.symlink(), file.link(), Sys.junction() and fs::link_create() of a path outside the project, as ln of one is; chdir() in the code of peter$py() or peter$knit("python", code) (os.chdir(), os.fchdir(), contextlib.chdir()), which moves R's working directory too, is read as setwd() is. After the code has moved R, a relative directory given to these functions is read in the directory R is in, so setwd("data"); ...; setwd("..") returns to the project, as do os.chdir("data") and os.chdir("..") in Python when each is a statement of its own on a line with no indentation, no : and no bracket left open, in code with no triple-quoted string (after any other chdir() a relative directory is read both in the directory R was in and in the one that chdir() names); before any move it is read in the project. Python comments are not read as code, except in code with a triple-quoted string, which is read with its comments. Python's restore idiom cwd = os.getcwd(); os.chdir("data"); os.chdir(cwd) returns to a directory the code computes, so it asks even in auto and yolo. getwd() and the directory setwd() returns are read as the one the code has moved R to, starting from R's working directory when the classifier reads the code. A function body and the code of local() are read as code of their own: the names they assign are followed (a name assigned with <<- or assign() counts, outside them, as one the code computes), a function's other names count as ones the code computes, and R starts where the code started or has moved it to. So owd = setwd("data"); ...; setwd(owd) stays in the project at the top level of the code, in a function (with on.exit(setwd(owd))), in local() and in tryCatch(finally = setwd(owd)). A directory the code computes that R moves back from is level 3: that of withr::with_dir() or xfun::in_dir(), and one saved with a plain owd = setwd() or owd = getwd() in a branch or a loop (if (p) owd = setwd("data")), but only for setwd(owd) in the scope that saved it and only when the code binds that name no other way anywhere (to another value, as a loop variable or a function's argument, with <<-, assign() or list2env(), or by an assignment in eval() or with()); otherwise setwd(owd) to a directory the code computes stays level 4. A relative directory after withr::with_dir() or xfun::in_dir() counts as one the code computes. A drive-relative path such as D:data counts as outside on every OS. The classifier does not follow the working directory changed in other ways (such as usethis::local_project(), get("setwd"), the wd of callr::r(), or env given -C among other short options, env -iC DIR, or as an abbreviated --chdir, env --chd=DIR), nor read the code another interpreter runs (Rscript -e, perl -e, node -e, pwsh -CommandWithArgs or -cwa), a path the shell computes (rm "$f" in a loop, xargs rm) or code handed to sh -c or bash -c as one word whose spaces are escaped with a backslash or written $IFS (sh -c rm\ -f\ file): such a command is level 3, which auto and yolo run without a question whatever it deletes. The wd of processx::run() is read when the call, or a name the code assigns, holds it as a string; a wd the code computes is read as the project directory. A delete function handed to lapply(), Map() or purrr::walk() reads its paths as ones the code computes, level 3, so auto runs lapply("~/notes", unlink) without a question.

In auto, the default, and in yolo a model can delete or overwrite files and objects without asking. Use them in projects you can restore (version control, backups, gptr_rewind() for recent turns), choose manual elsewhere, and run untrusted prompts or untrusted projects in a disposable container or virtual machine.

Sub-agents, workers and child processes

Inline sub-agents run in your session and see its objects. The worker backend runs a sub-agent in a separate R process that starts from gptr's reduced child environment (it does not read your ~/.Renviron), but that process runs under your user account with your file permissions: the worker backend is not an isolation boundary. Its permission requests are sent to your session and classified again there. Your session reads a worker's result file with readRDS(): on R before 4.4 a crafted result file can run code in your session, and the objects a worker returns are R objects by design. gptr_coach() runs every run and every coach as an unattended session in its own R process under your account, which is not a sandbox either; a fence keeps a coaching run's writes in its own folder as far as the classifier sees them, and Codex's own shell is off in coaching sessions. Elsewhere, on the codex route Codex's own shell runs commands in every mode without passing gptr's gate, rules or secret guard: in plan, manual and edits its sandbox is read-only, so it can still read any file your account can read, and in auto and yolo it also changes and deletes files inside the project within its sandbox. MCP servers, the claude and codex command-line tools, shell commands started with peter$sh() and Shiny artifacts are ordinary processes of your account as well; artifacts start without any registered secret and listen on the loopback interface, and each launch gets an access token in its address (on Windows only when 'openssl' is installed; otherwise gptr says that the artifact has no token).

Untrusted content

Model replies, tool results, file contents, MCP results and project instruction files (AGENTS.md, CLAUDE.md, .gptr/vignette.Rmd) are treated as data. Text from these sources is never used as a formatting template, so braces in a reply cannot run R code. A project you cloned is untrusted until you trust it with gptr_trust(trust = TRUE) (see gptr_trust()), or answer yes when gptr_init() asks: until then its settings can only tighten permissions, its extensions, plugins and MCP servers do not run, and its instruction files are shown to the model as information rather than commands. When trusted files change after a pull, gptr asks again.

Secrets

Keys are held in a private vault and appear in sessions, logs, errors and permission questions only as markers such as [secret:ANTHROPIC_API_KEY]. Values are redacted before anything is written or sent: the session files, documents, caches, spill files, wire logs and the output of child processes. Their URL-encoded, JSON-escaped and base64 forms are redacted too; a copy the code changes in another way, such as reversed or cut, is no longer recognized and is not redacted. The console shows what model code prints with registered secrets redacted where it indents that output under the call, and so are the warnings it shows; where it does not indent it (a console that cannot redraw a line, or gptr.verbose below 2), R prints the output itself, a registered secret included, on your screen only. gptr never reads the credential files of other tools. Reading a registered secret from model code asks even in auto mode: Sys.getenv() of its name in any letter case, or of a variable the code only ever sets to strings one of which is its name; $NAME or ${NAME} in a command line (system(), processx::run(), peter$sh() and the others above) and os.environ or getenv() in Python; an environment dump (Sys.getenv(), ps::ps_environ()); and a read of a .env or .Renviron file (.env, .env.local or name.env), of a file named auth.json (gptr's credential store), of a discovery record of gptr_mcp_serve() (mcp-serve/serve-<pid>.json) or of a file gptr_env() loaded, by a function that reads its text such as readLines(), or in a command line or Python. So does handing one to a child process through the env of peter$sh() or peter$script(), by its name or in a value, unless the same code reads that secret by name: the question for that read, or an r(secret:NAME) rule allowing it, covers the hand-over too. A name the code computes when it runs (with paste0(), through get() or do.call(), as a function's argument, or in a variable it sets otherwise or only to strings naming no secret) is read at level 3, which auto runs without asking. Such a file read through lapply() or another function that calls the reader (lapply(".env", readLines)), or read from a copy (file.copy(".env", "k.txt"), then readLines("k.txt")), is not read as a secret read either. Sending a secret over the network asks in every mode, yolo included: code that reads a secret, here or in an earlier call, or hands one to a child through env, and calls an R network function such as download.file() or httr2::req_perform(), or holds a string naming a network program such as curl, wget or ssh and starts a process with system(), system2(), processx::run(), peter$sh(), peter$bg() or peter$script(); a program name the code builds from pieces is not read. A key registered after it already appeared in a file (for example pasted into a prompt) can be removed from the files with gptr_scrub(); run gptr_scrub(error = TRUE) before committing to fail when any registered secret remains.

Data at rest and protected health information (PHI)

gptr keeps what it needs to resume and replay work. Review what you commit when the data are personal or clinical:

  • .gptr/sessions/ (full conversations, including printed results) is excluded from git by the .gptr/.gitignore that gptr_init() writes.

  • .gptr/cache/s1/ holds System 1 answers and is committed by default so that a script replays without model calls. It stores a salted hash of each input and a hash of each question, never their text, but the answers themselves (a label and its probability) remain, and the salt is committed with the cache, so anyone with the repository can test guesses of short inputs. For PHI, stop committing it with gptr_config(cache_commit = list(s1 = FALSE, s2 = FALSE), .scope = "project") (gptr then keeps a .gitignore in cache/s1/), or clear it with gptr_cache("clear", "s1") before committing.

  • .gptr/cache/s2/ (answer text for replay), .gptr/transcripts/ (console transcripts), .gptr/checkpoints/ (pre-images of objects and files) and the data snapshots of artifacts (.gptr/artifacts/<id>/v<n>/data/) are excluded from git by default. The checkpoints never hold a copy of a protected file or one that configures R or gptr (.env, .Renviron, keys under .ssh/). Object images, kept by reference in memory or spilled to the checkpoints as files, hold workspace objects' values with nothing redacted (gptr_rewind() says which are kept).

  • .gptr/plans/ (plans proposed in plan mode) and the app.R of each artifact are committed by default; they can quote data values the model saw.

  • Documents you record into keep the model's code and up to gptr.doc_output_lines lines of printed output per step, which can contain data values. A console turn's block also keeps, as #< lines, what its prompt was sent with, whatever that option says: the head of each @file (up to 40 lines) and the ! code notes with their printed output. Review them before sharing.

  • The block of a recorded gptr_coach() call keeps the coaching it chose (its note, skills, review and rules), which coaches write from your runs and which can quote data values they saw.

Local servers

gptr_mcp_serve() exposes the live session to other agents over HTTP on 127.0.0.1 only, with a random bearer token and an Origin check, and every call passes the permission gate. Any local process that learns the token can call the served tools while the server runs; stop it with gptr_mcp_serve(stop = TRUE) when you are done. With advertise = TRUE the token is also written to a discovery record that only you can read (on Unix), so that local clients find the session; any program running as you can read it while the server runs.