R6 class that manages an isolated R environment for executing LLM-generated R code. Tools are bound as callable functions within this environment, enabling the LLM to batch-invoke and process data locally.
new()Initialize a new SandboxManager.
SandboxManager$new(
tools = list(),
preload_packages = c("dplyr", "purrr"),
max_output_chars = 8000,
parent_env = NULL
)toolsOptional list of Tool objects to bind into the sandbox.
preload_packagesCharacter vector of package names to preload into the sandbox (their exports become available). Default: c("dplyr", "purrr").
max_output_charsMaximum characters to capture from code output.
Prevents runaway print() from flooding the context. Default: 8000.
parent_envOptional parent environment for the sandbox.
When a ChatSession is available, pass session$get_envir() here
to enable cross-step variable persistence.
bind_tools()Bind Tool objects into the sandbox as callable R functions.
SandboxManager$bind_tools(tools)toolsA list of Tool objects to bind.
Invisible self (for chaining).
execute()Execute R code in the sandbox environment.
SandboxManager$execute(code_str)code_strA character string containing R code to execute.
A character string with captured stdout, or an error message.
get_tool_signatures()Get human-readable signatures for all bound tools.
SandboxManager$get_tool_signatures()A character string with Markdown-formatted tool documentation.
get_env()Get the sandbox environment.
SandboxManager$get_env()The R environment used by the sandbox.
list_tools()Get list of bound tool names.
SandboxManager$list_tools()Character vector of tool names available in the sandbox.
reset()Reset the sandbox environment (clear all user variables). Tool bindings and preloaded packages are preserved.
SandboxManager$reset()
clone()The objects of this class are cloneable with this method.
SandboxManager$clone(deep = FALSE)deepWhether to make a deep clone.