1mNAME0m
       interp - Create and manipulate Tcl interpreters

1mSYNOPSIS0m
       1minterp 4m22moption24m ?4marg24m 4marg24m 4m...24m?


1mDESCRIPTION0m
       This  command  makes  it  possible to create one or more new Tcl inter-
       preters that co-exist with the creating interpreter in the same  appli-
       cation.   The  creating  interpreter  is  called the 4mmaster24m and the new
       interpreter is called a 4mslave24m.  A  master  can  create  any  number  of
       slaves, and each slave can itself create additional slaves for which it
       is master, resulting in a hierarchy of interpreters.

       Each interpreter is independent from the others: it has  its  own  name
       space  for commands, procedures, and global variables.  A master inter-
       preter may create connections between its slaves  and  itself  using  a
       mechanism  called  an  4malias24m.   An 4malias24m is a command in a slave inter-
       preter which, when invoked, causes a command to be invoked in its  mas-
       ter  interpreter  or in another slave interpreter.  The only other con-
       nections between interpreters are through  environment  variables  (the
       1menv  22mvariable), which are normally shared among all interpreters in the
       application. Note that the name space for  files  (such  as  the  names
       returned by the 1mopen 22mcommand) is no longer shared between interpreters.
       Explicit commands are provided to share files and  to  transfer  refer-
       ences to open files from one interpreter to another.

       The 1minterp 22mcommand also provides support for 4msafe24m interpreters.  A safe
       interpreter is a slave whose functions have been greatly restricted, so
       that  it is safe to execute untrusted scripts without fear of them dam-
       aging other interpreters or the application's environment. For example,
       all  IO  channel creation commands and subprocess creation commands are
       made inaccessible to safe interpreters.  See  1mSAFE  INTERPRETERS  22mbelow
       for  more  information  on  what  features are present in a safe inter-
       preter.  The dangerous functionality  is  not  removed  from  the  safe
       interpreter;  instead,  it is 4mhidden24m, so that only trusted interpreters
       can obtain access to it. For a detailed explanation of hidden commands,
       see  1mHIDDEN  COMMANDS22m, below.  The alias mechanism can be used for pro-
       tected communication (analogous to  a  kernel  call)  between  a  slave
       interpreter  and  its  master.   See  1mALIAS INVOCATION22m, below, for more
       details on how the alias mechanism works.

       A qualified interpreter name is a proper Tcl lists containing a  subset
       of its ancestors in the interpreter hierarchy, terminated by the string
       naming the interpreter in its immediate master. Interpreter  names  are
       relative  to  the interpreter in which they are used. For example, if 1ma0m
       is a slave of the current interpreter and it has a slave 1ma122m,  which  in
       turn  has  a  slave  1ma1122m, the qualified name of 1ma11 22min 1ma 22mis the list 1ma10m
       1ma1122m.

       The 1minterp 22mcommand,  described  below,  accepts  qualified  interpreter
       names as arguments; the interpreter in which the command is being eval-
       uated can always be referred to as 1m{} 22m(the empty list or string).  Note
       that  it  is  impossible to refer to a master (ancestor) interpreter by
       name in a slave interpreter except through aliases. Also, there  is  no
       global  name by which one can refer to the first interpreter created in
       an application.  Both restrictions are motivated by safety concerns.

1mTHE INTERP COMMAND0m
       The 1minterp 22mcommand is used to  create,  delete,  and  manipulate  slave
       interpreters,  and  to share or transfer channels between interpreters.
       It can have any of several forms, depending on the 4moption24m argument:

       1minterp alias 4m22msrcPath24m 4msrcToken0m
              Returns a Tcl list whose elements are  the  4mtargetCmd24m  and  4marg24ms
              associated  with  the alias represented by 4msrcToken24m (this is the
              value returned when the alias was created; it is  possible  that
              the  name  of  the source command in the slave is different from
              4msrcToken24m).

       1minterp alias 4m22msrcPath24m 4msrcToken24m 1m{}0m
              Deletes the alias for 4msrcToken24m in the slave interpreter  identi-
              fied by 4msrcPath24m.  4msrcToken24m refers to the value returned when the
              alias was created;  if the source command has been renamed,  the
              renamed command will be deleted.

       1minterp alias 4m22msrcPath24m 4msrcCmd24m 4mtargetPath24m 4mtargetCmd24m ?4marg24m 4marg24m 4m...24m?
              This command creates an alias between one slave and another (see
              the 1malias 22mslave command below for  creating  aliases  between  a
              slave  and  its  master).   In this command, either of the slave
              interpreters may be anywhere in the  hierarchy  of  interpreters
              under  the interpreter invoking the command.  4mSrcPath24m and 4msrcCmd0m
              identify the source of the alias.  4mSrcPath24m is a Tcl  list  whose
              elements  select a particular interpreter.  For example, ``1ma b22m''
              identifies an interpreter 1mb22m, which is a slave of interpreter  1ma22m,
              which  is  a  slave  of the invoking interpreter.  An empty list
              specifies the interpreter invoking the  command.   4msrcCmd24m  gives
              the  name  of a new command, which will be created in the source
              interpreter.  4mTargetPath24m and 4mtargetCmd24m specify a  target  inter-
              preter and command, and the 4marg24m arguments, if any, specify addi-
              tional arguments to 4mtargetCmd24m which are prepended to  any  argu-
              ments  specified  in the invocation of 4msrcCmd24m.  4mTargetCmd24m may be
              undefined at the time of this call, or it may already exist;  it
              is  not  created  by  this  command.  The alias arranges for the
              given target command to be invoked  in  the  target  interpreter
              whenever  the  given  source  command  is  invoked in the source
              interpreter.  See 1mALIAS INVOCATION 22mbelow for more details.   The
              command  returns  a  token  that uniquely identifies the command
              created 4msrcCmd24m, even if the command is renamed  afterwards.  The
              token may but does not have to be equal to 4msrcCmd24m.

       1minterp aliases 22m?4mpath24m?
              This  command returns a Tcl list of the tokens of all the source
              commands for aliases defined in the  interpreter  identified  by
              4mpath24m.  The  tokens  correspond  to  the values returned when the
              aliases were created (which may not be the same as  the  current
              names of the commands).

       1minterp create 22m?1m-safe22m? ?1m--22m? ?4mpath24m?
              Creates  a  slave  interpreter identified by 4mpath24m and a new com-
              mand, called a 4mslave24m 4mcommand24m. The name of the slave  command  is
              the  last  component  of 4mpath24m. The new slave interpreter and the
              slave command are created in the interpreter identified  by  the
              path  obtained  by  removing  the  last component from 4mpath24m. For
              example, if 4mpath24m 4mis24m 1ma b c 22mthen a new slave interpreter and slave
              command named 1mc 22mare created in the interpreter identified by the
              path 1ma b22m.  The slave command may be used to manipulate  the  new
              interpreter  as described below. If 4mpath24m is omitted, Tcl creates
              a unique name of the form 1minterp4m22mx24m, where 4mx24m is  an  integer,  and
              uses  it for the interpreter and the slave command. If the 1m-safe0m
              switch is specified (or if the  master  interpreter  is  a  safe
              interpreter),  the  new  slave  interpreter will be created as a
              safe interpreter with limited functionality; otherwise the slave
              will  include  the  full  set of Tcl built-in commands and vari-
              ables. The 1m-- 22mswitch can be used to mark the  end  of  switches;
              it  may be needed if 4mpath24m is an unusual value such as 1m-safe22m. The
              result of the command is the name of the  new  interpreter.  The
              name  of a slave interpreter must be unique among all the slaves
              for its master;  an error occurs if a slave interpreter  by  the
              given name already exists in this master.  The initial recursion
              limit of the slave interpreter is set to the  current  recursion
              limit of its parent interpreter.

       1minterp delete 22m?4mpath24m 4m...?0m
              Deletes  zero  or  more  interpreters given by the optional 4mpath0m
              arguments, and for each interpreter, it also deletes its slaves.
              The  command also deletes the slave command for each interpreter
              deleted.  For each 4mpath24m argument, if no interpreter by that name
              exists, the command raises an error.

       1minterp eval 4m22mpath24m 4marg24m ?4marg24m 4m...24m?
              This  command  concatenates all of the 4marg24m arguments in the same
              fashion as the 1mconcat  22mcommand,  then  evaluates  the  resulting
              string  as  a  Tcl script in the slave interpreter identified by
              4mpath24m. The result of this evaluation (including error information
              such  as  the  1merrorInfo  22mand  1merrorCode  22mvariables, if an error
              occurs) is returned to the invoking interpreter.  Note that  the
              script  will  be  executed in the current context stack frame of
              the 4mpath24m interpreter; this is so that the implementations (in  a
              master  interpreter)  of aliases in a slave interpreter can exe-
              cute scripts in the slave that find out  information  about  the
              slave's current state and stack frame.

       1minterp exists 4m22mpath0m
              Returns   1m1  22mif a slave interpreter by the specified 4mpath24m exists
              in this master, 1m0 22motherwise. If 4mpath24m is  omitted,  the  invoking
              interpreter is used.

       1minterp expose 4m22mpath24m 4mhiddenName24m ?4mexposedCmdName24m?
              Makes the hidden command 4mhiddenName24m exposed, eventually bringing
              it back under a new 4mexposedCmdName24m name (this name is  currently
              accepted  only  if  it is a valid global name space name without
              any ::), in the interpreter denoted by 4mpath24m.  If an exposed com-
              mand  with the targeted name already exists, this command fails.
              Hidden commands are explained in more detail in 1mHIDDEN COMMANDS22m,
              below.

       1minterp hide 4m22mpath24m 4mexposedCmdName24m ?4mhiddenCmdName24m?
              Makes  the exposed command 4mexposedCmdName24m hidden, renaming it to
              the hidden command 4mhiddenCmdName24m, or keeping the  same  name  if
              4mhiddenCmdName24m  is not given, in the interpreter denoted by 4mpath24m.
              If a hidden command with the targeted name already exists,  this
              command  fails.  Currently both 4mexposedCmdName24m and 4mhiddenCmdName0m
              can not contain namespace qualifiers, or  an  error  is  raised.
              Commands to be hidden by 1minterp hide 22mare looked up in the global
              namespace even if the current namespace is not the  global  one.
              This prevents slaves from fooling a master interpreter into hid-
              ing the wrong command, by making the current namespace  be  dif-
              ferent  from  the  global one.  Hidden commands are explained in
              more detail in 1mHIDDEN COMMANDS22m, below.

       1minterp hidden 4m22mpath0m
              Returns a list of the names of all hidden commands in the inter-
              preter identified by 4mpath24m.

       1minterp invokehidden 4m22mpath24m ?1m-global22m? 4mhiddenCmdName24m ?4marg24m 4m...24m?
              Invokes the hidden command 4mhiddenCmdName24m with the arguments sup-
              plied in the interpreter denoted by 4mpath24m.  No  substitutions  or
              evaluation are applied to the arguments.  If the 1m-global 22mflag is
              present, the hidden command is invoked at the  global  level  in
              the  target  interpreter; otherwise it is invoked at the current
              call frame and can access local variables in that and outer call
              frames.   Hidden commands are explained in more detail in 1mHIDDEN0m
              1mCOMMANDS22m, below.

       1minterp issafe 22m?4mpath24m?
              Returns 1m1 22mif the interpreter identified by the specified 4mpath24m is
              safe, 1m0 22motherwise.

       1minterp marktrusted 4m22mpath0m
              Marks  the  interpreter  identified by 4mpath24m as trusted. Does not
              expose the hidden commands. This command  can  only  be  invoked
              from  a  trusted  interpreter.  The command has no effect if the
              interpreter identified by 4mpath24m is already trusted.

       1minterp recursionlimit 4m22mpath24m ?4mnewlimit24m?
              Returns the maximum allowable nesting depth for the  interpreter
              specified  by  4mpath24m.   If 4mnewlimit24m is specified, the interpreter
              recursion limit will  be  set  so  that  nesting  of  more  than
              4mnewlimit24m  calls  to  1mTcl_Eval()  22mand  related procedures in that
              interpreter will return an error.  The 4mnewlimit24m  value  is  also
              returned.  The 4mnewlimit24m value must be a positive integer between
              1 and the maximum value of a non-long integer on the platform.

              The command sets the maximum size of the Tcl call stack only. It
              cannot  by  itself  prevent stack overflows on the C stack being
              used by the application. If your machine has a limit on the size
              of  the C stack, you may get stack overflows before reaching the
              limit set by the command. If this happens, see  if  there  is  a
              mechanism  in your system for increasing the maximum size of the
              C stack.

       1minterp share 4m22msrcPath24m 4mchannelId24m 4mdestPath0m
              Causes the IO channel identified by 4mchannelId24m to  become  shared
              between  the  interpreter  identified  by 4msrcPath24m and the inter-
              preter identified by 4mdestPath24m. Both interpreters have  the  same
              permissions  on the IO channel.  Both interpreters must close it
              to close the underlying IO channel; IO channels accessible in an
              interpreter  are  automatically  closed  when  an interpreter is
              destroyed.

       1minterp slaves 22m?4mpath24m?
              Returns a Tcl list of the names of all  the  slave  interpreters
              associated  with  the interpreter identified by 4mpath24m. If 4mpath24m is
              omitted, the invoking interpreter is used.

       1minterp target 4m22mpath24m 4malias0m
              Returns a Tcl list describing  the  target  interpreter  for  an
              alias.  The  alias  is  specified  with  an interpreter path and
              source command name, just as in 1minterp alias 22mabove. The name  of
              the target interpreter is returned as an interpreter path, rela-
              tive to the invoking interpreter.  If the target interpreter for
              the  alias  is  the  invoking  interpreter then an empty list is
              returned. If the target interpreter for the  alias  is  not  the
              invoking  interpreter or one of its descendants then an error is
              generated.  The target command does not have to  be  defined  at
              the time of this invocation.

       1minterp transfer 4m22msrcPath24m 4mchannelId24m 4mdestPath0m
              Causes  the  IO channel identified by 4mchannelId24m to become avail-
              able in the interpreter identified by 4mdestPath24m  and  unavailable
              in the interpreter identified by 4msrcPath24m.

1mSLAVE COMMAND0m
       For  each  slave interpreter created with the 1minterp 22mcommand, a new Tcl
       command is created in the master interpreter with the same name as  the
       new  interpreter. This command may be used to invoke various operations
       on the interpreter.  It has the following general form:
              4mslave24m 4mcommand24m ?4marg24m 4marg24m 4m...24m?
       4mSlave24m is the name of the interpreter, and 4mcommand24m and the  4marg24ms  deter-
       mine  the  exact behavior of the command.  The valid forms of this com-
       mand are:

       4mslave24m 1maliases0m
              Returns a Tcl list whose elements are  the  tokens  of  all  the
              aliases  in 4mslave24m.  The tokens correspond to the values returned
              when the aliases were created (which may not be the same as  the
              current names of the commands).

       4mslave24m 1malias 4m22msrcToken0m
              Returns  a  Tcl  list  whose elements are the 4mtargetCmd24m and 4marg24ms
              associated with the alias represented by 4msrcToken24m (this  is  the
              value  returned  when the alias was created; it is possible that
              the actual source command in the slave is different from  4msrcTo-0m
              4mken24m).

       4mslave24m 1malias 4m22msrcToken24m 1m{}0m
              Deletes the alias for 4msrcToken24m in the slave interpreter.  4msrcTo-0m
              4mken24m refers to the value returned when the alias was created;  if
              the source command has been renamed, the renamed command will be
              deleted.

       4mslave24m 1malias 4m22msrcCmd24m 4mtargetCmd24m ?4marg24m 4m..24m?
              Creates an alias such that whenever 4msrcCmd24m is invoked in  4mslave24m,
              4mtargetCmd24m  is  invoked in the master.  The 4marg24m arguments will be
              passed to 4mtargetCmd24m as additional  arguments,  prepended  before
              any  arguments  passed  in  the invocation of 4msrcCmd24m.  See 1mALIAS0m
              1mINVOCATION 22mbelow for details.  The command returns a token  that
              uniquely identifies the command created 4msrcCmd24m, even if the com-
              mand is renamed afterwards. The token may but does not  have  to
              be equal to 4msrcCmd24m.

       4mslave24m 1meval 4m22marg24m ?4marg24m 4m..24m?
              This  command  concatenates all of the 4marg24m arguments in the same
              fashion as the 1mconcat  22mcommand,  then  evaluates  the  resulting
              string  as a Tcl script in 4mslave24m.  The result of this evaluation
              (including error information such as the 1merrorInfo 22mand 1merrorCode0m
              variables,  if  an  error  occurs)  is  returned to the invoking
              interpreter.  Note that the script will be executed in the  cur-
              rent context stack frame of 4mslave24m; this is so that the implemen-
              tations (in a master interpreter) of aliases in a  slave  inter-
              preter  can  execute scripts in the slave that find out informa-
              tion about the slave's current state and stack frame.

       4mslave24m 1mexpose 4m22mhiddenName24m ?4mexposedCmdName24m?
              This command exposes the hidden command  4mhiddenName24m,  eventually
              bringing  it  back under a new 4mexposedCmdName24m name (this name is
              currently accepted only if it is a valid global name space  name
              without  any ::), in 4mslave24m.  If an exposed command with the tar-
              geted name already exists, this command fails.  For more details
              on hidden commands, see 1mHIDDEN COMMANDS22m, below.

       4mslave24m 1mhide 4m22mexposedCmdName24m ?4mhiddenCmdName24m?
              This  command hides the exposed command 4mexposedCmdName24m, renaming
              it to the hidden command 4mhiddenCmdName24m, or keeping the same name
              if  the  argument  is not given, in the 4mslave24m interpreter.  If a
              hidden command with the targeted name already exists, this  com-
              mand fails.  Currently both 4mexposedCmdName24m and 4mhiddenCmdName24m can
              not contain namespace qualifiers, or an error is  raised.   Com-
              mands to be hidden are looked up in the global namespace even if
              the current namespace is  not  the  global  one.  This  prevents
              slaves  from  fooling a master interpreter into hiding the wrong
              command, by making the current namespace be different  from  the
              global  one.   For  more  details on hidden commands, see 1mHIDDEN0m
              1mCOMMANDS22m, below.

       4mslave24m 1mhidden0m
              Returns a list of the names of all hidden commands in 4mslave24m.

       4mslave24m 1minvokehidden 22m?1m-global 4m22mhiddenName24m ?4marg24m 4m..24m?
              This command invokes the hidden command 4mhiddenName24m with the sup-
              plied  arguments,  in 4mslave24m. No substitutions or evaluations are
              applied to the arguments.  If the 1m-global  22mflag  is  given,  the
              command  is  invoked at the global level in the slave; otherwise
              it is invoked at the current call frame  and  can  access  local
              variables  in  that  or  outer call frames.  For more details on
              hidden commands, see 1mHIDDEN COMMANDS22m, below.

       4mslave24m 1missafe0m
              Returns  1m1 22mif the slave interpreter is safe, 1m0 22motherwise.

       4mslave24m 1mmarktrusted0m
              Marks the slave interpreter as trusted. Can only be invoked by a
              trusted  interpreter.  This  command  does not expose any hidden
              commands in the slave interpreter. The command has no effect  if
              the slave is already trusted.

       4mslave24m 1mrecursionlimit 22m?4mnewlimit24m?
              Returns the maximum allowable nesting depth for the 4mslave24m inter-
              preter.  If 4mnewlimit24m is specified, the recursion limit in  4mslave0m
              will  be  set  so  that  nesting  of more than 4mnewlimit24m calls to
              1mTcl_Eval() 22mand related procedures in 4mslave24m will return an error.
              The 4mnewlimit24m value is also returned.  The 4mnewlimit24m value must be
              a positive integer between 1 and the maximum value of a non-long
              integer on the platform.

              The command sets the maximum size of the Tcl call stack only. It
              cannot by itself prevent stack overflows on the  C  stack  being
              used by the application. If your machine has a limit on the size
              of the C stack, you may get stack overflows before reaching  the
              limit  set  by  the  command. If this happens, see if there is a
              mechanism in your system for increasing the maximum size of  the
              C stack.

1mSAFE INTERPRETERS0m
       A  safe  interpreter  is  one with restricted functionality, so that is
       safe to execute an arbitrary script from your worst enemy without  fear
       of  that  script damaging the enclosing application or the rest of your
       computing environment.  In order to make an interpreter  safe,  certain
       commands  and variables are removed from the interpreter.  For example,
       commands to create files on disk are removed, and the 1mexec  22mcommand  is
       removed,  since  it could be used to cause damage through subprocesses.
       Limited access to these facilities can be provided, by creating aliases
       to  the  master  interpreter  which check their arguments carefully and
       provide restricted access to a safe subset of facilities.  For example,
       file creation might be allowed in a particular subdirectory and subpro-
       cess invocation might be allowed for a carefully selected and fixed set
       of programs.

       A  safe  interpreter  is  created by specifying the 1m-safe 22mswitch to the
       1minterp create 22mcommand.  Furthermore, any slave created by a safe inter-
       preter will also be safe.

       A  safe interpreter is created with exactly the following set of built-
       in commands:

              1mafter       append      array       binary0m
              1mbreak       case        catch       clock0m
              1mclose       concat      continue    eof0m
              1merror       eval        expr        fblocked0m
              1mfcopy       fileevent   flush       for0m
              1mforeach     format      gets        global0m
              1mif          incr        info        interp0m
              1mjoin        lappend     lindex      linsert0m
              1mlist        llength     lrange      lreplace0m
              1mlsearch     lsort       namespace   package0m
              1mpid         proc        puts        read0m
              1mregexp      regsub      rename      return0m
              1mscan        seek        set         split0m
              1mstring      subst       switch      tell0m
              1mtime        trace       unset       update0m
              1muplevel     upvar       variable    vwait0m
              1mwhile0m

       The following commands are hidden by 1minterp create 22mwhen  it  creates  a
       safe interpreter:

              1mcd          encoding    exec        exit0m
              1mfconfigure  file        glob        load0m
              1mopen        pwd         socket      source0m

       These  commands can be recreated later as Tcl procedures or aliases, or
       re-exposed by 1minterp expose22m.

       The following commands from Tcl's library of support procedures are not
       present in a safe interpreter:

              1mauto_exec_ok    auto_import     auto_load0m
              1mauto_load_index auto_qualify    unknown0m

       Note  in particular that safe interpreters have no default 1munknown 22mcom-
       mand, so  Tcl's  default  autoloading  facilities  are  not  available.
       Autoload access to Tcl's commands that are normally autoloaded:


              1mauto_mkindex         auto_mkindex_old0m
              1mauto_reset           history0m
              1mparray               pkg_mkIndex0m
              1m::pkg::create        ::safe::interpAddToAccessPath0m
              1m::safe::interpCreate ::safe::interpConfigure0m
              1m::safe::interpDelete ::safe::interpFindInAccessPath0m
              1m::safe::interpInit   ::safe::setLogCmd0m
              1mtcl_endOfWord        tcl_findLibrary0m
              1mtcl_startOfNextWord  tcl_startOfPreviousWord0m
              1mtcl_wordBreakAfter   tcl_wordBreakBefore0m

       can  only  be  provided by explicit definition of an 1munknown 22mcommand in
       the safe interpreter.  This will involve exposing the  1msource  22mcommand.
       This  is most easily accomplished by creating the safe interpreter with
       Tcl's 1mSafe-Tcl 22mmechanism.  1mSafe-Tcl 22mprovides safe versions  of  1msource22m,
       1mload22m,  and other Tcl commands needed to support autoloading of commands
       and the loading of packages.

       In addition, the 1menv 22mvariable is not present in a safe interpreter,  so
       it  cannot share environment variables with other interpreters. The 1menv0m
       variable poses a security  risk,  because  users  can  store  sensitive
       information  in  an  environment  variable. For example, the PGP manual
       recommends storing the PGP private key protection password in the envi-
       ronment  variable  4mPGPPASS24m. Making this variable available to untrusted
       code executing in a safe interpreter would incur a security risk.

       If extensions are  loaded  into  a  safe  interpreter,  they  may  also
       restrict  their  own  functionality to eliminate unsafe commands. For a
       discussion of management  of  extensions  for  safety  see  the  manual
       entries for 1mSafe-Tcl 22mand the 1mload 22mTcl command.

       A  safe  interpreter  may  not  alter the recursion limit of any inter-
       preter, including itself.

