MCPcopy Create free account
hub / github.com/modelscope/ms-agent / _security_check

Method _security_check

ms_agent/skill/container.py:462–485  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 4

execute_python_scriptMethod · 0.95
execute_python_codeMethod · 0.95
execute_shellMethod · 0.95
execute_javascriptMethod · 0.95

Calls 1

searchMethod · 0.45

Tested by

no test coverage detected