melmuk/luasandbox-wrapper
Composer 安装命令:
composer require melmuk/luasandbox-wrapper
包简介
PHP wrapper around the luasandbox extension.
关键字:
README 文档
README
PHP wrapper around the luasandbox extension.
Why this wrapper
ext-luasandbox is powerful but low-level. This package gives you:
- simple
execute(array $data, LuaCode $code): mixedAPI - deterministic per-run sandbox isolation by default
- typed wrapper exceptions
- explicit conversion modes: strict and native-compatible
- configurable memory/CPU limits
- pluggable print output sinks with output-size guard
- rich execution result (
value,output, metrics)
Installation
composer require melmuk/luasandbox-wrapper
Requirements:
- PHP
^8.1 ext-luasandbox
Quick start
<?php use Melmuk\LuaSandboxWrapper\LuaCode; use Melmuk\LuaSandboxWrapper\LuaExecutor; $executor = new LuaExecutor(); $code = new LuaCode(<<<'LUA' function execute(data) print("hello", data.id) data.handled = true return data end LUA); $result = $executor->execute(['id' => 42], $code);
Advanced usage
<?php use Melmuk\LuaSandboxWrapper\LuaCode; use Melmuk\LuaSandboxWrapper\Conversion\ConversionMode; use Melmuk\LuaSandboxWrapper\LuaExecutor; use Melmuk\LuaSandboxWrapper\Output\BufferedOutputSink; use Melmuk\LuaSandboxWrapper\SandboxConfig; $sink = new BufferedOutputSink(); $config = SandboxConfig::defaults() ->withMemoryLimitBytes(32 * 1024 * 1024) ->withCpuLimitSeconds(0.5) ->withConversionMode(ConversionMode::STRICT) ->blacklistLuaGlobals(['math.random']) ->withOutputSink($sink) ->withMaxOutputBytes(64 * 1024); $executor = new LuaExecutor($config); $execution = $executor->run(['id' => 42], LuaCode::forFunction(<<<'LUA' function execute(data) print("processing", data.id) data.ok = true return data end LUA)); $value = $execution->value(); $output = $execution->output(); $durationMs = $execution->durationMs();
Error handling
Catch typed exceptions from Melmuk\LuaSandboxWrapper\Exception:
LuaSandboxExtensionMissingExceptionLuaCompilationExceptionLuaRuntimeExceptionLuaFunctionNotFoundExceptionOutputLimitExceededExceptionLuaExecutionException(base type)
<?php use Melmuk\LuaSandboxWrapper\Exception\LuaExecutionException; try { $executor->execute($data, $code); } catch (LuaExecutionException $e) { // $e->functionName(), $e->phase(), $e->getMessage() }
Output sinks
Included sinks:
StdoutOutputSink(default)BufferedOutputSink
You can implement Melmuk\LuaSandboxWrapper\Output\OutputSink to route print output to logs, queues, etc.
Function Access Tuning
Default behavior uses a blacklist overlay on top of LuaSandbox defaults.
<?php $config = SandboxConfig::defaults() ->blacklistLuaGlobals(['math.random', 'debug.traceback']) ->blacklistLuaLibraries(['os']);
Switch to explicit whitelist mode when you need a strict script contract:
<?php $config = SandboxConfig::defaults() ->whitelistLuaGlobals(['pairs', 'ipairs']) ->whitelistLuaLibraries(['string']);
Testing
composer install
composer test
Tests include config, code object, and integration behavior for execution, output capture, and exception mapping.
Docs
docs/quickstart.mddocs/conversion.mddocs/wrapper-vs-extension.mddocs/reference.md
melmuk/luasandbox-wrapper 适用场景与选型建议
melmuk/luasandbox-wrapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「sandbox」 「lua」 「luasandbox」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 melmuk/luasandbox-wrapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 melmuk/luasandbox-wrapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 melmuk/luasandbox-wrapper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Bindings for qless
Bundle extension that installs and loads Semantic MediaWiki and associated extensions
Package
Inbox pattern process implementation for your Laravel Applications
Php Sandbox in a child process which should make it possible to run user supplied code safely
A Laravel package that intercepts outgoing emails and stores them locally for viewing via an in-app web interface.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2026-03-01