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
feat: add configurable terminal tool timeout
Mason Kim(ZINUS US_SALES)86d7666c8681
diff --git a/.env.example b/.env.exampleindex 4d2795d6..cb7033a1 100644--- a/.env.example+++ b/.env.example@@ -117,6 +117,10 @@ 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.+TERMINAL_TOOL_TIMEOUT=+## Scraper URLs and settings## For Docker (default):SCRAPER_PUBLIC_URL=diff --git a/README.md b/README.mdindex 7ddc15ba..88e5829e 100644--- a/README.md+++ b/README.md@@ -2871,6 +2871,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)# 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 949d5e05..dbd46229 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 with hard limit timeout 1200 seconds and optimum timeout 60 seconds\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("# 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/ftester/worker/executor.go b/backend/cmd/ftester/worker/executor.goindex bbd8e997..70e99276 100644--- a/backend/cmd/ftester/worker/executor.go+++ b/backend/cmd/ftester/worker/executor.go@@ -4,6 +4,7 @@ import ("context""encoding/json""fmt"+ "time""pentagi/cmd/ftester/mocks""pentagi/pkg/config"@@ -135,6 +136,7 @@ func (te *toolExecutor) GetTool(ctx context.Context, funcName string) (tools.ToocontainerLID,te.dockerClient,te.proxies.GetTermLogProvider(),+ time.Duration(te.cfg.TerminalToolTimeout)*time.Second,), nilcase tools.FileToolName:@@ -147,6 +149,7 @@ func (te *toolExecutor) GetTool(ctx context.Context, funcName string) (tools.ToocontainerLID,te.dockerClient,te.proxies.GetTermLogProvider(),+ time.Duration(te.cfg.TerminalToolTimeout)*time.Second,), nilcase tools.BrowserToolName:diff --git a/backend/cmd/installer/wizard/controller/controller.go b/backend/cmd/installer/wizard/controller/controller.goindex 6e0fe4cf..3080a632 100644--- a/backend/cmd/installer/wizard/controller/controller.go+++ b/backend/cmd/installer/wizard/controller/controller.go@@ -1913,6 +1913,7 @@ type ServerSettingsConfig struct {CookieSigningSalt loader.EnvVar // COOKIE_SIGNING_SALTProxyURL loader.EnvVar // PROXY_URLHTTPClientTimeout loader.EnvVar // HTTP_CLIENT_TIMEOUT+ TerminalToolTimeout loader.EnvVar // TERMINAL_TOOL_TIMEOUTExternalSSLCAPath loader.EnvVar // EXTERNAL_SSL_CA_PATHExternalSSLInsecure loader.EnvVar // EXTERNAL_SSL_INSECURESSLDir loader.EnvVar // PENTAGI_SSL_DIR@@ -1934,6 +1935,7 @@ func (c *controller) GetServerSettingsConfig() *ServerSettingsConfig {"COOKIE_SIGNING_SALT","PROXY_URL","HTTP_CLIENT_TIMEOUT",+ "TERMINAL_TOOL_TIMEOUT","EXTERNAL_SSL_CA_PATH","EXTERNAL_SSL_INSECURE","PENTAGI_SSL_DIR",@@ -1949,6 +1951,7 @@ func (c *controller) GetServerSettingsConfig() *ServerSettingsConfig {"PENTAGI_DATA_DIR": "pentagi-data","PENTAGI_SSL_DIR": "pentagi-ssl","HTTP_CLIENT_TIMEOUT": "600",+ "TERMINAL_TOOL_TIMEOUT": "600","EXTERNAL_SSL_INSECURE": "false",}@@ -1968,6 +1971,7 @@ func (c *controller) GetServerSettingsConfig() *ServerSettingsConfig {CookieSigningSalt: vars["COOKIE_SIGNING_SALT"],ProxyURL: vars["PROXY_URL"],HTTPClientTimeout: vars["HTTP_CLIENT_TIMEOUT"],+ TerminalToolTimeout: vars["TERMINAL_TOOL_TIMEOUT"],ExternalSSLCAPath: vars["EXTERNAL_SSL_CA_PATH"],ExternalSSLInsecure: vars["EXTERNAL_SSL_INSECURE"],SSLDir: vars["PENTAGI_SSL_DIR"],@@ -2007,6 +2011,7 @@ func (c *controller) UpdateServerSettingsConfig(config *ServerSettingsConfig) er"COOKIE_SIGNING_SALT": config.CookieSigningSalt.Value,"PROXY_URL": proxyURL,"HTTP_CLIENT_TIMEOUT": config.HTTPClientTimeout.Value,+ "TERMINAL_TOOL_TIMEOUT": config.TerminalToolTimeout.Value,"EXTERNAL_SSL_CA_PATH": config.ExternalSSLCAPath.Value,"EXTERNAL_SSL_INSECURE": config.ExternalSSLInsecure.Value,"PENTAGI_SSL_DIR": config.SSLDir.Value,@@ -2031,6 +2036,7 @@ func (c *controller) ResetServerSettingsConfig() *ServerSettingsConfig {"COOKIE_SIGNING_SALT","PROXY_URL","HTTP_CLIENT_TIMEOUT",+ "TERMINAL_TOOL_TIMEOUT","EXTERNAL_SSL_CA_PATH","EXTERNAL_SSL_INSECURE","PENTAGI_SSL_DIR",diff --git a/backend/cmd/installer/wizard/locale/locale.go b/backend/cmd/installer/wizard/locale/locale.goindex b7c7f360..9f728998 100644--- a/backend/cmd/installer/wizard/locale/locale.go+++ b/backend/cmd/installer/wizard/locale/locale.go@@ -1199,8 +1199,10 @@ const (ServerSettingsProxyPassword = "Proxy Password"ServerSettingsProxyPasswordDesc = "Password for proxy authentication (optional)"- ServerSettingsHTTPClientTimeout = "HTTP Client Timeout"- ServerSettingsHTTPClientTimeoutDesc = "Timeout in seconds for external API calls (LLM providers, search engines, etc.)"+ 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"ServerSettingsExternalSSLCAPath = "Custom CA Certificate Path"ServerSettingsExternalSSLCAPathDesc = "Path inside container to custom root CA cert (e.g., /opt/pentagi/ssl/ca-bundle.pem)"@@ -1227,6 +1229,7 @@ const (ServerSettingsProxyUsernameHint = "Proxy Username"ServerSettingsProxyPasswordHint = "Proxy Password"ServerSettingsHTTPClientTimeoutHint = "HTTP Timeout"+ ServerSettingsTerminalToolTimeoutHint = "Terminal Timeout"ServerSettingsExternalSSLCAPathHint = "Custom CA Path"ServerSettingsExternalSSLInsecureHint = "Skip SSL Verification"ServerSettingsSSLDirHint = "SSL Directory"@@ -1270,6 +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.++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.`+ServerSettingsExternalSSLCAPathHelp = `Path to custom CA certificate file (PEM format) inside the container.Must point to /opt/pentagi/ssl/ directory, which is mounted from pentagi-ssl volume on the host.@@ -2277,6 +2288,7 @@ const (EnvDesc_COOKIE_SIGNING_SALT = "PentAGI Cookie Signing Salt"EnvDesc_PROXY_URL = "HTTP/HTTPS Proxy URL"EnvDesc_HTTP_CLIENT_TIMEOUT = "HTTP Client Timeout (seconds)"+ EnvDesc_TERMINAL_TOOL_TIMEOUT = "Terminal Tool Timeout (seconds)"EnvDesc_EXTERNAL_SSL_CA_PATH = "Custom CA Certificate Path"EnvDesc_EXTERNAL_SSL_INSECURE = "Skip SSL Verification"EnvDesc_PENTAGI_SSL_DIR = "PentAGI SSL Directory"diff --git a/backend/cmd/installer/wizard/models/server_settings_form.go b/backend/cmd/installer/wizard/models/server_settings_form.goindex 817e420f..d23728d5 100644--- a/backend/cmd/installer/wizard/models/server_settings_form.go+++ b/backend/cmd/installer/wizard/models/server_settings_form.go@@ -101,6 +101,12 @@ func (m *ServerSettingsFormModel) BuildForm() tea.Cmd {config.HTTPClientTimeout,false,))+ fields = append(fields, m.createTextField("terminal_tool_timeout",+ locale.ServerSettingsTerminalToolTimeout,+ locale.ServerSettingsTerminalToolTimeoutDesc,+ config.TerminalToolTimeout,+ false,+ ))// external ssl settingsfields = append(fields, m.createTextField("external_ssl_ca_path",@@ -281,6 +287,14 @@ func (m *ServerSettingsFormModel) GetCurrentConfiguration() string {sections = append(sections, fmt.Sprintf("• %s: %s", locale.ServerSettingsHTTPClientTimeoutHint, httpTimeout))}+ if terminalTimeout := cfg.TerminalToolTimeout.Value; terminalTimeout != "" {+ terminalTimeout = m.GetStyles().Info.Render(terminalTimeout + "s")+ sections = append(sections, fmt.Sprintf("• %s: %s", locale.ServerSettingsTerminalToolTimeoutHint, terminalTimeout))+ } else if terminalTimeout := cfg.TerminalToolTimeout.Default; terminalTimeout != "" {+ terminalTimeout = m.GetStyles().Muted.Render(terminalTimeout + "s")+ sections = append(sections, fmt.Sprintf("• %s: %s", locale.ServerSettingsTerminalToolTimeoutHint, terminalTimeout))+ }+if externalSSLCAPath := cfg.ExternalSSLCAPath.Value; externalSSLCAPath != "" {externalSSLCAPath = m.GetStyles().Info.Render(externalSSLCAPath)sections = append(sections, fmt.Sprintf("• %s: %s", locale.ServerSettingsExternalSSLCAPathHint, externalSSLCAPath))@@ -352,6 +366,8 @@ func (m *ServerSettingsFormModel) GetHelpContent() string {sections = append(sections, locale.ServerSettingsProxyURLHelp)case "http_client_timeout":sections = append(sections, locale.ServerSettingsHTTPClientTimeoutHelp)+ case "terminal_tool_timeout":+ sections = append(sections, locale.ServerSettingsTerminalToolTimeoutHelp)case "external_ssl_ca_path":sections = append(sections, locale.ServerSettingsExternalSSLCAPathHelp)case "external_ssl_insecure":@@ -382,6 +398,7 @@ func (m *ServerSettingsFormModel) HandleSave() error {CookieSigningSalt: cfg.CookieSigningSalt,ProxyURL: cfg.ProxyURL,HTTPClientTimeout: cfg.HTTPClientTimeout,+ TerminalToolTimeout: cfg.TerminalToolTimeout,ExternalSSLCAPath: cfg.ExternalSSLCAPath,ExternalSSLInsecure: cfg.ExternalSSLInsecure,SSLDir: cfg.SSLDir,@@ -430,6 +447,15 @@ func (m *ServerSettingsFormModel) HandleSave() error {}}newCfg.HTTPClientTimeout.Value = value+ case "terminal_tool_timeout":+ if value != "" {+ if timeout, err := strconv.Atoi(value); err != nil {+ return fmt.Errorf("invalid terminal tool timeout: must be a number")+ } else if timeout < 0 {+ return fmt.Errorf("invalid terminal tool timeout: must be >= 0")+ }+ }+ newCfg.TerminalToolTimeout.Value = valuecase "external_ssl_ca_path":newCfg.ExternalSSLCAPath.Value = valuecase "external_ssl_insecure":diff --git a/backend/docs/config.md b/backend/docs/config.mdindex 26b2c342..438d668c 100644--- a/backend/docs/config.md+++ b/backend/docs/config.md@@ -209,6 +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) |### Usage Details@@ -227,6 +228,22 @@ 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`:+ ```go+ term := NewTerminalTool(+ flowID,+ taskID,+ subtaskID,+ containerID,+ containerLID,+ dockerClient,+ termLogProvider,+ time.Duration(cfg.TerminalToolTimeout)*time.Second,+ )+ ```++ 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.+- **DockerNetwork**: Controls the network isolation mode for containers. Supports two modes:**Bridge Mode** (custom network name, e.g., `pentagi-network`):diff --git a/backend/pkg/config/config.go b/backend/pkg/config/config.goindex 0f88c97c..b4d649c4 100644--- a/backend/pkg/config/config.go+++ b/backend/pkg/config/config.go@@ -35,6 +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"`// === 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 10f7c787..9927a599 100644--- a/backend/pkg/config/config_test.go+++ b/backend/pkg/config/config_test.go@@ -271,7 +271,7 @@ func clearConfigEnv(t *testing.T) {envVars := []string{"DATABASE_URL", "DEBUG", "DATA_DIR", "ASK_USER", "INSTALLATION_ID", "LICENSE_KEY","DOCKER_INSIDE", "DOCKER_NET_ADMIN", "DOCKER_SOCKET", "DOCKER_NETWORK",- "DOCKER_PUBLIC_IP", "DOCKER_WORK_DIR", "DOCKER_DEFAULT_IMAGE", "DOCKER_DEFAULT_IMAGE_FOR_PENTEST",+ "DOCKER_PUBLIC_IP", "DOCKER_WORK_DIR", "DOCKER_DEFAULT_IMAGE", "DOCKER_DEFAULT_IMAGE_FOR_PENTEST", "TERMINAL_TOOL_TIMEOUT","SERVER_PORT", "SERVER_HOST", "SERVER_USE_SSL", "SERVER_SSL_KEY", "SERVER_SSL_CRT","STATIC_URL", "STATIC_DIR", "CORS_ORIGINS", "COOKIE_SIGNING_SALT","SCRAPER_PUBLIC_URL", "SCRAPER_PRIVATE_URL",@@ -548,6 +548,31 @@ func TestNewConfig_HTTPClientTimeout(t *testing.T) {})}+func TestNewConfig_TerminalToolTimeout(t *testing.T) {+ clearConfigEnv(t)+ t.Chdir(t.TempDir())++ t.Run("default timeout", func(t *testing.T) {+ config, err := NewConfig()+ require.NoError(t, err)+ assert.Equal(t, 600, config.TerminalToolTimeout)+ })++ t.Run("custom timeout", func(t *testing.T) {+ t.Setenv("TERMINAL_TOOL_TIMEOUT", "900")+ config, err := NewConfig()+ require.NoError(t, err)+ assert.Equal(t, 900, config.TerminalToolTimeout)+ })++ t.Run("zero timeout", func(t *testing.T) {+ t.Setenv("TERMINAL_TOOL_TIMEOUT", "0")+ config, err := NewConfig()+ require.NoError(t, err)+ assert.Equal(t, 0, config.TerminalToolTimeout)+ })+}+func TestNewConfig_AgentSupervisionDefaults(t *testing.T) {clearConfigEnv(t)t.Chdir(t.TempDir())diff --git a/backend/pkg/tools/args.go b/backend/pkg/tools/args.goindex f6cab856..62334c13 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 (minimum 10; maximum 1200; default 60). 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 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"`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 4bcf2b5d..a7efa287 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 with hard limit timeout 1200 seconds and " +- "optimum timeout 60 seconds, only one command can be executed at a time",+ 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. " ++ "Only one command can be executed at a time",Parameters: reflector.Reflect(&TerminalAction{}),},FileToolName: {diff --git a/backend/pkg/tools/terminal.go b/backend/pkg/tools/terminal.goindex 767c4e7d..cfac289b 100644--- a/backend/pkg/tools/terminal.go+++ b/backend/pkg/tools/terminal.go@@ -22,9 +22,10 @@ import ()const (- defaultExecCommandTimeout = 5 * time.Minute- defaultExtraExecTimeout = 5 * time.Second- defaultQuickCheckTimeout = 500 * time.Millisecond+ maxExplicitExecCommandTimeout = 20 * time.Minute+ defaultExtraExecTimeout = 5 * time.Second+ maxRuntimeExecCommandTimeout = maxExplicitExecCommandTimeout + defaultExtraExecTimeout+ defaultQuickCheckTimeout = 500 * time.Millisecond// ANSI terminal color codes (aligned with PentAGI UI palette)ansiColorInputCmd = "\033[96m" // Bright Cyan - matches UI blue accents@@ -39,13 +40,14 @@ type execResult struct {}type terminal struct {- flowID int64- taskID *int64- subtaskID *int64- containerID int64- containerLID string- dockerClient docker.DockerClient- tlp TermLogProvider+ flowID int64+ taskID *int64+ subtaskID *int64+ containerID int64+ containerLID string+ dockerClient docker.DockerClient+ tlp TermLogProvider+ defaultExecTimeout time.Duration}func NewTerminalTool(@@ -54,15 +56,36 @@ func NewTerminalTool(containerID int64, containerLID string,dockerClient docker.DockerClient,tlp TermLogProvider,+ defaultExecTimeout time.Duration,) Tool {return &terminal{- flowID: flowID,- taskID: taskID,- subtaskID: subtaskID,- containerID: containerID,- containerLID: containerLID,- dockerClient: dockerClient,- tlp: tlp,+ flowID: flowID,+ taskID: taskID,+ subtaskID: subtaskID,+ containerID: containerID,+ containerLID: containerLID,+ dockerClient: dockerClient,+ tlp: tlp,+ defaultExecTimeout: defaultExecTimeout,+ }+}++func (t *terminal) configuredExecTimeout() time.Duration {+ if t.defaultExecTimeout < 0 {+ return 0+ }++ return t.defaultExecTimeout+}++func (t *terminal) normalizeExecTimeout(timeout time.Duration) time.Duration {+ switch {+ case timeout > 0 && timeout <= maxRuntimeExecCommandTimeout:+ return timeout+ case timeout > maxRuntimeExecCommandTimeout:+ return t.configuredExecTimeout()+ default:+ return t.configuredExecTimeout()}}@@ -106,7 +129,10 @@ func (t *terminal) Handle(ctx context.Context, name string, args json.RawMessagelogger.WithError(err).Error("failed to unmarshal terminal action")return "", fmt.Errorf("failed to unmarshal terminal action: %w", err)}- timeout := time.Duration(action.Timeout)*time.Second + defaultExtraExecTimeout+ timeout := t.normalizeExecTimeout(time.Duration(action.Timeout) * time.Second)+ if timeout > 0 {+ timeout += defaultExtraExecTimeout+ }result, err := t.ExecCommand(ctx, action.Cwd, action.Input, action.Detach.Bool(), timeout)return t.wrapCommandResult(ctx, args, name, result, err)case FileToolName:@@ -172,9 +198,7 @@ func (t *terminal) ExecCommand(return "", fmt.Errorf("failed to put terminal log (stdin): %w", err)}- if timeout <= 0 || timeout > 20*time.Minute {- timeout = defaultExecCommandTimeout- }+ timeout = t.normalizeExecTimeout(timeout)createResp, err := t.dockerClient.ContainerExecCreate(ctx, containerName, container.ExecOptions{Cmd: cmd,@@ -214,8 +238,11 @@ func (t *terminal) ExecCommand(}func (t *terminal) getExecResult(ctx context.Context, id string, timeout time.Duration) (string, error) {- ctx, cancel := context.WithTimeout(ctx, timeout)- defer cancel()+ if timeout > 0 {+ var cancel context.CancelFunc+ ctx, cancel = context.WithTimeout(ctx, timeout)+ defer cancel()+ }// attach to the exec processresp, err := t.dockerClient.ContainerExecAttach(ctx, id, container.ExecAttachOptions{diff --git a/backend/pkg/tools/terminal_test.go b/backend/pkg/tools/terminal_test.goindex defe0eb8..ff26a77b 100644--- a/backend/pkg/tools/terminal_test.go+++ b/backend/pkg/tools/terminal_test.go@@ -208,3 +208,48 @@ func TestPrimaryTerminalName(t *testing.T) {})}}++func TestNormalizeExecTimeout(t *testing.T) {+ t.Parallel()++ tests := []struct {+ name string+ configured time.Duration+ requested time.Duration+ want time.Duration+ }{+ {+ name: "explicit timeout is preserved",+ configured: 10 * time.Minute,+ requested: 45 * time.Second,+ want: 45 * time.Second,+ },+ {+ name: "zero requested timeout uses configured default",+ configured: 10 * time.Minute,+ requested: 0,+ want: 10 * time.Minute,+ },+ {+ name: "too large explicit timeout falls back to configured default",+ configured: 10 * time.Minute,+ requested: maxRuntimeExecCommandTimeout + time.Second,+ want: 10 * time.Minute,+ },+ {+ name: "configured zero keeps timeout disabled",+ configured: 0,+ requested: 0,+ want: 0,+ },+ }++ 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.normalizeExecTimeout(tt.requested))+ })+ }+}diff --git a/backend/pkg/tools/tools.go b/backend/pkg/tools/tools.goindex 531e296c..a900aa23 100644--- a/backend/pkg/tools/tools.go+++ b/backend/pkg/tools/tools.go@@ -4,6 +4,7 @@ import ("context""encoding/json""fmt"+ "time""pentagi/pkg/config""pentagi/pkg/database"@@ -528,6 +529,7 @@ func (fte *flowToolsExecutor) GetAssistantExecutor(cfg AssistantExecutorConfig)container.LocalID.String,fte.docker,fte.tlp,+ time.Duration(fte.cfg.TerminalToolTimeout)*time.Second,)definitions := []llms.FunctionDefinition{@@ -799,6 +801,7 @@ func (fte *flowToolsExecutor) GetInstallerExecutor(cfg InstallerExecutorConfig)container.LocalID.String,fte.docker,fte.tlp,+ time.Duration(fte.cfg.TerminalToolTimeout)*time.Second,)ce := &customExecutor{@@ -993,6 +996,7 @@ func (fte *flowToolsExecutor) GetPentesterExecutor(cfg PentesterExecutorConfig)container.LocalID.String,fte.docker,fte.tlp,+ time.Duration(fte.cfg.TerminalToolTimeout)*time.Second,)ce := &customExecutor{@@ -1256,6 +1260,7 @@ func (fte *flowToolsExecutor) GetGeneratorExecutor(cfg GeneratorExecutorConfig)container.LocalID.String,fte.docker,fte.tlp,+ time.Duration(fte.cfg.TerminalToolTimeout)*time.Second,)ce := &customExecutor{@@ -1321,6 +1326,7 @@ func (fte *flowToolsExecutor) GetRefinerExecutor(cfg RefinerExecutorConfig) (Concontainer.LocalID.String,fte.docker,fte.tlp,+ time.Duration(fte.cfg.TerminalToolTimeout)*time.Second,)ce := &customExecutor{@@ -1382,6 +1388,7 @@ func (fte *flowToolsExecutor) GetMemoristExecutor(cfg MemoristExecutorConfig) (Ccontainer.LocalID.String,fte.docker,fte.tlp,+ time.Duration(fte.cfg.TerminalToolTimeout)*time.Second,)ce := &customExecutor{@@ -1450,6 +1457,7 @@ func (fte *flowToolsExecutor) GetEnricherExecutor(cfg EnricherExecutorConfig) (Ccontainer.LocalID.String,fte.docker,fte.tlp,+ time.Duration(fte.cfg.TerminalToolTimeout)*time.Second,)ce := &customExecutor{diff --git a/docker-compose.yml b/docker-compose.ymlindex 6a78a7ef..f706b166 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -112,6 +112,7 @@ services:- EXTERNAL_SSL_CA_PATH=${EXTERNAL_SSL_CA_PATH:-}- EXTERNAL_SSL_INSECURE=${EXTERNAL_SSL_INSECURE:-}- HTTP_CLIENT_TIMEOUT=${HTTP_CLIENT_TIMEOUT:-}+ - TERMINAL_TOOL_TIMEOUT=${TERMINAL_TOOL_TIMEOUT:-}- SCRAPER_PUBLIC_URL=${SCRAPER_PUBLIC_URL:-}- SCRAPER_PRIVATE_URL=${SCRAPER_PRIVATE_URL:-}- GRAPHITI_ENABLED=${GRAPHITI_ENABLED:-}