langchain icon indicating copy to clipboard operation
langchain copied to clipboard

wip: docker wrapper and tool generator - run untrusted code

Open blob42 opened this issue 2 years ago • 1 comments

WIP docker wrapper utility for untrusted code execution.

TODO:

  • [ ] Docker utility wrapper
    • [x] drop networking capabilities by default
    • [x] poc: send payload to container's stdin through socket notes: a bit hacky there is no way to know when stdout is ready but seems working.
    • [ ] poc: send payload to container's stdin with subprocess pipe
    • [ ] send payload to container via filesystem or API put method.
    • [x] Spawn new container for query
    • [x] Attach to running container's stdin and send command
    • [x] Use gVisor runtime and add warning if not available
    • [x] docker image template helper
  • [ ] LLMChain with docker run/exec context
  • [ ] Documentation
    • [x] networking
    • [ ] sending queries to arbitrary containers/images
    • [ ] create custom image templates
    • [ ] Docker tool generator
  • [ ] Testing
    • [x] Skippable docker tests if docket not available
    • [x] Default to using gVisor runtime if available.
    • [x] Auto pull images from docker hub.

Examples

blob42 avatar Feb 23 '23 23:02 blob42

quick update: I implemented sending the query to the container through docker API's socket. This allows to truly send arbitrary commands and fully simulates sending input through a TTY. The output is also read through the socket and separate in to stdin and stderr.

This was necessary as sending commands using the basic run and exec_run docker does not allow to send complex multiline input and only allows for simple one line scripts. In the example notebook small bash script over multiple lines is sent to a spawned container.

An other option would've been to use subprocess and call docker exec with pipe redirection. If the socket solution is too hacky I will fallback to this option.

blob42 avatar Feb 25 '23 23:02 blob42