Skip to main content
Glama
sandbox.py868 B
import asyncio import time from mcp_run_python import code_sandbox def log_handler(level: str, message: str): print(f'{level}: {message}') code = """ import numpy, asyncio a = numpy.array(thing) print(a) await asyncio.sleep(1) a """ async def main(): async with code_sandbox(dependencies=['numpy'], log_handler=log_handler) as sandbox: print('running code') result = await sandbox.eval(code, {'thing': [1, 2, 3]}) print(f'{result["status"].title()}:') if result['status'] == 'success': print(result['return_value']) else: print(result['error']) tic = time.time() result = await asyncio.gather(*[sandbox.eval(code) for _ in range(10)]) toc = time.time() print(f'Execution time: {toc - tic:.3f} seconds') if __name__ == '__main__': asyncio.run(main())

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pydantic/mcp-run-python'

If you have feedback or need assistance with the MCP directory API, please join our Discord server