# Safe-mode

**URL:** <https://community.wolfram.com/t/safe-mode/567>\
**Category:** Questions\
**Tags:** software-development, mathematica\
**Created:** [September 18, 2013, 9:08am UTC](https://community.wolfram.com/t/safe-mode/567 "2013-09-18T09:08:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zdenek](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zdenek](https://community.wolfram.com/u/zdenek)\
**Post date:** [September 18, 2013, 9:08am UTC](https://community.wolfram.com/t/safe-mode/567/1 "2013-09-18T09:08:42Z")

</div>

HI,  
is there something like “safe-mode” in Mathematica. I would like to run and automatically test several projects (students work) and I would like to disable all low-level functions accessing the file system and operating system. (Something like: “math --safe-mode -script myProgram.m”)

One solution could be (I probably missed some functions):

```auto
ClearAttributes[{Run, RunThrough, CopyFile, DeleteFile, RenameFile, 
  CreateDirectory, CopyDirectory, DeleteDirectory, RenameDirectory, 
  OpenRead, OpenWrite, Read, Write, BinaryRead, 
  BinaryWrite}, Protected]
Run[___] := $Failed;
RunThrough[___] := $Failed;
CopyFile[___] := $Failed;
DeleteFile[___] := $Failed;
RenameFile[___] := $Failed;
CreateDirectory[___] := $Failed;
CopyDirectory[___] := $Failed;
DeleteDirectory[___] := $Failed;
RenameDirectory[___] := $Failed;
OpenRead[___] := $Failed;
OpenWrite[___] := $Failed;
Read[___] := $Failed;
Write[___] := $Failed;
BinaryRead[___] := $Failed;
BinaryWrite[___] := $Failed;
SetAttributes[{Run, RunThrough, CopyFile, DeleteFile, RenameFile, 
  CreateDirectory, CopyDirectory, DeleteDirectory, RenameDirectory, 
  OpenRead, OpenWrite, Read, Write, BinaryRead, 
  BinaryWrite}, Protected]

```

Any ideas?

Zdenek

---

<div class="post-metadata">

**Author:** ![ruler58585](https://avatars.discourse-cdn.com/v4/letter/r/f6c823/32.png) [@ruler58585](https://community.wolfram.com/u/ruler58585)\
**Post date:** [September 18, 2013, 7:41pm UTC](https://community.wolfram.com/t/safe-mode/567/2 "2013-09-18T19:41:43Z")

</div>

If this is purely to prevent students from messing with your computer you could always run mathmatica itself on a virtual operating system~linux or something to make it incredibly difficult for them to access anything.

---

<div class="post-metadata">

**Author:** ![zdenek](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zdenek](https://community.wolfram.com/u/zdenek)\
**Post date:** [September 25, 2013, 11:07am UTC](https://community.wolfram.com/t/safe-mode/567/3 "2013-09-25T11:07:19Z")

</div>

It is for automatic tested homeworks. Each student will push his homework into git repository and it is automatically tested by bash script+Mathematica. In your solution I will need to create new VM image (beacuse the old one may be corrupted from previous run) for each student’s push.

---

<div class="post-metadata">

**Author:** ![luc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/luc/32/19500_2.png) [@luc](https://community.wolfram.com/u/luc)\
**Post date:** [September 25, 2013, 3:56pm UTC](https://community.wolfram.com/t/safe-mode/567/4 "2013-09-25T15:56:53Z")

</div>

one way is to keep the expression of the student in a “Hold” or “HoldComplete” and then look for any of those function in the expression.  
you can that way make a “secure” version of ToExpression.  
If notebooks I meant to be run completely, there is all you need in the language to easily extract the input cells in a single line like:

```auto
Cases[NotebookGet[nb],Cell[content_,"Input",opt1 __,CellTags->tag,opt2___]:>ToSecureExpression[content],Infinity,1];

```

I hope this helps.
