Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
refactor: update TERMINAL_TOOL_TIMEOUT to 1200 seconds with detailed documentation
Dmitry Ng78e46bd77ac8
diff --git a/.env.example b/.env.exampleindex cb7033a1..46a0a564 100644--- a/.env.example+++ b/.env.example@@ -117,8 +117,8 @@ EXTERNAL_SSL_INSECURE=## Default: 600 (10 minutes). Set to 0 to use the default.HTTP_CLIENT_TIMEOUT=-## Default terminal tool timeout in seconds when a command uses timeout=0-## Default: 600 (10 minutes). Set to 0 to disable the server-side default timeout.+## Default terminal tool timeout in seconds applied when an agent requests timeout=0 or a negative value.+## Default: 1200 (20 minutes). Range: 1–10800 (up to 3 hours). Values <= 0 or above 10800 are clamped to 10800 (agents always get a finite timeout).TERMINAL_TOOL_TIMEOUT=## Scraper URLs and settingsdiff --git a/README.md b/README.mdindex 0515cbbb..47fe454e 100644--- a/README.md+++ b/README.md@@ -2900,7 +2900,7 @@ EMBEDDING_STRIP_NEW_LINES=true # Whether to remove new lines from text before e# Advanced settingsPROXY_URL= # Optional proxy for all API callsHTTP_CLIENT_TIMEOUT=600 # Timeout in seconds for external API calls (default: 600, 0 = no timeout)-TERMINAL_TOOL_TIMEOUT=600 # Default timeout in seconds for terminal tool commands when timeout=0 (0 = no default timeout)+TERMINAL_TOOL_TIMEOUT=1200 # Default timeout in seconds for terminal tool commands when timeout=0 or negative (range: 1–10800; values <= 0 or above 10800 are clamped to 10800 = 3 hours)# SSL/TLS Certificate Configuration (for external communication with LLM backends and tool servers)EXTERNAL_SSL_CA_PATH= # Path to custom CA certificate file (PEM format) inside the containerdiff --git a/backend/cmd/ftester/mocks/tools.go b/backend/cmd/ftester/mocks/tools.goindex dbd46229..c4bf63b7 100644--- a/backend/cmd/ftester/mocks/tools.go+++ b/backend/cmd/ftester/mocks/tools.go@@ -369,7 +369,7 @@ func MockResponse(funcName string, args json.RawMessage) (string, error) {builder.WriteString(fmt.Sprintf("# Subtask ID %d\n\n", searchMemoryArgs.SubtaskID.Int64()))}builder.WriteString("# Tool Name 'terminal'\n\n")- builder.WriteString("# Tool Description\n\nCalls a terminal command in blocking mode. Use timeout=0 to apply the server default from TERMINAL_TOOL_TIMEOUT (default 600 seconds), or provide an explicit timeout up to 1200 seconds\n\n")+ builder.WriteString("# Tool Description\n\nCalls a terminal command in blocking mode. Use timeout=0 or a negative value to apply the configured server default timeout. Explicit positive values are accepted up to 10800 seconds (3 hours); values outside this range are replaced by the server default\n\n")builder.WriteString("# Chunk\n\n")builder.WriteString(fmt.Sprintf("This is a memory chunk related to your questions '%s'. It contains information about previous commands, outputs, and relevant context that was stored in the vector database.\n\n", questionsText))builder.WriteString("---------------------------\n")diff --git a/backend/cmd/installer/wizard/locale/locale.go b/backend/cmd/installer/wizard/locale/locale.goindex 9f728998..2a5d0501 100644--- a/backend/cmd/installer/wizard/locale/locale.go+++ b/backend/cmd/installer/wizard/locale/locale.go@@ -1202,7 +1202,7 @@ const (ServerSettingsHTTPClientTimeout = "HTTP Client Timeout"ServerSettingsHTTPClientTimeoutDesc = "Timeout in seconds for external API calls (LLM providers, search engines, etc.)"ServerSettingsTerminalToolTimeout = "Terminal Tool Timeout"- ServerSettingsTerminalToolTimeoutDesc = "Default timeout in seconds for terminal tool commands when timeout=0"+ ServerSettingsTerminalToolTimeoutDesc = "Default timeout in seconds for terminal commands (0 or negative = use 3-hour maximum)"ServerSettingsExternalSSLCAPath = "Custom CA Certificate Path"ServerSettingsExternalSSLCAPathDesc = "Path inside container to custom root CA cert (e.g., /opt/pentagi/ssl/ca-bundle.pem)"@@ -1273,13 +1273,14 @@ Default: 600 seconds (10 minutes)Setting to 0 disables timeout (not recommended in production)Too low values may cause legitimate long-running requests to fail.`- ServerSettingsTerminalToolTimeoutHelp = `Default timeout in seconds for terminal tool commands when the tool call uses timeout=0.+ ServerSettingsTerminalToolTimeoutHelp = `Default timeout in seconds applied when an agent requests timeout=0 or a negative timeout value.This affects commands executed through the isolated terminal container, including scanners and CLI-based utilities.-Default: 600 seconds (10 minutes)-Setting to 0 disables the server-side default timeout-Explicit timeout values provided by the tool call still take precedence when they are within the normal range.`+Default: 1200 seconds (20 minutes)+Allowed range: 1–10800 seconds (up to 3 hours)+Values <= 0 or above 10800 are clamped to the maximum (10800 s = 3 hours); agents are never allowed to run indefinitely.+Explicit timeout values provided by the tool call override this default when they are within the 1–10800 s range.`ServerSettingsExternalSSLCAPathHelp = `Path to custom CA certificate file (PEM format) inside the container.diff --git a/backend/docs/config.md b/backend/docs/config.mdindex 4b474ff6..be5f5135 100644--- a/backend/docs/config.md+++ b/backend/docs/config.md@@ -209,7 +209,7 @@ These settings control how PentAGI interacts with Docker, which is used for term| DockerWorkDir | `DOCKER_WORK_DIR` | *(none)* | Custom working directory inside Docker containers || DockerDefaultImage | `DOCKER_DEFAULT_IMAGE` | `debian:latest` | Default Docker image for containers when specific images fail || DockerDefaultImageForPentest | `DOCKER_DEFAULT_IMAGE_FOR_PENTEST` | `vxcontrol/kali-linux` | Default Docker image for penetration testing tasks |-| TerminalToolTimeout | `TERMINAL_TOOL_TIMEOUT` | `600` | Default timeout in seconds for terminal tool commands when timeout is set to `0` (0 = no default timeout) |+| TerminalToolTimeout | `TERMINAL_TOOL_TIMEOUT` | `1200` | Default execution timeout in seconds applied when an agent requests `timeout=0` or a negative value. Accepted range: `1`–`10800` (3 hours). Values `<= 0` or above `10800` are clamped to the 3-hour maximum. Negative values are treated identically to `0`. |### Usage Details@@ -228,7 +228,7 @@ The Docker settings are primarily used in `pkg/docker/client.go` which implement}```-- **TerminalToolTimeout**: Sets the default execution timeout for terminal tool commands when the tool call uses `timeout=0`:+- **TerminalToolTimeout**: Sets the default execution timeout for terminal tool commands when the tool call uses `timeout=0` or a negative value:```goterm := NewTerminalTool(flowID,@@ -242,7 +242,7 @@ The Docker settings are primarily used in `pkg/docker/client.go` which implement)```- Use `0` to disable the server-side default timeout. Explicit timeout values provided by the tool call still take precedence when they are within the normal range.+ The value is clamped inside the terminal tool: values `<= 0` or above `10800` s (3 hours) are silently raised/capped to the 3-hour maximum — agents always receive a finite timeout. Negative values are accepted at the environment level and treated identically to `0` (both resolve to the 3-hour ceiling). Explicit `timeout` values provided by the tool call override this default when they are within the `1`–`10800` s range.- **DockerNetwork**: Controls the network isolation mode for containers. Supports two modes:diff --git a/backend/pkg/config/config.go b/backend/pkg/config/config.goindex b4d649c4..c40ba553 100644--- a/backend/pkg/config/config.go+++ b/backend/pkg/config/config.go@@ -35,7 +35,7 @@ type Config struct {DockerWorkDir string `env:"DOCKER_WORK_DIR"`DockerDefaultImage string `env:"DOCKER_DEFAULT_IMAGE" envDefault:"debian:latest"`DockerDefaultImageForPentest string `env:"DOCKER_DEFAULT_IMAGE_FOR_PENTEST" envDefault:"vxcontrol/kali-linux"`- TerminalToolTimeout int `env:"TERMINAL_TOOL_TIMEOUT" envDefault:"600"`+ TerminalToolTimeout int `env:"TERMINAL_TOOL_TIMEOUT" envDefault:"1200"`// === API Server Configuration ===ServerPort int `env:"SERVER_PORT" envDefault:"8080"`diff --git a/backend/pkg/config/config_test.go b/backend/pkg/config/config_test.goindex 9927a599..68926522 100644--- a/backend/pkg/config/config_test.go+++ b/backend/pkg/config/config_test.go@@ -555,7 +555,7 @@ func TestNewConfig_TerminalToolTimeout(t *testing.T) {t.Run("default timeout", func(t *testing.T) {config, err := NewConfig()require.NoError(t, err)- assert.Equal(t, 600, config.TerminalToolTimeout)+ assert.Equal(t, 1200, config.TerminalToolTimeout)})t.Run("custom timeout", func(t *testing.T) {diff --git a/backend/pkg/tools/args.go b/backend/pkg/tools/args.goindex 62334c13..a04ad05d 100644--- a/backend/pkg/tools/args.go+++ b/backend/pkg/tools/args.go@@ -94,7 +94,7 @@ type TerminalAction struct {Input string `json:"input" jsonschema:"required" jsonschema_description:"Command to be run in the docker container terminal according to rules to execute commands"`Cwd string `json:"cwd" jsonschema:"required" jsonschema_description:"Custom current working directory to execute commands in or default directory otherwise if it's not specified"`Detach Bool `json:"detach" jsonschema:"required,type=boolean" jsonschema_description:"Set to true for INTERACTIVE or LONG-RUNNING commands: shells (msfconsole, bash, python), listeners (nc -lvnp, socat TCP-LISTEN), servers (python -m http.server, php -S), monitors (tcpdump, tail -f). These commands expect user input or run indefinitely. When true: command runs in background, you get immediate confirmation, no stdout/stderr captured. When false: command must complete within timeout and return output. For quick batch commands (nmap, curl, ls) use false"`- Timeout Int64 `json:"timeout" jsonschema:"required,type=integer" jsonschema_description:"Execution time limit in seconds. Use 0 to apply the server default from TERMINAL_TOOL_TIMEOUT (default 600, 0 = no timeout). Explicit values should normally stay within 10-1200 seconds. For batch commands that may run long, use the 'timeout' shell utility INSIDE your command to ensure clean completion with full output: 'timeout 55 nmap -sV target' (set 5-10 seconds less than this parameter). For interactive/long-running commands, use detach=true instead of relying solely on timeout"`+ Timeout Int64 `json:"timeout" jsonschema:"required,type=integer" jsonschema_description:"Execution time limit in seconds. Use 0 value to apply the configured server default timeout. Explicit positive values are accepted up to 10800 seconds (3 hours); any value outside the 1–10800 range or non-positive is replaced by the server default. For batch commands that may run long, use the 'timeout' shell utility INSIDE your command to ensure clean completion with full output: 'timeout 55 nmap -sV target' (set 5-10 seconds less than this parameter). For interactive/long-running commands, use detach=true instead of relying solely on timeout"`Message string `json:"message" jsonschema:"required,title=Terminal command message" jsonschema_description:"Not so long message which explain what do you want to achieve and to execute in terminal to send to the user in user's language only"`}diff --git a/backend/pkg/tools/registry.go b/backend/pkg/tools/registry.goindex a7efa287..6e1ef657 100644--- a/backend/pkg/tools/registry.go+++ b/backend/pkg/tools/registry.go@@ -156,8 +156,9 @@ var allowedStoringInMemoryTools = []string{var registryDefinitions = map[string]llms.FunctionDefinition{TerminalToolName: {Name: TerminalToolName,- Description: "Calls a terminal command in blocking mode. Use timeout=0 to apply the server default " +- "from TERMINAL_TOOL_TIMEOUT (default 600 seconds), or provide an explicit timeout up to 1200 seconds. " ++ Description: "Calls a terminal command in blocking mode. " ++ "Use timeout=0 or a negative value to apply the configured server default timeout. " ++ "Explicit positive values are accepted up to 10800 seconds (3 hours); values outside this range are replaced by the server default. " +"Only one command can be executed at a time",Parameters: reflector.Reflect(&TerminalAction{}),},diff --git a/backend/pkg/tools/terminal.go b/backend/pkg/tools/terminal.goindex 8ad99519..c287c8d1 100644--- a/backend/pkg/tools/terminal.go+++ b/backend/pkg/tools/terminal.go@@ -22,9 +22,8 @@ import ()const (- maxExplicitExecCommandTimeout = 20 * time.Minute+ maxExplicitExecCommandTimeout = 3 * time.HourdefaultExtraExecTimeout = 5 * time.Second- maxRuntimeExecCommandTimeout = maxExplicitExecCommandTimeout + defaultExtraExecTimeoutdefaultQuickCheckTimeout = 500 * time.Millisecond// ANSI terminal color codes (aligned with PentAGI UI palette)@@ -71,21 +70,21 @@ func NewTerminalTool(}func (t *terminal) configuredExecTimeout() time.Duration {- if t.defaultExecTimeout < 0 {- return 0+ if t.defaultExecTimeout <= 0 || t.defaultExecTimeout > maxExplicitExecCommandTimeout {+ // Zero, negative, or above the operator ceiling: cap to the maximum allowed value.+ // Agents must never execute commands without a time bound.+ return maxExplicitExecCommandTimeout}return t.defaultExecTimeout}func (t *terminal) normalizeExecTimeout(timeout time.Duration) time.Duration {- switch {- case timeout > 0 && timeout <= maxRuntimeExecCommandTimeout:+ switch defaultExecTimeout := t.configuredExecTimeout() + defaultExtraExecTimeout; {+ case timeout > 0 && timeout <= defaultExecTimeout:return timeout- case timeout > maxRuntimeExecCommandTimeout:- return maxRuntimeExecCommandTimeoutdefault:- return t.configuredExecTimeout()+ return defaultExecTimeout}}diff --git a/backend/pkg/tools/terminal_test.go b/backend/pkg/tools/terminal_test.goindex de18809f..f4ed086b 100644--- a/backend/pkg/tools/terminal_test.go+++ b/backend/pkg/tools/terminal_test.go@@ -209,44 +209,170 @@ func TestPrimaryTerminalName(t *testing.T) {}}+func TestConfiguredExecTimeout(t *testing.T) {+ t.Parallel()++ tests := []struct {+ name string+ configured time.Duration+ want time.Duration+ }{+ {+ name: "typical value is returned as-is",+ configured: 600 * time.Second,+ want: 600 * time.Second,+ },+ {+ name: "new default (1200 s) is returned as-is",+ configured: 1200 * time.Second,+ want: 1200 * time.Second,+ },+ {+ name: "exactly at the 3-hour ceiling is returned as-is",+ configured: maxExplicitExecCommandTimeout,+ want: maxExplicitExecCommandTimeout,+ },+ {+ name: "zero is capped to the 3-hour ceiling",+ configured: 0,+ want: maxExplicitExecCommandTimeout,+ },+ {+ name: "negative one second is capped to the 3-hour ceiling",+ configured: -1 * time.Second,+ want: maxExplicitExecCommandTimeout,+ },+ {+ name: "large negative is capped to the 3-hour ceiling",+ configured: -9999 * time.Second,+ want: maxExplicitExecCommandTimeout,+ },+ {+ name: "one second above the ceiling is capped",+ configured: maxExplicitExecCommandTimeout + time.Second,+ want: maxExplicitExecCommandTimeout,+ },+ {+ name: "very large value (> 3 h) is capped to the 3-hour ceiling",+ configured: 100000 * time.Second,+ want: maxExplicitExecCommandTimeout,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ t.Parallel()++ term := &terminal{defaultExecTimeout: tt.configured}+ assert.Equal(t, tt.want, term.configuredExecTimeout())+ })+ }+}+func TestNormalizeExecTimeout(t *testing.T) {t.Parallel()+ // ceilFor computes the effective runtime ceiling for a given configured value:+ // it equals configuredExecTimeout() + defaultExtraExecTimeout.+ ceilFor := func(configured time.Duration) time.Duration {+ term := &terminal{defaultExecTimeout: configured}+ return term.configuredExecTimeout() + defaultExtraExecTimeout+ }+tests := []struct {name stringconfigured time.Durationrequested time.Durationwant time.Duration}{+ // --- Explicit positive values: preserved when within the operator ceiling ---{- name: "explicit timeout is preserved",+ name: "typical explicit value is preserved",configured: 10 * time.Minute,requested: 45 * time.Second,want: 45 * time.Second,},{- name: "zero requested timeout uses configured default",+ name: "explicit value exactly at the ceiling is preserved",configured: 10 * time.Minute,- requested: 0,- want: 10 * time.Minute,+ requested: ceilFor(10 * time.Minute), // 600s + 5s = 605s+ want: ceilFor(10 * time.Minute),+ },+ {+ name: "explicit value one second above the ceiling falls back to ceiling",+ configured: 10 * time.Minute,+ requested: ceilFor(10*time.Minute) + time.Second,+ want: ceilFor(10 * time.Minute),+ },+ {+ name: "explicit value at the default configured (1200 s) is preserved",+ configured: 1200 * time.Second,+ requested: 1200 * time.Second,+ want: 1200 * time.Second,+ },+ {+ name: "explicit value above the 1200-s ceiling falls back to that ceiling",+ configured: 1200 * time.Second,+ requested: ceilFor(1200*time.Second) + time.Second, // 1205s + 1s → fallback+ want: ceilFor(1200 * time.Second), // 1205s+ },+ {+ name: "explicit value at the 3-hour ceiling is preserved when configured=0",+ configured: 0,+ requested: ceilFor(0), // 3h + 5s+ want: ceilFor(0),+ },+ {+ name: "explicit value above the 3-hour ceiling falls back to 3-hour ceiling",+ configured: 0,+ requested: ceilFor(0) + time.Second,+ want: ceilFor(0),},++ // --- Zero requested: falls back to the operator ceiling ---{- name: "too large explicit timeout clamps to max runtime timeout",+ name: "zero requested with typical configured falls back to ceiling",configured: 10 * time.Minute,- requested: maxRuntimeExecCommandTimeout + time.Second,- want: maxRuntimeExecCommandTimeout,+ requested: 0,+ want: ceilFor(10 * time.Minute), // 605s},{- name: "configured zero keeps timeout disabled",+ name: "zero requested with default configured (1200 s) falls back to ceiling",+ configured: 1200 * time.Second,+ requested: 0,+ want: ceilFor(1200 * time.Second), // 1205s+ },+ {+ name: "zero requested with configured=0 falls back to 3-hour ceiling",configured: 0,requested: 0,- want: 0,+ want: ceilFor(0), // 3h + 5s+ },+ {+ name: "zero requested with oversized configured (> 3 h) falls back to 3-hour ceiling",+ configured: 100000 * time.Second,+ requested: 0,+ want: ceilFor(0), // capped to 3h + 5s+ },++ // --- Negative requested: treated identically to zero ---+ {+ name: "negative requested falls back to configured ceiling",+ configured: 10 * time.Minute,+ requested: -5 * time.Second,+ want: ceilFor(10 * time.Minute),},{- name: "configured zero does not disable oversized explicit timeout limit",+ name: "negative requested with configured=0 falls back to 3-hour ceiling",configured: 0,- requested: maxRuntimeExecCommandTimeout + time.Second,- want: maxRuntimeExecCommandTimeout,+ requested: -1 * time.Second,+ want: ceilFor(0),+ },+ {+ name: "negative requested with negative configured falls back to 3-hour ceiling",+ configured: -5 * time.Second,+ requested: -1 * time.Second,+ want: ceilFor(0), // both negative → absolute 3-hour max},}