Skip to main content

Safely serves multiple, isolated terminal sessions in a browser

Project description

runthis-server

RunThis Server is a tool for serving up unique, interactive terminal sessions over HTTP. This enables interactive demonstration pages and documentation for a variety of command-line applications.

Installation

RunThis-server may be installed with either conda or pip:

# use the conda-forge channel
$ conda install -c conda-forge runthis-server

# Or you can use Pip, if you must.
$ pip install runthis-server

Test Usage

You can start up the server with the runthis-server command line utility.

$ runthis-server --help
usage: runthis-server [-h] [--config CONFIG]

optional arguments:
  -h, --help       show this help message and exit
  --config CONFIG  Path to config file

Production Usage

For production, we recomment using hypercorn, as the server here is a Quart application. To use RunThis Server + hypercorn together, run the following command:

$ hypercorn runthis.server.hypercorn:app

Or if you need to run with HTTPS certificates:

$ hypercorn runthis.server.hypercorn:app \
    --certfile /pat/to/certs/fullchain.pem \
    --keyfile /path/to/certs/privkey.pem \
    --bind 0.0.0.0:80

Note: Currently there is no way to pass a path to a config file into the runthis server when running under hypercorn. The server will just look for a runthis-server.yml file in the current working directory and use that. If such a file does not exist, the default values will be used! Please change directory into the location of the runthis-server.yml file before running hypercorn.

Configuration

By default, the server is configured to run by looking for a runthis-server.yml file in the current working directory. You can pass in a specific configuration file with the --config flag.

All configuration variables are optional. The following lists there meaning and default values. Usually, these appear as top-level keys in the YAML file:

# The path to the public certificate file. This is currently only
# used by the hypercorn interface, and is passed directly though
# to hypercorn's configuration.
certfile: None

# The command variable is a string that lists ths command, or path
# to run whenever a new instance is requested. Nominally, this is
# a command that starts a REPL, but doesn't have to be.
command: "python3"

# The docker variable is a boolean that determines whether or not
# the command should be run in its own single-use docker container.
# Docker, of course, must be available on the host.
docker: true

# The docker_image varible specifies which docker image should be
# started up if the command is being run in a docker container.
docker_image: "ubuntu:latest"

# The host variable is the URL or IP address that the server is
# running on. By default, this is "127.0.0.1". Other valid options are
# "0.0.0.0", which will expose the server to the outside world, as well
# as any valid CNAME or IP address. RunThis Server works by taking in
# a request and then redirecting to a new port on this server. The selection
# of the host determines the redirection address. Here is the mapping:
#
#  host        -> TTY redirect_base
#  127.0.0.1   -> 0.0.0.0
#  0.0.0.0     -> IP address of server as seen by https://api.ipify.org
#  IP or CNAME -> Same IP or CNAME
host: "127.0.0.1"

# The path to the private certificate file. This is currently only
# used by the hypercorn interface, and is passed directly though
# to hypercorn's configuration.
certfile: None

# The port variable is an int that specifies the port number that the
# the RunThis Server itself operates on. The TTY redirects go to
# separate ports. Therefore you would access the RunThis Server as f"http://{host}:{port}"
port: 5000

# The tty_server variable is a string flag that represents the TTY server software that
# will be executed each time a request is made. Currently, the valid options are:
#
#  gotty: go-based TTY server https://github.com/yudai/gotty
#  ttyd: C++ TTY server https://tsl0922.github.io/ttyd/
tty_server: "gotty"

# The gotty_path is the path to the gotty executable
gotty_path: "gotty"

# The ttyd_path is the path to the ttyd executable
ttyd_path: "ttyd"

# The tty_server_port_start variable is an integer at which the TTY servers
# will start serving their terminals. Each successive request increases this
# value by one, so that each session recieves its own unique value.
tty_server_port_start: 8080

The above values may also be embedded into a top-level runthis key, if needed for compatibily with other files. For exmaple,

runthis:
    host: 0.0.0.0
    port: 80

Request Parameters

Requests of the server are be made to the URL f"http://{host}:{port}". However, this URL accepts either GET or POST requests and takes the following parameters as options.

presetup: This is code that the new interpreter session is initialized. It is executed without any notification to the user.

setup: This is code that is executed right when the interpreter starts up, after the presetup code is executed. Additionally, this code is echoed (printed in its source form) to the user prior to being execute. This is good for running examples.

For example, the following GET request would run import sys silently, and then execute print(sys.executable) after printing literally "print(sys.executable)".

http://127.0.0.1:5000/?presetup=import+sys&setup=print%28sys.executable%29

Usually, you should have a URL encoding library generate these URLs from source code for you.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runthis-server-0.0.4.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file runthis-server-0.0.4.tar.gz.

File metadata

  • Download URL: runthis-server-0.0.4.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200311 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for runthis-server-0.0.4.tar.gz
Algorithm Hash digest
SHA256 2db14707ae1c5a60f4798c51eb84546ba26220ac6897b3d4cb16607bbbbae1e5
MD5 e44c34f32b16e3ba0fc26eaca877b3a1
BLAKE2b-256 82cd1acf0876e639a3849b4f0eb2caf15d3e44594c4f4decdda8b01a605bf734

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page