validateSandboxConfig validates the sandbox configuration Returns an error if the configuration is invalid
(workflowData *WorkflowData)
| 69 | // validateSandboxConfig validates the sandbox configuration |
| 70 | // Returns an error if the configuration is invalid |
| 71 | func validateSandboxConfig(workflowData *WorkflowData) error { |
| 72 | if workflowData == nil { |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | if workflowData.SandboxConfig == nil { |
| 77 | return nil // No sandbox config is valid |
| 78 | } |
| 79 | |
| 80 | sandboxConfig := workflowData.SandboxConfig |
| 81 | |
| 82 | // Check if sandbox.agent: false was specified |
| 83 | // This requires the "dangerously-disable-sandbox-agent" feature to include a |
| 84 | // justification string. Without a valid justification, disabling the sandbox |
| 85 | // is a validation error. |
| 86 | if sandboxConfig.Agent != nil && sandboxConfig.Agent.Disabled { |
| 87 | justification, err := getSandboxDisableJustification(workflowData) |
| 88 | if err != nil { |
| 89 | flag := string(constants.DangerouslyDisableSandboxAgentFeatureFlag) |
| 90 | return NewValidationError( |
| 91 | "sandbox.agent", |
| 92 | "false", |
| 93 | fmt.Sprintf("disabling the agent sandbox removes a trust boundary: '%s' must be a literal justification string (%d+ chars, no expressions): %v", flag, minSandboxDisableJustificationLength, err), |
| 94 | fmt.Sprintf("Add the feature value to your workflow frontmatter:\n\nfeatures:\n %s: \"controlled environment with no internet access\"\nsandbox:\n agent: false\n\nSee: %s", flag, constants.DocsSandboxURL), |
| 95 | ) |
| 96 | } |
| 97 | sandboxConfig.Agent.DisableReason = justification |
| 98 | sandboxValidationLog.Printf("sandbox.agent: false permitted by %s justification: %q", constants.DangerouslyDisableSandboxAgentFeatureFlag, justification) |
| 99 | } |
| 100 | |
| 101 | // Validate mounts syntax if specified in agent config |
| 102 | agentConfig := getAgentConfig(workflowData) |
| 103 | if agentConfig != nil && len(agentConfig.Mounts) > 0 { |
| 104 | if err := validateMountsSyntax(agentConfig.Mounts); err != nil { |
| 105 | return err |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // Validate config structure if provided (deprecated - was only for SRT) |
| 110 | if sandboxConfig.Config != nil { |
| 111 | // Config is no longer used - SRT removed |
| 112 | return NewConfigurationError( |
| 113 | "sandbox.config", |
| 114 | "deprecated", |
| 115 | "custom sandbox config is deprecated (was only for Sandbox Runtime which has been removed)", |
| 116 | "Remove sandbox.config from your workflow. AWF (Agent Workflow Firewall) is the only supported sandbox and does not use this configuration.", |
| 117 | ) |
| 118 | } |
| 119 | |
| 120 | // Validate MCP gateway port if configured |
| 121 | if sandboxConfig.MCP != nil && sandboxConfig.MCP.Port != 0 { |
| 122 | if err := validateIntRange(sandboxConfig.MCP.Port, constants.MinNetworkPort, constants.MaxNetworkPort, "sandbox.mcp.port"); err != nil { |
| 123 | return err |
| 124 | } |
| 125 | sandboxValidationLog.Printf("Validated MCP gateway port: %d", sandboxConfig.MCP.Port) |
| 126 | } |
| 127 | |
| 128 | // Validate that if agent sandbox is enabled, MCP gateway is always enabled. |