Matlab and 'sandbox' process Peak CPU Usage in macOS Big Sur
Show older comments
Matlab version: 9.10.0.1684407 (R2021a) Update 3'
System Version: Big Sur 11.4 (20F71)
MacBook Pro: (13-inch, 2020, Four Thunderbolt 3 ports)
Processor: 2 GHz Quad-Core Intel Core i5
Memory: 16 GB 3733 MHz LPDDR4X
Graphics card: Intel Iris Plus Graphics 1536 MB
Problem:
In the image bellow I pressed command+return to run the code and the sandboxed process started to peak. This happens all the time while using matlab. Sometimes even when just typing in in the code editor. I even tried closing all other applications in the system and run just Matlab, the problem persisted.

From time to time the sandboxd process peaks CPU usage and the entire Matlab becomes laggy, impossible to use. It is a recurrent problem. I tried installing 2020b version, but same thing happened. I'm not using Magnet or other window snaping tool.
I've sent a feedback to Mathworks under this identifier when it happened to froze once, forcing me to quit the application: Help troubleshooting recent MATLAB crash: 04938298 ref:_00Di0Ha1u._5003q1PuOu8:ref
Accepted Answer
More Answers (4)
Raphaël Nussbaumer
on 11 Dec 2021
0 votes
Kill this process was the only solution which worked for me. I'm having to do that roughly every 30min.
The problem occurs frequently, even in 11.6.2 (Big Sur) with 2021b. I agree with Raphaël Nussbaumer that stopping the spindump task fixes the problem. For me, it occurs when the editor window is clicked from the command window or a file is opened with a double click, on OSX (MacBook Pro (13", 2020, 2.3 GHz quad-core Intel Core i7, 32 GB 3733 MHz LPDDR4X)
Matthew Johnson
on 29 Apr 2022
0 votes
I'm not sure if what just worked for me will work for everyone -- it sounds like there could possibly be several closely-related variations on the same issue. But my 2021b was hanging on startup similar to what others were getting. I tried launching from the command line without the desktop running ( /Applications/MATLAB_R2021b.app/bin/matlab -nodesktop ) and then running the desktop command from within the terminal. When I did that, I got an error message about my desktop layout configuration XML file being corrupted, and that MATLAB was going to use the default configuration. I went ahead and re-positioned my window and panes, and then exited MATLAB and restarted the usual (non-command-line) way, and it started up just fine (and it appeared to have successfully saved my desktop layout). Again, not sure if others are having the same issue for the same reason, but perhaps this will fix some cases?
1 Comment
Tim Lueth
on 8 Jun 2022
I have tried this. Unfortunately, it did not help to fix the spindump/sandbox problem on 2021b and OSX10.16.
Since I use Matlab on an Apple Mac every week in lectures, I was tired of having this problem several times each week in front of hundreds of students! There is no warning but Matlab slows down and slows down and finally "stands" without error message. Especially for functions or scripts that run for several seconds or minutes, detection is very difficult, time wasting and switching to the terminal program and entering the superuser password is unprofessional.
The solution works in four steps:
1st: Find the PID number of the sandbox process and the spindump process
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
% [a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/libexec/sandboxd','IgnoreCase',true)), e=split(d);
% if ~isempty(e); PID2=e{2}; else PID2=[]; end;
2nd: Kill the process as super user using your private sudo password in the command line. YOU HAVE TO EXCHANGE <yoursudopassword> by your own password without the <> chars.
if ~isempty(PID1); system(sprintf('echo <yoursudopassword> | sudo -S kill -9 %s',PID1)); end;
3rd: Write a loop that checks every second whether the process exists (and uses more that 1% of CPU time)
function spindumpkill
while true
pause(1);
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <yoursudopassword> | sudo -S kill -9 %s',PID1)); end;
end
4th: Start this function as batch process in the background (using the parallel box) or create an OSX-App for that.
batch spindumpkill
9 Comments
Farrastaqy Esmuzati
on 31 Jan 2023
Edited: Farrastaqy Esmuzati
on 31 Jan 2023
Hello, I'm undergrad EE student from Indonesia currently studying in Malaysia.
I'd like to ask, I think I have the same problem, and that I'm using macOS Monterey 12.6.3 and MATLAB r2022b. My problem occurs and MATLAB freezes when I tried closing a figure window by pressing the "x" button, but for this when I expand pressing the green button then close with the same "x" button it seems ok. However, the same problem also occurs when I use scope within simulink when I simulate a simscape electrical model, so far there's no particular pattern that I could find regarding why this happens, it seems just after several minutes (or seconds in some instance) after running the simulation it freezes, I do not know if other model and using the scope will freeze as well.
I previously used r2021b, but the .slx file model provided by our lecturer cannot open it since it is made using newer version of r2022a. Please if you would be so kind as to help assist a bit on your provided solution -- does it mean I have to make an app with the code you provided? I asked chatGPT, it seems your code is a MATLAB code so does it mean in that case I have to put it in script and run everytime I run MATLAB? please elaborate more.
Also, I have not updated to macOS 13.x Ventura, but if it would fix then I would upgrade. Downgrading macOS is kinda not an option, since I will need to erase everything, and I don't have time for another problems with a different complexity, and the assignment due is kinda in 2 days. Using r2022a might be an option, if it makes it more stable, I have been installing MATLAB dozens time for the past few days.
Your help will be appreciative, after this I think it's either I will not macOS as the main OS I use next laptop I'd buy, or maybe just use Open Source programs and that I'll be finishing my degree soon inshallah anyway, and I would lose access to MATLAB/Mathworks anyway.
Joao Nizer
on 31 Jan 2023
Farrastaqy Esmuzati
on 31 Jan 2023
@Tim Lueth, can you really explain step 1 through 4, I do not understand most of it such as "..batch process in the backgroud..", I have already installed the Parallel Computing Toolbox.
Farrastaqy Esmuzati
on 31 Jan 2023
@Joao Nizer I tried using your solution of making .app in the automator, and wrote the line below:
cd /Applications/MATLAB_R2022b.app/bin
open matlab
And I deleted "cat" in the Run Shell Script, while the Shell is /bin/bash, and Pass input is: to stdin

macOS Monterey 12.6.3
r2022b
it did not work, still froze when I use scope in Simscape Electrical Simulink
Farrastaqy Esmuzati
on 31 Jan 2023
if @Tim Lueth or you @Joao Nizer, or anyone could explain step 1-4 by @Tim Lueth solution. Please let me know, thank you
Walter Roberson
on 31 Jan 2023
"4th: Start this function as batch process in the background (using the parallel box) or create an OSX-App for that."
That includes several possibilities:
- If you have Parallel Computing Toolbox, you can run the function using batch
- If you have Parallel Computing Toolbox, you can run the function using parfeval
- You cannot, however, using parfeval() with backgroundPool for this situation, as system is not supported inside thread-based workers
- you can run the function in a separate MATLAB session. You can use the dock icon to "Open Additional Instance of MATLAB" and run the function there
- you could get even fancier and code a MacOS level daemon https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html ... but if you were going to go to that trouble it would probably be better to recode as shell script (much much less memory)
Farrastaqy Esmuzati
on 31 Jan 2023
@Walter Roberson, so here is what I did. And I also have Parallel Computing Toolbox
I copied the code into the function:
function spindumpkill
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <my password> | sudo -S kill -9 %s',PID1)); end;
while true
pause(1);
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <my password> | sudo -S kill -9 %s',PID1)); end;
end
and I saved the file in .m format in the path, with the same name as the function:
/Users/<computer username>/Documents/MATLAB/spindumpkill.m
Then I run, in the command window:

I don't know why but the "ID kept increasing" each time I run
I also attached the .m file, however it's renamed "spindumpkill_copy.m" but I run the "spindumpkill.m" one.
It's not fixed yet, when I run Simscape Electrical Simulink then I double-click the "scope", it still freezes after couple of seconds.
I also tried putting the 1st and 2nd step in different line and put it under the "while" loop like this:
function spindumpkill
while true
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <my password> | sudo -S kill -9 %s',PID1)); end;
pause(1);
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <my password> | sudo -S kill -9 %s',PID1)); end;
end
It still freezes.
Should I just upgrade to macOS 13.x Ventura, but I'm afraid it won't be reversible, if I needed to revert back to Monterey.
Walter Roberson
on 31 Jan 2023
The ID number for batch() is tracking which batch session request this is. Because batch are designed to have the results stay around until collected, the ID number increments for each new batch() request and ID numbers are not reused until you go in and remove the appropriate file that the number is being recorded into. It will not normally reset between sessions, as it is expected that you might drop out of MATLAB and return later to find out how the batch sessions are going.
Walter Roberson
on 31 Jan 2023
You could potentially create a new APFS volume and install Ventura into it; https://support.apple.com/en-ca/guide/disk-utility/dskutl14027/mac
Categories
Find more on Internationalization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!