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

Method execute_shell

ms_agent/skill/container.py:1132–1220  ·  view source on GitHub ↗

Execute a shell command. Uses sandbox mode or local mode based on use_sandbox setting. Args: command: Shell command string or list of commands. skill_id: Identifier of the skill being executed. input_spec: Input specification. R

(
            self,
            command: Union[str, List[str]],
            skill_id: str = 'unknown',
            input_spec: ExecutionInput = None)

Source from the content-addressed store, hash-verified

1130 return output
1131
1132 async def execute_shell(
1133 self,
1134 command: Union[str, List[str]],
1135 skill_id: str = 'unknown',
1136 input_spec: ExecutionInput = None) -> ExecutionOutput:
1137 """
1138 Execute a shell command.
1139
1140 Uses sandbox mode or local mode based on use_sandbox setting.
1141
1142 Args:
1143 command: Shell command string or list of commands.
1144 skill_id: Identifier of the skill being executed.
1145 input_spec: Input specification.
1146
1147 Returns:
1148 ExecutionOutput with results.
1149 """
1150 input_spec = input_spec or ExecutionInput()
1151
1152 cmd_str = command if isinstance(command, str) else ' && '.join(command)
1153
1154 record = self._create_record(
1155 skill_id=skill_id,
1156 executor_type=ExecutorType.SHELL,
1157 input_spec=input_spec,
1158 script_path=cmd_str[:200])
1159
1160 record.start_time = datetime.now()
1161 record.status = ExecutionStatus.RUNNING
1162
1163 try:
1164 # Security check (stricter for local mode)
1165 is_safe, reason = self._security_check(
1166 cmd_str, is_local=not self.use_sandbox)
1167 if not is_safe:
1168 record.status = ExecutionStatus.SECURITY_BLOCKED
1169 record.error_message = reason
1170 output = ExecutionOutput(
1171 stderr=f'Security check failed: {reason}', exit_code=-1)
1172 record.end_time = datetime.now()
1173 record.output_spec = output
1174 self.spec.add_record(record)
1175 return output
1176
1177 start_time = datetime.now()
1178
1179 if self.use_sandbox:
1180 # Sandbox mode: prepend environment setup
1181 env_exports = [
1182 f"export SKILL_OUTPUT_DIR='{self.SANDBOX_OUTPUT_DIR}'",
1183 ]
1184 for key, value in input_spec.env_vars.items():
1185 safe_value = value.replace("'", "\\'")
1186 env_exports.append(f"export {key}='{safe_value}'")
1187
1188 full_cmd = ' && '.join(env_exports + [cmd_str])
1189

Callers 2

executeMethod · 0.95
_execute_commandMethod · 0.80

Calls 9

_create_recordMethod · 0.95
_security_checkMethod · 0.95
_execute_in_sandboxMethod · 0.95
_parse_sandbox_resultMethod · 0.95
_local_execute_shellMethod · 0.95
_collect_output_filesMethod · 0.95
ExecutionInputClass · 0.85
ExecutionOutputClass · 0.85
add_recordMethod · 0.80

Tested by

no test coverage detected