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

Method _local_run_subprocess

ms_agent/skill/container.py:548–591  ·  view source on GitHub ↗

Run subprocess locally with security restrictions. Cross-platform support with timeout and resource limits. Args: cmd: Command list to execute. env: Environment variables. cwd: Working directory. stdin_input: Input to pass to

(self,
                              cmd: List[str],
                              env: Dict[str, str] = None,
                              cwd: Path = None,
                              stdin_input: str = None)

Source from the content-addressed store, hash-verified

546 # -------------------------------------------------------------------------
547
548 def _local_run_subprocess(self,
549 cmd: List[str],
550 env: Dict[str, str] = None,
551 cwd: Path = None,
552 stdin_input: str = None) -> tuple[str, str, int]:
553 """
554 Run subprocess locally with security restrictions.
555
556 Cross-platform support with timeout and resource limits.
557
558 Args:
559 cmd: Command list to execute.
560 env: Environment variables.
561 cwd: Working directory.
562 stdin_input: Input to pass to stdin.
563
564 Returns:
565 Tuple of (stdout, stderr, exit_code).
566 """
567 # Setup environment
568 run_env = os.environ.copy()
569 run_env['SKILL_OUTPUT_DIR'] = str(self.output_dir)
570 if env:
571 run_env.update(env)
572
573 # Use workspace as default cwd
574 work_dir = cwd or self.workspace_dir
575
576 try:
577 result = subprocess.run(
578 cmd,
579 capture_output=True,
580 text=True,
581 timeout=self.timeout,
582 cwd=str(work_dir),
583 env=run_env,
584 stdin=subprocess.PIPE if stdin_input else None,
585 input=stdin_input,
586 )
587 return result.stdout, result.stderr, result.returncode
588 except subprocess.TimeoutExpired:
589 return '', f'Execution timed out after {self.timeout}s', -1
590 except Exception as e:
591 return '', str(e), -1
592
593 def _get_python_executable(self) -> str:
594 """Get the Python executable for the current platform."""

Calls 2

updateMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected