mcpField
P
python-executor

python-executor

github.com/magentosh开发498.1k 次安装12 周前更新
代码仓库

关于 python-executor

python-executor 是一项 belt 技能,可在隔离的纯 CPU 环境中运行 Python 代码,并预装常用库,适合需要执行脚本并获取生成文件的 Agent 和用户。

主要功能

  1. 01沙箱化运行 Python 3.10
  2. 02预装 100 多个库
  3. 03可配置超时和内存版本
  4. 04自动返回 outputs/ 中的文件

适用场景

  1. 01抓取网页内容
  2. 02分析并可视化数据集
  3. 03处理图像、视频和 3D 模型
  4. 04调用 API 并生成文档

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/magentosh/superpowers --skill python-executor

安装后在 Claude Code 中输入/python-executor确认已加载。

详细介绍

安装 belt CLI 技能: npx skills add belt-sh/cli

Python 代码执行器

在安全的沙盒环境中执行 Python 代码,预装 100 多个库。

Python 代码执行器

快速开始

需要 inference.sh CLI(belt)。安装说明

belt login

# Run Python code
belt app run infsh/python-executor --input '{
  "code": "import pandas as pd\nprint(pd.__version__)"
}'

应用详情

属性值
应用 IDinfsh/python-executor
环境Python 3.10,仅 CPU
RAM8GB(默认)/ 16GB(high_memory)
超时1-300 秒(默认:30)

输入架构

{
  "code": "print('Hello World!')",
  "timeout": 30,
  "capture_output": true,
  "working_dir": null
}

预装库

网页抓取与 HTTP
  • requests、httpx、aiohttp - HTTP 客户端
  • beautifulsoup4、lxml - HTML/XML 解析
  • selenium、playwright - 浏览器自动化
  • scrapy - 网页抓取框架
数据处理
  • numpy、pandas、scipy - 数值计算
  • matplotlib、seaborn、plotly - 可视化
图像处理
  • pillow、opencv-python-headless - 图像操作
  • scikit-image、imageio - 图像算法
视频与音频
  • moviepy - 视频编辑
  • av(PyAV)、ffmpeg-python - 视频处理
  • pydub - 音频操作
3D 处理
  • trimesh、open3d - 3D 网格处理
  • numpy-stl、meshio、pyvista - 3D 文件格式
文档与图形
  • svgwrite、cairosvg - SVG 创建
  • reportlab、pypdf2 - PDF 生成

示例

网页抓取
belt app run infsh/python-executor --input '{
  "code": "import requests\nfrom bs4 import BeautifulSoup\n\nresponse = requests.get(\"https://example.com\")\nsoup = BeautifulSoup(response.content, \"html.parser\")\nprint(soup.find(\"title\").text)"
}'
使用可视化进行数据分析
belt app run infsh/python-executor --input '{
  "code": "import pandas as pd\nimport matplotlib.pyplot as plt\n\ndata = {\"name\": [\"Alice\", \"Bob\"], \"sales\": [100, 150]}\ndf = pd.DataFrame(data)\n\nplt.bar(df[\"name\"], df[\"sales\"])\nplt.savefig(\"outputs/chart.png\")\nprint(\"Chart saved!\")"
}'
图像处理
belt app run infsh/python-executor --input '{
  "code": "from PIL import Image\nimport numpy as np\n\n# Create gradient image\narr = np.linspace(0, 255, 256*256, dtype=np.uint8).reshape(256, 256)\nimg = Image.fromarray(arr, mode=\"L\")\nimg.save(\"outputs/gradient.png\")\nprint(\"Image created!\")"
}'
视频创建
belt app run infsh/python-executor --input '{
  "code": "from moviepy.editor import ColorClip, TextClip, CompositeVideoClip\n\nclip = ColorClip(size=(640, 480), color=(0, 100, 200), duration=3)\ntxt = TextClip(\"Hello!\", fontsize=70, color=\"white\").set_position(\"center\").set_duration(3)\nvideo = CompositeVideoClip([clip, txt])\nvideo.write_videofile(\"outputs/hello.mp4\", fps=24)\nprint(\"Video created!\")",
  "timeout": 120
}'
3D 模型处理
belt app run infsh/python-executor --input '{
  "code": "import trimesh\n\nsphere = trimesh.creation.icosphere(subdivisions=3, radius=1.0)\nsphere.export(\"outputs/sphere.stl\")\nprint(f\"Created sphere with {len(sphere.vertices)} vertices\")"
}'
API 调用
belt app run infsh/python-executor --input '{
  "code": "import requests\nimport json\n\nresponse = requests.get(\"https://api.github.com/users/octocat\")\ndata = response.json()\nprint(json.dumps(data, indent=2))"
}'

文件输出

保存到 outputs/ 的文件会自动返回:

# These files will be in the response
plt.savefig('outputs/chart.png')
df.to_csv('outputs/data.csv')
video.write_videofile('outputs/video.mp4')
mesh.export('outputs/model.stl')

变体

# Default (8GB RAM)
belt app run infsh/python-executor --input input.json

# High memory (16GB RAM) for large datasets
belt app run infsh/python-executor@high_memory --input input.json

使用场景

  • 网页抓取 - 从网站提取数据
  • 数据分析 - 处理并可视化数据集
  • 图像处理 - 调整图像大小、裁剪和合成图像
  • 视频创建 - 生成带文字叠加的视频
  • 3D 处理 - 加载、转换并导出 3D 模型
  • API 集成 - 调用外部 API
  • PDF 生成 - 创建报告和文档
  • 自动化 - 运行任意 Python 脚本

重要说明

  • 仅 CPU - 不含 GPU/ML 库(此类任务请使用专用 AI 应用)
  • 安全执行 - 在隔离的子进程中运行
  • 非交互式 - 使用 plt.savefig(),而非 plt.show()
  • 文件检测 - 自动检测并返回输出文件

相关技能

# AI image generation (for ML-based images)
npx skills add inference-sh/skills@ai-image-generation

# AI video generation (for ML-based videos)
npx skills add inference-sh/skills@ai-video-generation

# LLM models (for text generation)
npx skills add inference-sh/skills@llm-models

文档

评论

支持 Markdown