Check code for potentially dangerous patterns. Args: code: Code string to check. is_local: If True, use stricter patterns for local execution. Returns: Tuple of (is_safe, reason).
(self,
code: str,
is_local: bool = False)
| 460 | return f'{self.SANDBOX_ROOT}/skills/{safe_id}' |
| 461 | |
| 462 | def _security_check(self, |
| 463 | code: str, |
| 464 | is_local: bool = False) -> tuple[bool, str]: |
| 465 | """ |
| 466 | Check code for potentially dangerous patterns. |
| 467 | |
| 468 | Args: |
| 469 | code: Code string to check. |
| 470 | is_local: If True, use stricter patterns for local execution. |
| 471 | |
| 472 | Returns: |
| 473 | Tuple of (is_safe, reason). |
| 474 | """ |
| 475 | if not self.enable_security_check: |
| 476 | return True, '' |
| 477 | |
| 478 | # Use stricter patterns for local execution |
| 479 | patterns = LOCAL_DANGEROUS_PATTERNS if is_local else DANGEROUS_PATTERNS |
| 480 | |
| 481 | for pattern in patterns: |
| 482 | if re.search(pattern, code, re.IGNORECASE): |
| 483 | return False, f'Dangerous pattern detected: {pattern}' |
| 484 | |
| 485 | return True, '' |
| 486 | |
| 487 | def _validate_path_in_workspace(self, path: Path) -> bool: |
| 488 | """ |
no test coverage detected