# Where's the "Sandbox" then? Running commands

**URL:** https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717
**Category:** General
**Created:** [20 June 2025 11:45 UTC](https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717 "2025-06-20T11:45:01Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 June 2025 11:45 UTC](https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717/1 "2025-06-20T11:45:01Z")

</div>

I was just playing with `speedtest` and it was suggested I use a `Ubuntu` command `speedtest-cli`

I installed it and it is installed in `/usr/bin/`

And - surprisingly to me in some ways - it works when I put it in the `exec` node.

WHY?

I thought node-red was _sandboxed_ to it's directory and sub-folders.

Not super concerning, but just to help me learn.  
🙂

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [20 June 2025 12:43 UTC](https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717/2 "2025-06-20T12:43:19Z")

</div>

An exec node can do anything that the user running node red can do. The sandbox is for the function node.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [20 June 2025 15:40 UTC](https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717/3 "2025-06-20T15:40:10Z")

</div>

> [@Colin](#):
>
> The sandbox is for the function node.

Can you expand on this?  
This flow runs OS commands with execSync() in a function node.  
I don't think I have made any changes in settings.js to enable this.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e4ae67698328f40db8832e18483fab8aad106d3f.png)

```auto
[{"id":"f25f5b82ef69d0c5","type":"function","z":"24571e38fbe87e0f","name":"function 10","func":"try {\n msg.payload = childProcess.execSync(msg.payload).toString().trim();\n} catch (err) {\n // If there's an error, attach it to the message\n msg.payload = `Error executing command: ${err.message}`;\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"childProcess","module":"child_process"}],"x":670,"y":100,"wires":[["32aad220a2dded1f"]]},{"id":"f59cde23e2bc699e","type":"inject","z":"24571e38fbe87e0f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"whoami","payloadType":"str","x":510,"y":100,"wires":[["f25f5b82ef69d0c5"]]},{"id":"32aad220a2dded1f","type":"debug","z":"24571e38fbe87e0f","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":140,"wires":[]},{"id":"eecb5aa49634c09c","type":"inject","z":"24571e38fbe87e0f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"sudo whoami","payloadType":"str","x":490,"y":140,"wires":[["f25f5b82ef69d0c5"]]}]

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [20 June 2025 15:50 UTC](https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717/4 "2025-06-20T15:50:08Z")

</div>

It is sandboxed from the node process running node-red. It uses the [node VM](https://nodejs.org/api/vm.html)

if you use `process` `exec` or `spawn`, etc, you can still do things like access the system. That is why you should always use a service account with just the right amount of permissions to do what you want to let node-red do to your system.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [20 June 2025 15:55 UTC](https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717/5 "2025-06-20T15:55:34Z")

</div>

Thanks Steve.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [20 June 2025 16:16 UTC](https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717/6 "2025-06-20T16:16:12Z")

</div>

And it is also important to know the 'sandbox' the Function node runs code in is not a completely secure sandbox. It prevents casual access to things that shouldn't be accessed, but JavaScript provides many ways to circumvent it.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 June 2025 21:10 UTC](https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717/7 "2025-06-20T21:10:01Z")

</div>

Thanks all.

This came about because of what was mentioned in the first post.

So - to confirm I understand:  
NR can run any command _I_ can (non `root`).

Now to (sorry) digress....  
So where does the `public` directory configured in the settings fit in?

Is that the ..... _root_ directory for any file I/O?  
Though if it is the _root_: why is it I have to keep putting in the full path from **THE** root (top) directory?

eg:  
`/home/me/.node-red/public/(what ever)`  
and not just `(what ever)`?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [18 September 2025 21:10 UTC](https://discourse.nodered.org/t/wheres-the-sandbox-then-running-commands/97717/8 "2025-09-18T21:10:30Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