1mALIAS INVOCATION0m
       The alias mechanism has been carefully designed so that it can be  used
       safely  when  an  untrusted script is executing in a safe slave and the
       target of the alias is a trusted master.  The most important  thing  in
       guaranteeing safety is to ensure that information passed from the slave
       to the master is never evaluated or substituted in the master;  if this
       were  to  occur,  it would enable an evil script in the slave to invoke
       arbitrary functions in the master, which would compromise security.

       When the source for an alias is invoked in the slave  interpreter,  the
       usual Tcl substitutions are performed when parsing that command.  These
       substitutions are carried out in the source interpreter  just  as  they
       would  be  for any other command invoked in that interpreter.  The com-
       mand procedure for the source command takes its  arguments  and  merges
       them with the 4mtargetCmd24m and 4marg24ms for the alias to create a new array of
       arguments.  If the words of 4msrcCmd24m were ``4msrcCmd24m 4marg124m 4marg224m 4m...24m  4margN24m'',
       the  new set of words will be ``4mtargetCmd24m 4marg24m 4marg24m 4m...24m 4marg24m 4marg124m 4marg224m 4m...0m
       4margN24m'', where 4mtargetCmd24m and 4marg24ms are the values supplied when the alias
       was  created.   4mTargetCmd24m is then used to locate a command procedure in
       the target interpreter, and that command procedure is invoked with  the
       new  set  of  arguments.   An error occurs if there is no command named
       4mtargetCmd24m in the target interpreter.  No additional  substitutions  are
       performed  on  the  words:   the  target  command  procedure is invoked
       directly, without going through the normal  Tcl  evaluation  mechanism.
       Substitutions  are  thus performed on each word exactly once: 4mtargetCmd0m
       and 4margs24m were substituted when parsing the  command  that  created  the
       alias,  and 4marg124m 4m-24m 4margN24m are substituted when the alias's source command
       is parsed in the source interpreter.

       When writing the 4mtargetCmd24ms for aliases in  safe  interpreters,  it  is
       very important that the arguments to that command never be evaluated or
       substituted, since this would provide an escape mechanism  whereby  the
       slave  interpreter could execute arbitrary code in the master.  This in
       turn would compromise the security of the system.

