skills/matlab/references/executing-scripts.md
This reference explains reviewed execution plans. Bundled helpers never launch MATLAB, GNU Octave, MATLAB Engine, MEX, a compiler, or any subprocess.
Before execution, confirm all of the following:
.m file is trusted and statically reviewed;.mlx, .fig, .mlapp, MEX, MAT object, project action,
startup file, package, or generated artifact is reachable;Static scan findings are not proof of safety. Never execute a file solely to discover what it does.
-batchMathWorks recommends -batch for noninteractive command-line workflows.
Conceptually, an approved plan looks like:
["matlab", "-batch", "run('/reviewed/project/main.m')"]
This is argv, not an instruction to run untrusted code.
Official R2026a behavior:
-noFigureWindows or -nodisplay;-r;Use -sd <reviewed-folder> to set the initial folder. Do not embed untrusted
text in a MATLAB statement. Prefer a fixed function name and JSON-validated
scalar/list arguments converted by the planner.
MATLAB startup still matters. On Linux, the launcher processes
.matlab7rc.sh; MATLAB also runs matlabrc.m and the first executable
startup on its path. finish.m can run at normal exit. A MATLAB Project can
add paths and run startup/shutdown actions. -sd is not a security sandbox.
-r is for interactive workflows and has not been recommended for
noninteractive use since R2019a. Older -r "...; exit" patterns are easier to
hang or mask errors.
python scripts/plan_batch_command.py matlab script src/main.m --root .
python scripts/plan_batch_command.py matlab function src/analyze.m \
--root . --arg-json '{"value": 3}'
python scripts/plan_batch_command.py matlab tests tests/TestAnalyze.m --root .
The planner:
.m target under --root;.mlx, MEX, and oversized paths;executes=false;PATH, calls a runtime, reads credentials, or spawns a process.JSON object arguments are represented as a MATLAB struct; arrays and scalar
JSON values use bounded literal conversion. Review semantics and shape before
approval.
The current manual documents:
--eval/-e to evaluate code and exit;--no-gui, --quiet, and --no-history;--no-init-all/--norc to skip system and user initialization;--path to add a narrow function path;--no-window-system to disable graphics entirely.For deterministic reviewed plans, prefer --no-init-all --no-history --quiet --no-gui. Use --no-window-system only when graphics are not needed.
Octave also has site, version, user, local .octaverc, and MATLAB-compatible
startup.m files; skipping them changes expected user configuration and must
be a conscious choice.
Octave does not implement MATLAB -batch, Projects, or
matlab.unittest. Its BIST test function and %!test blocks are different.
Do not use an Octave result as proof that MATLAB code, graphics, toolboxes, or
deployment will behave identically.
For automation:
exit inside library
code;R2026a runtests automatically opens and closes a project when tests belong
to a project not already open. Review project startup/shutdown behavior before
using it.
Base MATLAB has matlab.unittest; parallel execution requires Parallel
Computing Toolbox. Advanced dependency selection, dashboards, generated tests,
coverage/equivalence features can require MATLAB Test or other products.
Separate four questions:
matlab.codetools.requiredFilesAndProducts and Dependency Analyzer address
the first question imperfectly. license("inuse") observes only products used
on executed paths and itself requires launching MATLAB. None grants a license.
Do not automatically install MATLAB or a toolbox. Downloads, installers, network-license configuration, and unattended automation are governed by the user's MathWorks account, administrator, and license terms. The R2026a Program Offering Guide has specific automation-server and external-application terms; do not paraphrase it as legal permission.
Building requires MATLAB plus the compiler/code-generation product and all
products used by the source. Deployed applications can use MATLAB Runtime
under applicable terms, but Runtime does not execute arbitrary .m code and
cannot host MATLAB Engine for Python. Generated code must be verified; compiler
success is not scientific validation.
Never compile untrusted MATLAB, MEX, C/C++, model, or package input.
A safe CI design uses:
MathWorks provides CI integrations, but their presence does not include MATLAB or grant a license.
codeCompatibilityReport and Project Upgrade on reviewed code.Notable base changes relevant to this skill include Python 3.13 support and
environment management, Python string conversion, JSON table/timetable I/O,
interactive HTML export, faster startup and selected kernels, and project-aware
runtests. Read the release notes rather than assuming this list is complete.
matlab on Linux and -batchruntests R2026a behaviorrequiredFilesAndProducts