_to_plain
TerminalToolkit
- timeout (Optional[float]): The default timeout in seconds for blocking commands. Defaults to 20.0.
- working_directory (Optional[str]): The base directory for operations. For the local backend, this acts as a security sandbox. For the Docker backend, this sets the working directory inside the container. If not specified, defaults to ”./workspace” for local and “/workspace” for Docker.
- use_docker_backend (bool): If True, all commands are executed in a Docker container. Defaults to False.
- docker_container_name (Optional[str]): The name of the Docker container to use. Required if use_docker_backend is True.
- session_logs_dir (Optional[str]): The directory to store session logs. Defaults to a ‘terminal_logs’ subfolder in the working directory.
- safe_mode (bool): Whether to apply security checks to commands. Defaults to True.
- allowed_commands (Optional[List[str]]): List of allowed commands when safe_mode is True. If None, uses default safety rules.
- clone_current_env (bool): Whether to clone the current Python environment for local execution. Defaults to False.
init
_setup_cloned_environment
_setup_initial_environment
_adapt_command_for_environment
_write_to_log
- log_file (str): Path to the log file
- content (str): Content to write
_sanitize_command
_start_output_reader_thread
_collect_output_until_idle
- id (str): The session ID.
- idle_duration (float): How long the stream must be empty to be considered idle.(default: 0.5)
- check_interval (float): The time to sleep between checks. (default: 0.1)
- max_wait (float): The maximum total time to wait for the process to go idle. (default: 5.0)
shell_exec
- id (str): A unique identifier for the command’s session. This ID is used to interact with non-blocking processes.
- command (str): The shell command to execute.
- block (bool, optional): Determines the execution mode. Defaults to True. If
True(blocking mode), the function waits for the command to complete and returns the full output. Use this for most commands . IfFalse(non-blocking mode), the function starts the command in the background. Use this only for interactive sessions or long-running tasks, or servers.
id. To interact with the background process, use
other functions: shell_view(id) to see output,
shell_write_to_process(id, "input") to send input, and
shell_kill_process(id) to terminate.
shell_write_to_process
- id (str): The unique session ID of the non-blocking process.
- command (str): The text to write to the process’s standard input.
shell_view
- id (str): The unique session ID of the non-blocking process.
shell_kill_process
- id (str): The unique session ID of the process to kill.
shell_ask_user_for_help
- If session exists: Shows session output and allows interaction
- If session doesn’t exist: Creates a temporary session for help
- id (str): The session ID of the interactive process needing help. Can be empty string for general help without session context.
- prompt (str): The question or instruction from the LLM to show the human user (e.g., “The program is asking for a filename. Please enter ‘config.json’.”).