Python代码执行技能Skill python-executor

这个技能允许在安全沙箱环境中执行Python代码,预装了100多个库,如NumPy、Pandas、Matplotlib等,适用于数据科学、网络抓取、图像处理、视频制作、3D模型处理和自动化脚本等多种任务。关键词:Python代码执行,沙箱安全,数据分析,网络抓取,图像处理,视频编辑,3D建模,自动化脚本。

数据分析 0 次安装 0 次浏览 更新于 3/12/2026

name: python-executor description: “在安全沙箱环境中通过inference.sh执行Python代码。预安装:NumPy, Pandas, Matplotlib, requests, BeautifulSoup, Selenium, Playwright, MoviePy, Pillow, OpenCV, trimesh, 以及100多个库。用途:数据处理,网络抓取,图像操作,视频创建,3D模型处理,PDF生成,API调用,自动化脚本。触发词:python, 执行代码, 运行脚本, 网络抓取, 数据分析, 图像处理, 视频编辑, 3D模型, 自动化, pandas, matplotlib” allowed-tools: Bash(infsh *)

Python代码执行器

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

Python代码执行器

快速开始

curl -fsSL https://cli.inference.sh | sh && infsh login

# 运行Python代码
infsh app run infsh/python-executor --input '{
  "code": "import pandas as pd
print(pd.__version__)"
}'

安装说明: 安装脚本仅检测您的操作系统/架构,从dist.inference.sh下载匹配的二进制文件,并验证其SHA-256校验和。无需提升权限或后台进程。手动安装与验证可用。

应用详情

属性
应用ID infsh/python-executor
环境 Python 3.10, 仅CPU
内存 8GB(默认)/ 16GB(高内存)
超时时间 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生成

示例

网络抓取

infsh app run infsh/python-executor --input '{
  "code": "import requests
from bs4 import BeautifulSoup

response = requests.get(\"https://example.com\")
soup = BeautifulSoup(response.content, \"html.parser\")
print(soup.find(\"title\").text)"
}'

数据分析与可视化

infsh app run infsh/python-executor --input '{
  "code": "import pandas as pd
import matplotlib.pyplot as plt

data = {\"name\": [\"Alice\", \"Bob\"], \"sales\": [100, 150]}
df = pd.DataFrame(data)

plt.bar(df[\"name\"], df[\"sales\"])
plt.savefig(\"outputs/chart.png\")
print(\"图表已保存!\")"
}'

图像处理

infsh app run infsh/python-executor --input '{
  "code": "from PIL import Image
import numpy as np

# 创建渐变图像
arr = np.linspace(0, 255, 256*256, dtype=np.uint8).reshape(256, 256)
img = Image.fromarray(arr, mode=\"L\")
img.save(\"outputs/gradient.png\")
print(\"图像已创建!\")"
}'

视频创建

infsh app run infsh/python-executor --input '{
  "code": "from moviepy.editor import ColorClip, TextClip, CompositeVideoClip

clip = ColorClip(size=(640, 480), color=(0, 100, 200), duration=3)
txt = TextClip(\"Hello!\", fontsize=70, color=\"white\").set_position(\"center\").set_duration(3)
video = CompositeVideoClip([clip, txt])
video.write_videofile(\"outputs/hello.mp4\", fps=24)
print(\"视频已创建!\")",
  "timeout": 120
}'

3D模型处理

infsh app run infsh/python-executor --input '{
  "code": "import trimesh

sphere = trimesh.creation.icosphere(subdivisions=3, radius=1.0)
sphere.export(\"outputs/sphere.stl\")
print(f\"创建了具有{len(sphere.vertices)}个顶点的球体\")"
}'

API调用

infsh app run infsh/python-executor --input '{
  "code": "import requests
import json

response = requests.get(\"https://api.github.com/users/octocat\")
data = response.json()
print(json.dumps(data, indent=2))"
}'

文件输出

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

# 这些文件将在响应中返回
plt.savefig('outputs/chart.png')
df.to_csv('outputs/data.csv')
video.write_videofile('outputs/video.mp4')
mesh.export('outputs/model.stl')

变体

# 默认(8GB内存)
infsh app run infsh/python-executor --input input.json

# 高内存(16GB内存)用于大型数据集
infsh 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图像生成(用于基于ML的图像)
npx skills add inference-sh/skills@ai-image-generation

# AI视频生成(用于基于ML的视频)
npx skills add inference-sh/skills@ai-video-generation

# LLM模型(用于文本生成)
npx skills add inference-sh/skills@llm-models

文档