1mHIDDEN COMMANDS0m
       Safe interpreters greatly restrict the functionality available  to  Tcl
       programs  executing within them.  Allowing the untrusted Tcl program to
       have direct access to this functionality is unsafe, because it  can  be
       used  for  a variety of attacks on the environment.  However, there are
       times when there is a legitimate need to use the dangerous  functional-
       ity  in  the  context of the safe interpreter. For example, sometimes a
       program must be 1msource22md into the interpreter.  Another example  is  Tk,
       where  windows  are  bound  to  the hierarchy of windows for a specific
       interpreter; some potentially dangerous functions, e.g.  window manage-
       ment,  must  be  performed on these windows within the interpreter con-
       text.

       The 1minterp 22mcommand provides a solution to this problem in the  form  of
       4mhidden24m  4mcommands24m.  Instead  of removing the dangerous commands entirely
       from a safe interpreter, these  commands  are  hidden  so  they  become
       unavailable  to Tcl scripts executing in the interpreter. However, such
       hidden commands can be invoked by any  trusted  ancestor  of  the  safe
       interpreter,  in  the  context  of  the  safe interpreter, using 1minterp0m
       1minvoke22m. Hidden commands and exposed commands reside  in  separate  name
       spaces.  It  is possible to define a hidden command and an exposed com-
       mand by the same name within one interpreter.

       Hidden commands in a slave interpreter can be invoked in  the  body  of
       procedures  called  in the master during alias invocation. For example,
       an alias for 1msource 22mcould be created in a slave interpreter. When it is
       invoked  in  the slave interpreter, a procedure is called in the master
       interpreter to check that the operation is allowable (e.g. it  asks  to
       source  a  file  that  the slave interpreter is allowed to access). The
       procedure then it invokes the hidden 1msource 22mcommand in the slave inter-
       preter  to  actually  source in the contents of the file. Note that two
       commands named 1msource 22mexist in the slave interpreter:  the  alias,  and
       the hidden command.

       Because  a  master  interpreter  may invoke a hidden command as part of
       handling an alias invocation, great care must be taken to avoid  evalu-
       ating any arguments passed in through the alias invocation.  Otherwise,
       malicious slave interpreters could cause a trusted  master  interpreter
       to execute dangerous commands on their behalf. See the section on 1mALIAS0m
       1mINVOCATION 22mfor a more complete discussion of this topic.  To help avoid
       this  problem, no substitutions or evaluations are applied to arguments
       of 1minterp invokehidden22m.

       Safe interpreters are not allowed to invoke hidden  commands  in  them-
       selves  or in their descendants. This prevents safe slaves from gaining
       access to hidden functionality in themselves or their descendants.

       The set of hidden commands in an interpreter can be  manipulated  by  a
       trusted  interpreter  using  1minterp  expose 22mand 1minterp hide22m. The 1minterp0m
       1mexpose 22mcommand moves a hidden command to the set of exposed commands in
       the interpreter identified by 4mpath24m, potentially renaming the command in
       the process. If an exposed command by the targeted name already exists,
       the operation fails. Similarly, 1minterp hide 22mmoves an exposed command to
       the set of hidden commands in that interpreter. Safe  interpreters  are
       not allowed to move commands between the set of hidden and exposed com-
       mands, in either themselves or their descendants.

       Currently, the names of hidden commands cannot contain namespace quali-
       fiers, and you must first rename a command in a namespace to the global
       namespace before you can hide it.  Commands to be hidden by 1minterp hide0m
       are  looked up in the global namespace even if the current namespace is
       not the global one. This prevents slaves from fooling a  master  inter-
       preter  into  hiding the wrong command, by making the current namespace
       be different from the global one.

1mCREDITS0m
       This mechanism is  based  on  the  Safe-Tcl  prototype  implemented  by
       Nathaniel Borenstein and Marshall Rose.

1mEXAMPLES0m
       Creating and using an alias for a command in the current interpreter:
              1minterp alias 22m{} getIndex {} lsearch {alpha beta gamma delta}
              set idx [getIndex delta]

       Executing  an  arbitrary  command  in  a  safe  interpreter where every
       invokation of 1mlappend 22mis logged:
              set i [1minterp create 22m-safe]
              1minterp hide 22m$i lappend
              1minterp alias 22m$i lappend {} loggedLappend $i
              proc loggedLappend {i args} {
                 puts "logged invokation of lappend $args"
                 # Be extremely careful about command construction
                 eval [linsert $args 0 \
                       1minterp invokehidden 22m$i lappend]
              }
              1minterp eval 22m$i $someUntrustedScript


1mSEE ALSO0m
       load(n), safe(n), Tcl_CreateSlave(3)


1mKEYWORDS0m
