Tencent/WeKnora · error
timeout cannot be negative
Error message
timeout cannot be negative
What it means
ValidateConfig rejects a SandboxConfig whose DefaultTimeout is negative. Timeouts must be zero (no default) or positive; a negative value indicates a computation or config parsing bug, so Manager creation refuses to proceed.
Source
Thrown at internal/sandbox/sandbox.go:378
CubeHTTPTimeout: DefaultCubeHTTPTimeout,
}
}
// ValidateConfig validates sandbox configuration
func ValidateConfig(config *Config) error {
if config == nil {
return errors.New("config is nil")
}
switch config.Type {
case SandboxTypeDocker, SandboxTypeCube, SandboxTypeE2B, SandboxTypeDisabled:
// Valid types
default:
return errors.New("invalid sandbox type")
}
if config.DefaultTimeout < 0 {
return errors.New("timeout cannot be negative")
}
if config.MaxMemory < 0 {
return errors.New("memory limit cannot be negative")
}
if config.MaxCPU < 0 {
return errors.New("CPU limit cannot be negative")
}
return nil
}
View on GitHub (pinned to 988cbb0330)
Solutions
- Set DefaultTimeout to a positive duration (e.g. 30 * time.Second) or leave it at zero for no default.
- Audit where the value is computed — fix any time.Since/time.Until mixup producing negatives.
- Validate DefaultTimeout >= 0 before constructing the Manager and fail fast with context.
Example fix
// before
cfg.DefaultTimeout = time.Until(deadline) // negative if deadline passed
// after
if d := time.Until(deadline); d > 0 {
cfg.DefaultTimeout = d
} else {
cfg.DefaultTimeout = 30 * time.Second
} Defensive patterns
Strategy: validation
Validate before calling
if cfg.DefaultTimeout < 0 {
return fmt.Errorf("invalid sandbox config: DefaultTimeout=%v must be >= 0", cfg.DefaultTimeout)
} Try / catch
if err := sandbox.ValidateConfig(cfg); err != nil {
if strings.Contains(err.Error(), "timeout") {
cfg.DefaultTimeout = 30 * time.Second // safe default
return nil
}
return err
} Prevention
- Use time.Duration typed fields everywhere; avoid raw ints.
- Never assign the result of time.Since as a timeout; use time.Until with a positivity check.
- Validate configs in unit tests.
When it happens
Trigger: Passing a SandboxConfig with DefaultTimeout < 0 to NewManager or NewSessionBoundManager, e.g. from subtracting timestamps, misreading duration units, or a negative number in a config file.
Common situations: Loading YAML/JSON config with a negative timeout; computing a deadline with time.Since instead of time.Until and storing the negative result.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- E2B timeout must be at least one second
- invalid sandbox type
- memory limit cannot be negative
- CPU limit cannot be negative
- E2B backend does not support NeverTimeout
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/f0abfd17126ab8bd.
Report an issue: GitHub.