Repository navigation
Conversation
…h an "eval" permission
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Agents that drive a plugin often send code, not single calls. A design agent sends "draw these 40 shapes" as a short script, the way pen.dev's
executeor Figma plugin code work. A plugin's service can't run it:loadstringis removed there. The window hasloadstring, but windows pause while Zeron is hidden, so the work has to happen in the service. Today the only option is to invent a JSON op list.Now a service that asks for
"eval"can run a script it was given:envas its globals: nozeron,require,getfenv/setfenv,debug,print, and no Luau libraries unless the plugin passes them in. What it sets goes into a fresh table that reads through toenv, so the next script doesn't see it. The environment is set when the chunk loads, so there's nosetfenvafterwards.error()or runtime error comes back asfalse, "agent:3: ...".budget_msit returnsfalse, "agent: the script ran past its time budget (1000 ms)"and the service keeps serving. Once over budget, every safepoint raises the error, so apcallthe plugin handed in can't keep the script alive. The call's own 2 s budget still applies.require), 1 MB at most. Running out of memory ends the service, as any call does.zeron.evalraiseszeron.eval needs the "eval" permission."eval"without a service makes the manifest broken. The Allow sheet says "Run scripts its agents write: In its background service, with only what the plugin gives them. They can't do more than the plugin can."Security: the script can only call what the plugin puts in
env, and those functions already run under the plugin's own permissions. Soevaladds no new power, only code the person didn't see when they allowed the plugin. That's why it's a separate permission the Allow sheet names, and not on by default.Documented in
apps/zgx/docs/plugins.md(permission table, the service call table, and a short "Running agents' scripts" section). English and Simplified Chinese strings are in place.Testing
Six new tests in
zeron-engine:a_script_sees_only_what_its_given:zeron,ui,require,getfenv,setfenv,debug,loadstring,_G,print,osare nil inside. String methods still work. A global it sets doesn't reachenv.a_scripts_errors_say_where: syntax erroragent:2:, nil indexagent:3:,error()agent:2: no such screen. Bytecode is refused.a_runaway_script_stops_at_its_budget_and_the_service_goes_on:while true do endand apcall-wrapped loop both stop at 50 ms, then the next script and the next call answer.eval_needs_its_permissiona_hundred_line_script_runs_in_a_few_milliseconds: 100 lines, 98 calls intoenv. Compile and run took 1.0 to 1.7 ms in a debug build.plugins_manifest_broken_rules:"eval"without a service is broken.cargo test -p zeron-engine --lib plugins::service::vm: 14 passed.cargo test -p zeron-engine --lib plugins::: everything passes exceptplugins_templates_bad_and_taken_ids_are_refused, which fails because of a stray%TEMP%\xon my machine (same as #1363). On Windows I had to stub twolibc::getrusagetest helpers locally (chat_persistence.rs,source_control.rs) to compile the engine's lib tests. Those stubs aren't in this PR.cargo clippy -p zeron-engine --testsreports nothing new.I didn't build zgx, so
i18n_testsand the Allow sheet weren't run. The Luau change there is three lines inscreens/plugins/words.luau.For maintainers
evalbe inOUTSIDE_SANDBOX(always asked, even for your own plugins)? I left it out because the script can't do more than the plugin can.zeron.evalin the SDK'szeron.luauheader. That file is copied byte for byte into 16 bundled plugins, so I left that to you.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.