Message Boards Message Boards

0
|
13945 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Safe-mode

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):
 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
POSTED BY: Zdenek Buk
3 Replies
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:
Cases[NotebookGet[nb],Cell[content_,"Input",opt1__,CellTags->tag,opt2___]:>ToSecureExpression[content],Infinity,1];

I hope this helps.
POSTED BY: Luc Barthelet
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.
POSTED BY: Zdenek Buk
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.
POSTED BY: Russell Hart
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract