computer: Computer Class

ComputerR Documentation

Computer Class

Description

R6 class providing computer abstraction with atomic tools for file operations, bash execution, and R code execution.

Public fields

working_dir

Current working directory

sandbox_mode

Sandbox mode: "strict", "permissive", or "none"

execution_log

Log of executed commands

Methods

Public methods


Method new()

Initialize computer abstraction

Usage
Computer$new(working_dir = tempdir(), sandbox_mode = "permissive")
Arguments
working_dir

Working directory. Defaults to tempdir().

sandbox_mode

Sandbox mode: "strict", "permissive", or "none"


Method bash()

Execute bash command

Usage
Computer$bash(command, timeout_ms = 30000, capture_output = TRUE)
Arguments
command

Bash command to execute

timeout_ms

Timeout in milliseconds (default: 30000)

capture_output

Whether to capture output (default: TRUE)

Returns

List with stdout, stderr, exit_code


Method read_file()

Read file contents

Usage
Computer$read_file(path, encoding = "UTF-8")
Arguments
path

File path (relative to working_dir or absolute)

encoding

File encoding (default: "UTF-8")

Returns

File contents as character string


Method write_file()

Write file contents

Usage
Computer$write_file(path, content, encoding = "UTF-8")
Arguments
path

File path (relative to working_dir or absolute)

content

Content to write

encoding

File encoding (default: "UTF-8")

Returns

Success status


Method edit_file()

Edit a file by replacing an exact text pattern.

Usage
Computer$edit_file(path, pattern, replacement, all = FALSE, encoding = "UTF-8")
Arguments
path

File path (relative to working_dir or absolute)

pattern

Exact text to replace

replacement

Replacement text

all

Whether to replace all occurrences. Default FALSE.

encoding

File encoding (default: "UTF-8")

Returns

Success status


Method execute_r_code()

Execute R code in an isolated callr process

Usage
Computer$execute_r_code(code, timeout_ms = 30000, capture_output = TRUE)
Arguments
code

R code to execute

timeout_ms

Timeout in milliseconds (default: 30000)

capture_output

Whether to capture output (default: TRUE)

Returns

List with result, output, error, and execution_mode. execution_mode is always "sandbox_exec" for this computer-layer path, which does not persist values into a live ChatSession$get_envir().


Method get_log()

Get execution log

Usage
Computer$get_log()
Returns

List of logged executions


Method clear_log()

Clear execution log Check bash command for sandbox violations Log execution Resolve path (relative to working_dir or absolute) Check write path for sandbox violations Check R code for sandbox violations

Usage
Computer$clear_log()

Method clone()

The objects of this class are cloneable with this method.

Usage
Computer$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


aisdk documentation built on May 29, 2026, 9:07 a.m.