Page
Library
Module
Module type
Parameter
Class
Class type
Source
BwrapSourceThis module launches processes isolated from the main environment using sandboxing technology.
Sandbox configuration.
You can create one using the functions below. Example: conf() |> mount "/usr".
Create a configuration with all sharing disabled, mounting in read-only mode /bin, /usr, /lib, /lib32 and /lib64 (if they exist) and on tmpfs /tmp, /run and /var. The hostname is set to "OCaml".
uid c id use a custom user id in the sandbox. Automatically implies share_user c false. If id < 0, unset it.
gid c id use a custom group id in the sandbox. Automatically implies share_user c false. If id < 0, unset it.
hostname c h use the custom hostname h in the sandbox. Automatically implies share_uts c false. If h = "", unset it.
setenv c var v add the variable var with value v to the environment of the process.
mount c src dest mount the host path src on dest in the sandbox. The mounts are applied in the order they are set, the latter ones being able undo what the previous ones did. Any missing parent directories that are required to create a specified destination are automatically created as needed.
Example: let c = mount c "/a" "/a" in mount c ~rw:true "/a/b" "/a/b"
remount_ro c dest remount the path dest as readonly. It works only on the specified mount point, without changing any other mount point under the specified path.
tmpfs c dest mount new tmpfs on dest. Example: tmpfs c "/var" or tmpfs c "/tmp".
symlink c src dest create a symlink at dest with target src.
chdir dir change directory to dir in the sandboxed environment.
new_session c b when b is true, create a new terminal session for the sandbox (calls setsid()). This disconnects the sandbox from the controlling terminal which means the sandbox can't for instance inject input into the terminal.
Note: In a general sandbox, if you don't use new_session c true, it is recommended to use seccomp to disallow the TIOCSTI ioctl, otherwise the application can feed keyboard input to the terminal.
die_with_parent c b: when b is true, ensures that the sandboxed command dies when the program using this library dies. Kills (SIGKILL) all sandbox processes in sequence from parent to child including the sandboxed command process when the process using this library dies.
open_process_in c cmd args runs the command cmd with arguments args in a sandbox in parallel with the program. The standard output of the program can be read on the returned channel.
open_process_out c cmd args runs the command cmd with arguments args in a sandbox in parallel with the program.
open_process c cmd args runs the command cmd with arguments args in a sandbox in parallel with the program.
val open_process_full :
conf ->
string ->
string list ->
in_channel * out_channel * in_channelopen_process_full c cmd args runs the command cmd with arguments args in a sandbox in parallel with the program. The result is a triple of channels connected respectively to the standard output, standard input, and standard error of the command.