## 4. Running student programs

The next sections of this tutorial will help you interfacing your test suite with INGInious.

In the Getting started section of this tutorial, you were asked to provide a small Python program printing Hello World! on standard output. The grading script was the following one:

#!/bin/bash

getinput "thecode" > student/student_code.py
output=$(python3 student/student_code.py) if [ "$output" = "Hello World!" ]; then
feedback-result success
else
feedback-result failed
feedback-msg -em "Your program displayed : $output" fi  ### Breaking the grading script The grading script shown above will execute the grading code and student-provided code in the same context. An alert student who knows how the INGInious API interact between the grading script and the submission manager may try to open several new processes to change its own result. For instance, this grading script is particularly sensible on the feedback-grade and feedback-msg API (discussed later). Try again mission 1. Getting started with this simple code and observe the result: import os print("Hello World!") os.system("feedback-msg -em 'You have made it.' ")  Moreover, students are also able to modify grading scripts that would not yet be loaded at the time their code is executed. One can easily conclude that a badly written grading script may leave the student with total control on how (s)he's graded, requiring the teaching staff to read manually all the submissions to detect fraud. ### The run_student API To ensure the student has no access to your grading scripts or the INGInious interface, a specific run_student API is provided. This tool is used to add a layer of isolation by spawning a process in a new container which possibly has overriden limitations and has only access to the student task subdirectory. This is known as the student container, in contrast to the grading container. #### Using the API The run_student API is a grading container-accessible shell command that takes as positional argument the shell command to launch inside the student container, as well as the following optional parameters:  --container CONTAINER Name of the environment to use. The default is the same as the current environment. --time TIMEOUT_VALUE Timeout (CPU time) for the container. The default is the same as the grading container. --hard-time TIMEOUT_VALUE Hard timeout for the container (wall time). The default is three times the value indicated for --time. --memory MEMORY Maximum memory for the container, in MB. The default is the same as the current container. --share-network Share the network stack of the grading container with the student container. This is not the case by default. It forwards standard I/O, most signals and returns specific additional exit codes: • 252 : student container killed due to an out-of-memory • 253 : student container timed out • 254 : I/O redirection failed #### Adapting the grading script The existing grading script can now be adapted easily. This will become: #!/bin/bash getinput "thecode" > student/student_code.py output=$(run_student python3 student/student_code.py)

if [ "$output" = "Hello World!" ]; then feedback-result success else feedback-result failed feedback-msg -em "Your program displayed :$output"
fi


Please note that the student container will be started with the same working directory as the grading container. You may need to change it to /student before to allow students to perform IO in the working directory.

#### Retry to break the code

The current task run script has been corrected to reflect the need for student process isolation. Try to break the grading script again !

##### Hello World !

Here you are asked to provide a basic Python 3 program displaying Hello World! on standard output.

Hint : to display something on standard output, use the built-in print method.

### Information

 Author(s) The INGInious authors Deadline No deadline Submission limit No limitation