trading_agent.tools.bash_sandbox
¶
Builds the bwrap command line that runs the agent's bash terminal in a sandbox.
Inside the sandbox the whole filesystem is visible but read-only, except the desk's scratch folder and a private /tmp. Files that hold secrets are replaced by empty ones, the environment starts empty, and the sandbox has its own process list, so it cannot see or signal the gateway. The network is shared, so the agent can reach the internet; the local databases and UBI it can reach all require credentials that are hidden.
Typical usage example:
sandbox = BashSandbox(scratch_directory, hidden_paths) argument_list = sandbox.command(['bash', '--noprofile', '--norc'])
BashSandbox
¶
The sandbox for one desk's terminal.
Attributes:
| Name | Type | Description |
|---|---|---|
scratch_directory |
The only folder of the real filesystem the sandbox can write to. |
|
home_directory |
The sandbox's HOME, inside the scratch folder. |
Describes the sandbox without starting anything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scratch_directory
|
Path
|
The desk's scratch folder. |
required |
hidden_path_patterns
|
Sequence[str]
|
Files and folders to hide; "~" and "*" are expanded. |
required |
passed_variable_names
|
Sequence[str]
|
Environment variables the user chose to pass from the gateway into the sandbox, such as an API key a skill's script needs. |
()
|
Source code in src/trading_agent/tools/bash_sandbox.py
passed_environment
¶
The environment variables passed into the sandbox that are set in the gateway.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Each passed variable that has a value, with that value. |
Source code in src/trading_agent/tools/bash_sandbox.py
hidden_paths
¶
Expands the hidden path patterns into the paths that exist now.
Each path is resolved to where it really is, because a link such as /var/run pointing at /run would otherwise hide the same file twice, which bwrap refuses. A path inside a folder that is already hidden is left out, because the folder's empty replacement no longer contains it.
Returns:
| Type | Description |
|---|---|
list[Path]
|
Every existing file and folder to hide, outermost first. |
Source code in src/trading_agent/tools/bash_sandbox.py
command
¶
Builds the full command line that runs a program inside the sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program
|
Sequence[str]
|
The program and its arguments. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The bwrap command line. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
bwrap is not installed. |