class RubyLLM::CodeExecution

CodeExecution is the run_code tool Chat#with_code_execution gives the model. Each call runs Ruby, Python, JavaScript, or a shell script in a Sandbox, in a fresh run directory with read-only copies of the conversation’s files, and returns the exit code, the output, and every file the code wrote there as an attachment on the tool result. In a chat with a file store (see Chat#with_file_store), runs work with the chat’s files instead. With FileStore::Directory, code runs in the store’s folder and changes the files in place. With any other store, each run has read-only copies of the conversation’s files as usual, copies in the files the model names in files, and what the code writes is saved back to the store.

Calls run in the chat’s default sandbox. With escalate_to:, the model may name a wider sandbox for one call and say why; that call waits for Chat#approve, and the next call is back in the default.

chat = RubyLLM.chat.with_code_execution(escalate_to: [WorkspaceSandbox])
chat.tools[:run_code].escalations # => ["workspace"]