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

Method execute_javascript

ms_agent/skill/container.py:1222–1326  ·  view source on GitHub ↗

Execute JavaScript code via Node.js. Uses sandbox mode or local mode based on use_sandbox setting. Args: script_path: Path to JavaScript file. code: Inline JavaScript code (if no script_path). skill_id: Identifier of the skill being exec

(self,
                                 script_path: Union[str, Path] = None,
                                 code: str = None,
                                 skill_id: str = 'unknown',
                                 input_spec: ExecutionInput = None,
                                 runtime: str = 'node')

Source from the content-addressed store, hash-verified

1220 return output
1221
1222 async def execute_javascript(self,
1223 script_path: Union[str, Path] = None,
1224 code: str = None,
1225 skill_id: str = 'unknown',
1226 input_spec: ExecutionInput = None,
1227 runtime: str = 'node') -> ExecutionOutput:
1228 """
1229 Execute JavaScript code via Node.js.
1230
1231 Uses sandbox mode or local mode based on use_sandbox setting.
1232
1233 Args:
1234 script_path: Path to JavaScript file.
1235 code: Inline JavaScript code (if no script_path).
1236 skill_id: Identifier of the skill being executed.
1237 input_spec: Input specification.
1238 runtime: JavaScript runtime ('node' or 'deno').
1239
1240 Returns:
1241 ExecutionOutput with results.
1242 """
1243 input_spec = input_spec or ExecutionInput()
1244
1245 record = self._create_record(
1246 skill_id=skill_id,
1247 executor_type=ExecutorType.JAVASCRIPT,
1248 input_spec=input_spec,
1249 script_path=str(script_path) if script_path else '<inline>')
1250
1251 record.start_time = datetime.now()
1252 record.status = ExecutionStatus.RUNNING
1253
1254 try:
1255 # Get JavaScript code
1256 if script_path:
1257 with open(script_path, 'r', encoding='utf-8') as f:
1258 js_code = f.read()
1259 elif code:
1260 js_code = code
1261 else:
1262 raise ValueError('Either script_path or code must be provided')
1263
1264 # Security check (stricter for local mode)
1265 is_safe, reason = self._security_check(
1266 js_code, is_local=not self.use_sandbox)
1267 if not is_safe:
1268 record.status = ExecutionStatus.SECURITY_BLOCKED
1269 record.error_message = reason
1270 output = ExecutionOutput(
1271 stderr=f'Security check failed: {reason}', exit_code=-1)
1272 record.end_time = datetime.now()
1273 record.output_spec = output
1274 self.spec.add_record(record)
1275 return output
1276
1277 start_time = datetime.now()
1278
1279 if self.use_sandbox:

Callers 2

executeMethod · 0.95
_execute_commandMethod · 0.80

Calls 11

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

Tested by

no test coverage detected