通过 [inference.sh](https://inference.sh) 在安全沙箱环境中执行 Python 代码。预装:NumPy、Pandas、Matplotlib、requests、BeautifulSoup 等。
Python 代码执行器是一项面向实际任务的技能,主要用于在安全沙箱环境中执行 Python 代码, 并带有100+ 预安装库;XQQ 快速启动;
该技能适合需要稳定复用相关能力的场景,可作为自动化工作流的一部分,也便于后续检查、调整和扩展。从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;
若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
在安全、沙箱化的环境中执行 Python 代码,预装了 100+ 个常用库。

curl -fsSL https://cli.inference.sh | sh && infsh login
# 运行 Python 代码
infsh app run infsh/python-executor --input '{
"code": "import pandas as pdnprint(pd.__version__)"
}'
安装说明:安装脚本仅检测您的操作系统与架构,从
dist.inference.sh下载匹配的二进制文件,并校验其 SHA-256 校验和。不请求提权权限,也不启动后台进程。支持手动安装与校验。
| 属性 | 值 |
|---|---|
| App ID | infsh/python-executor |
| 运行环境 | Python 3.10,仅 CPU |
| 内存 | 8GB(默认) / 16GB(high_memory) |
| 超时时间 | 1–300 秒(默认:30 秒) |
{
"code": "print('Hello World!')",
"timeout": 30,
"capture_output": true,
"working_dir": null
}
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 — 音频操作trimesh、open3d — 3D 网格处理numpy-stl、meshio、pyvista — 3D 文件格式支持svgwrite、cairosvg — SVG 生成reportlab、pypdf2 — PDF 生成infsh app run infsh/python-executor --input '{
"code": "import requestsnfrom bs4 import BeautifulSoupnnresponse = requests.get("https://example.com")nsoup = BeautifulSoup(response.content, "html.parser")nprint(soup.find("title").text)"
}'
infsh app run infsh/python-executor --input '{
"code": "import pandas as pdnimport matplotlib.pyplot as pltnndata = {"name": ["Alice", "Bob"], "sales": [100, 150]}ndf = pd.DataFrame(data)nnplt.bar(df["name"], df["sales"])nplt.savefig("outputs/chart.png")nprint("Chart saved!")"
}'
infsh app run infsh/python-executor --input '{
"code": "from PIL import Imagenimport numpy as npnn# Create gradient imagenarr = 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!")"
}'
infsh app run infsh/python-executor --input '{
"code": "from moviepy.editor import ColorClip, TextClip, CompositeVideoClipnnclip = 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
}'
infsh app run infsh/python-executor --input '{
"code": "import trimeshnnsphere = trimesh.creation.icosphere(subdivisions=3, radius=1.0)nsphere.export("outputs/sphere.stl")nprint(f"Created sphere with {len(sphere.vertices)} vertices")"
}'
infsh app run infsh/python-executor --input '{
"code": "import requestsnimport jsonnnresponse = requests.get("https://api.github.com/users/octocat")ndata = response.json()nprint(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
plt.savefig(),而非 plt.show()outputs/ 下的文件将被自动识别并返回# AI 图像生成(适用于基于 ML 的图像生成) npx skills add inference-sh/skills@ai-image-generation # AI 视频生成(适用于基于 ML 的视频生成) npx skills add inference-sh/skills@ai-video-generation # 大语言模型(适用于文本生成) npx skills add inference-sh/skills@llm-models