Parses the code string to catch syntax errors and optionally checks for potentially dangerous function calls. This is intended as a fast pre-check so that obviously broken code never reaches the child process.
Value
A list with components:
- valid
Logical.
TRUEif the code parses without error.- error
NULLon success, or a character string describing the parse error.- warnings
Character vector of advisory warnings about potentially dangerous patterns (e.g.
system(),.Internal()). Empty if none detected. These are advisory only — the sandbox handles actual restriction.
Details
Note: Pattern-based validation is ADVISORY ONLY. It uses simple regex matching and can produce both false positives and false negatives. The OS-level sandbox (Seatbelt / bwrap) is the actual enforcement layer that restricts filesystem, network, and process access. Do not rely on validation alone to prevent dangerous operations.
Examples
# Valid code
result <- validate_code("1 + 1")
result$valid
#> [1] TRUE
# TRUE
# Syntax error
result <- validate_code("if (TRUE {")
result$valid
#> [1] FALSE
# FALSE
result$error
#> [1] "<text>:1:10: unexpected '{'\n1: if (TRUE {\n ^"
# Dangerous pattern warning
result <- validate_code("system('ls')")
result$warnings
#> [1] "Code contains call to `system()` which may be restricted by the sandbox"