Creates a SecureSession, passes it to a user function, and guarantees
cleanup via on.exit().
This is useful when you need to run multiple executions on the same session
(e.g., building up state across calls) without worrying about leaked
processes.
Usage
with_secure_session(fn, tools = list(), sandbox = TRUE, ...)Arguments
- fn
A function that receives a SecureSession as its first argument.
- tools
List of
securer_tool()objects to register in the session.- sandbox
Logical, whether to enable OS-level sandboxing (default
TRUE).- ...
Additional arguments passed to SecureSession
$new().
Examples
# \donttest{
# Run multiple commands on the same session
result <- with_secure_session(function(session) {
session$execute("x <- 10")
session$execute("x * 2")
}, sandbox = FALSE)
# With tools
result <- with_secure_session(
fn = function(session) {
session$execute("add(2, 3)")
},
tools = list(
securer_tool("add", "Add two numbers",
fn = function(a, b) a + b,
args = list(a = "numeric", b = "numeric"))
),
sandbox = FALSE
)
# }