Runcap provides an API for running arbitrary external command and capturing its stdout and/or stderr stream. Optionally, it is able to pipe data to the program's stdin. Execution timeout can be imposed.
Please see Runcap Documentation for details.