trading_agent.tools.bash_session
¶
One long-lived bash process inside the sandbox, like a terminal that stays open.
The folder and variables a command sets carry over to the next command. Each command runs with its input from /dev/null, so a command that waits for typing cannot swallow what comes after it. After each command a marker line with the exit status is printed, which is how the end of its output is found. A command that runs too long has its whole session restarted.
Typical usage example:
session = BashSession(sandbox, timeout_seconds=120, maximum_output_characters=20000) outcome = await session.run('ls -la') await session.close()
CommandOutcome
dataclass
¶
What one command produced.
Attributes:
| Name | Type | Description |
|---|---|---|
output |
str
|
Its combined standard output and error, cut to the maximum length. |
exit_status |
int | None
|
Its exit status, or None when it was stopped for running too long. |
truncated |
bool
|
Whether output was left out because it was too long. |
BashSession
¶
A persistent bash process in the sandbox.
Creates the session without starting bash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sandbox
|
BashSandbox
|
The sandbox to run in. |
required |
timeout_seconds
|
float
|
How long one command may run. |
required |
maximum_output_characters
|
int
|
How much output to keep from one command. |
required |
Source code in src/trading_agent/tools/bash_session.py
run
async
¶
Runs one command and waits for it to finish.
Commands from parallel tool calls run one after another, never at the same time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The command, as typed at a bash prompt. |
required |
Returns:
| Type | Description |
|---|---|
CommandOutcome
|
Its output and exit status. |
Source code in src/trading_agent/tools/bash_session.py
run_in_background
async
¶
Starts a long command that keeps running after this call returns.
Its output goes to a log file in the scratch folder. Background commands stop when the session restarts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The command. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The job's identifier, for check_background. |
Source code in src/trading_agent/tools/bash_session.py
check_background
async
¶
Reports whether a background job is still running, and the end of its log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The identifier from run_in_background. |
required |
Returns:
| Type | Description |
|---|---|
CommandOutcome
|
"running" or "finished", then the last 4,000 characters of its log. |