
Execute an External Verification or Audit Script Inside the Isolated Sandbox
Source:R/handoff.R
verify_with_script.RdRuns an arbitrary external or project-local R audit/verification script (for
example, a custom statistical consistency check, a statci CI audit, or a
peer-reviewer validation script) inside rcapsule's clean, path-confined,
ambient-secret-scrubbed sandbox via callr::rscript(). Captures exit status,
duration, stdout/stderr, scrubbed environment variable names, SHA-256
hashes of every created or modified artifact, and optional checks on
expected output files.
Arguments
- script
Path to an existing
.Rscript to execute inside the sandbox (may reside outsidepath, e.g. a shared organizational audit script).- path
Path to the project root directory to stage cleanly into the sandbox. Defaults to
".".- manifest
Optional
rcapsule_manifestobject or path tocapsule.jsonused to exclude previously generated outputs when staging the sandbox.- seed
Optional integer RNG seed applied before sourcing
script.- rng_kind
Character vector of length 3 from
base::RNGkind(). Defaults to the current session'sRNGkind().- env_vars
Optional named list of explicit environment variables passed to the sandboxed script.
- timeout
Execution timeout in seconds (default
300).- scrub_secrets
Logical; if
TRUE(default), strips ambient credential and token environment variables (AWS_*,GITHUB_TOKEN,OPENAI_API_KEY,*_SECRET*,*_TOKEN*, etc.) before executingscript.- keep_sandbox
Logical; if
TRUE, retains the temporary sandbox directory on disk and returns its path insandbox_dir. Defaults toFALSE.- expected_outputs
Optional character vector of project-relative output paths expected to exist in the sandbox after
scriptfinishes.- args
Optional character vector of string arguments forwarded to
scriptvia theRCAPSULE_AUDIT_ARGSenvironment variable (JSON array).
Value
An S3 object of class rcapsule_script_audit containing passed,
status ("passed" or "failed"), exit_status, duration_sec,
script, script_sha256, project_path, verified_at, rng,
scrubbed_env_vars, stdout, stderr, artifacts (tibble of created or
modified files with path, change, sha256, bytes, format),
expected_checks (tibble checking expected_outputs), and sandbox_dir.
Examples
tmp <- tempfile("rcapsule_script_audit_")
dir.create(tmp)
write.csv(data.frame(x = 1:5), file.path(tmp, "data.csv"), row.names = FALSE)
audit_script <- tempfile("audit_", fileext = ".R")
writeLines(
c("df <- read.csv('data.csv')",
"stopifnot(nrow(df) == 5L)",
"writeLines('audit_ok', 'audit_report.txt')"),
audit_script
)
res <- verify_with_script(
script = audit_script,
path = tmp,
seed = 42L,
expected_outputs = "audit_report.txt"
)
res
#>
#> ── rcapsule Isolated Script Audit: PASSED ──────────────────────────────────────
#> • Script: audit_1a631de9517a.R (SHA-256: e292fbf19c2c...)
#> • Exit status: 0 | Duration: 0.195s | Scrubbed env vars: 41
#> • Created/modified artifacts: 1
#>
#> ── Expected Output Checks ──
#>
#> ✔ audit_report.txt (9 bytes)
unlink(c(tmp, audit_script), recursive = TRUE)