Index: vim72/src/ex_docmd.c
===================================================================
--- vim72.orig/src/ex_docmd.c
+++ vim72/src/ex_docmd.c
@@ -2167,6 +2167,12 @@ do_one_cmd(cmdlinep, sourcing,
 	    goto doend;
 	}
 #endif
+    if (restricted != 0 && (ea.argt & EX_RESTRICT))
+	{
+	    errormsg = _("E981: Command not allowed in rvim");
+	    goto doend;
+	}
+
 	if (!curbuf->b_p_ma && (ea.argt & MODIFY))
 	{
 	    /* Command not allowed in non-'modifiable' buffer */
Index: vim72/src/ex_cmds.h
===================================================================
--- vim72.orig/src/ex_cmds.h
+++ vim72/src/ex_cmds.h
@@ -54,6 +54,7 @@
 #define CMDWIN	     0x100000L	/* allowed in cmdline window */
 #define MODIFY       0x200000L  /* forbidden in non-'modifiable' buffer */
 #define EXFLAGS      0x400000L	/* allow flags after count in argument */
+#define EX_RESTRICT  0x800000L   // forbidden in restricted mode
 #define FILES	(XFILE | EXTRA)	/* multiple extra files allowed */
 #define WORD1	(EXTRA | NOSPC)	/* one extra word allowed */
 #define FILE1	(FILES | NOSPC)	/* 1 file allowed, defaults to current file */
@@ -614,9 +615,9 @@ EX(CMD_mkview,		"mkview",	ex_mkrc,
 EX(CMD_mode,		"mode",		ex_mode,
 			WORD1|TRLBAR|CMDWIN),
 EX(CMD_mzscheme,	"mzscheme",	ex_mzscheme,
-			RANGE|EXTRA|DFLALL|NEEDARG|CMDWIN|SBOXOK),
+			RANGE|EXTRA|DFLALL|NEEDARG|CMDWIN|SBOXOK|EX_RESTRICT),
 EX(CMD_mzfile,		"mzfile",	ex_mzfile,
-			RANGE|FILE1|NEEDARG|CMDWIN),
+			RANGE|FILE1|NEEDARG|CMDWIN|EX_RESTRICT),
 EX(CMD_next,		"next",		ex_next,
 			RANGE|NOTADR|BANG|FILES|EDITCMD|ARGOPT|TRLBAR),
 EX(CMD_nbkey,		"nbkey",	ex_nbkey,
@@ -726,9 +727,9 @@ EX(CMD_put,		"put",		ex_put,
 EX(CMD_pwd,		"pwd",		ex_pwd,
 			TRLBAR|CMDWIN),
 EX(CMD_python,		"python",	ex_python,
-			RANGE|EXTRA|NEEDARG|CMDWIN),
+			RANGE|EXTRA|NEEDARG|CMDWIN|EX_RESTRICT),
 EX(CMD_pyfile,		"pyfile",	ex_pyfile,
-			RANGE|FILE1|NEEDARG|CMDWIN),
+			RANGE|FILE1|NEEDARG|CMDWIN|EX_RESTRICT),
 EX(CMD_quit,		"quit",		ex_quit,
 			BANG|TRLBAR|CMDWIN),
 EX(CMD_quitall,		"quitall",	ex_quit_all,
@@ -764,11 +765,11 @@ EX(CMD_rightbelow,	"rightbelow",	ex_wron
 EX(CMD_runtime,		"runtime",	ex_runtime,
 			BANG|NEEDARG|FILES|TRLBAR|SBOXOK|CMDWIN),
 EX(CMD_ruby,		"ruby",		ex_ruby,
-			RANGE|EXTRA|NEEDARG|CMDWIN),
+			RANGE|EXTRA|NEEDARG|CMDWIN|EX_RESTRICT),
 EX(CMD_rubydo,		"rubydo",	ex_rubydo,
-			RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN),
+			RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN|EX_RESTRICT),
 EX(CMD_rubyfile,	"rubyfile",	ex_rubyfile,
-			RANGE|FILE1|NEEDARG|CMDWIN),
+			RANGE|FILE1|NEEDARG|CMDWIN|EX_RESTRICT),
 EX(CMD_rviminfo,	"rviminfo",	ex_viminfo,
 			BANG|FILE1|TRLBAR|CMDWIN),
 EX(CMD_substitute,	"substitute",	do_sub,
@@ -942,11 +943,11 @@ EX(CMD_tabrewind,	"tabrewind",	ex_tabnex
 EX(CMD_tabs,		"tabs",		ex_tabs,
 			TRLBAR|CMDWIN),
 EX(CMD_tcl,		"tcl",		ex_tcl,
-			RANGE|EXTRA|NEEDARG|CMDWIN),
+			RANGE|EXTRA|NEEDARG|CMDWIN|EX_RESTRICT),
 EX(CMD_tcldo,		"tcldo",	ex_tcldo,
-			RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN),
+			RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN|EX_RESTRICT),
 EX(CMD_tclfile,		"tclfile",	ex_tclfile,
-			RANGE|FILE1|NEEDARG|CMDWIN),
+			RANGE|FILE1|NEEDARG|CMDWIN|EX_RESTRICT),
 EX(CMD_tearoff,		"tearoff",	ex_tearoff,
 			NEEDARG|EXTRA|TRLBAR|NOTRLCOM|CMDWIN),
 EX(CMD_tfirst,		"tfirst",	ex_tag,
Index: vim72/src/eval.c
===================================================================
--- vim72.orig/src/eval.c
+++ vim72/src/eval.c
@@ -9438,6 +9438,9 @@ f_eval(argvars, rettv)
 {
     char_u	*s;
 
+    if (check_restricted() || check_secure())
+        return;
+
     s = get_tv_string_chk(&argvars[0]);
     if (s != NULL)
 	s = skipwhite(s);
Index: vim72/src/if_perl.xs
===================================================================
--- vim72.orig/src/if_perl.xs
+++ vim72/src/if_perl.xs
@@ -670,6 +670,7 @@ VIM_init()
 #ifdef DYNAMIC_PERL
 static char *e_noperl = N_("Sorry, this command is disabled: the Perl library could not be loaded.");
 #endif
+static char *e_perlsandbox = N_("E299: Perl evaluation forbidden in sandbox without the Safe module");
 
 /*
  * ":perl"
@@ -717,11 +718,10 @@ ex_perl(eap)
 	vim_free(script);
     }
 
-#ifdef HAVE_SANDBOX
-    if (sandbox)
+    if (sandbox || secure)
     {
 	if ((safe = perl_get_sv( "VIM::safe", FALSE )) == NULL || !SvTRUE(safe))
-	    EMSG(_("E299: Perl evaluation forbidden in sandbox without the Safe module"));
+	    EMSG(_(e_perlsandbox));
 	else
 	{
 	    PUSHMARK(SP);
@@ -732,7 +732,7 @@ ex_perl(eap)
 	}
     }
     else
-#endif
+
 	perl_eval_sv(sv, G_DISCARD | G_NOARGS);
 
     SvREFCNT_dec(sv);

