Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fafrd/aquarium
AI-controlled Linux Containers
https://github.com/fafrd/aquarium
Last synced: 2 months ago
JSON representation
AI-controlled Linux Containers
- Host: GitHub
- URL: https://github.com/fafrd/aquarium
- Owner: fafrd
- License: gpl-3.0
- Created: 2023-03-21T03:56:02.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-24T18:08:26.000Z (over 1 year ago)
- Last Synced: 2024-08-02T05:15:11.638Z (5 months ago)
- Language: Go
- Homepage:
- Size: 70.3 KB
- Stars: 666
- Watchers: 13
- Forks: 40
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-starred - fafrd/aquarium - AI-controlled Linux Containers (Go)
- awesome-starred - fafrd/aquarium - AI-controlled Linux Containers (Go)
README
# Bot Aquarium
This project gives a large language model (LLM) control of a Linux machine.
In the example below, we start with the prompt:
> You now have control of an Ubuntu Linux server. Your goal is to run a Minecraft server. Do not respond with any judgement, questions or explanations. You will give commands and I will respond with current terminal output.
>
> Respond with a linux command to give to the server.The AI first does a _sudo apt-get update_, then installs openjdk-8-jre-headless. Each time it runs a command we return the result of this command back to OpenAI and ask for a summary of what happened, then use this summary as part of the next prompt.
[![asciicast](https://asciinema.org/a/0CH4ESDjt4H11WABiMlGZNMYU.png?)](https://asciinema.org/a/0CH4ESDjt4H11WABiMlGZNMYU?&speed=2&i=2&autoplay=1)
Inspired by [xkcd.com/350](https://xkcd.com/350/) and [Optimality is the tiger, agents are its teeth](https://www.lesswrong.com/posts/kpPnReyBC54KESiSn/optimality-is-the-tiger-and-agents-are-its-teeth)
# Usage
## Build
docker network create aquarium
docker build -t aquarium .
go build## Start
Pass your prompt in the form of a goal. For example, `--goal "Your goal is to run a minecraft server."`
Using OpenAI:
OPENAI_API_KEY=$OPENAI_API_KEY ./aquarium --goal "Your goal is to run a Minecraft server."
Using a local model provided by [llama-cpp-python](https://github.com/abetlen/llama-cpp-python):
./aquarium --goal "Your goal is to run a Minecraft server." --url "http://localhost:8000" --context-mode full
**arguments**
./aquarium -h
Usage of ./aquarium:
-context-mode string
How much context from the previous command do we give the AI? This is used by the AI to determine what to run next.
- partial: We send the last 10 lines of the terminal output to the AI. (cheap, accurate)
- full: We send the entire terminal output to the AI. (expensive, very accurate)
(default "partial")
-debug
Enable logging of AI prompts to debug.log
-goal string
Goal to give the AI. This will be injected within the following statement:> You now have control of an Ubuntu Linux server.
> [YOUR GOAL WILL BE INSERTED HERE]
> Do not respond with any judgement, questions or explanations. You will give commands and I will respond with current terminal output.
>
> Respond with a linux command to give to the server.
(default "Your goal is to run a Minecraft server.")
-limit int
Maximum number of commands the AI should run. (default 30)
-model string
OpenAI model to use. Ignored if --url is provided. See https://platform.openai.com/docs/models (default "gpt-3.5-turbo")
-preserve-container
Persist docker container after program completes.
-url string
URL to locally hosted endpoint. If provided, this supersedes the --model flag.## Logs
The left side of the screen contains general information about the state of the program. The right side contains the terminal, as seen by the AI.
These are written to aquarium.log and terminal.log.Calls to the AI are not logged unless you add the `--debug` flag. API requests and responses will be appended to debug.log.
# How it works
## Agent loop
1. Send the OpenAI api the list of commands (and their outcomes) executed so far, asking it what command should run next
1. Execute command in docker VM
1. Read output of previous command- send this to OpenAI and ask gpt-3.5-turbo for a summary of what happened
1. If the output was too long, OpenAI api will return a 400
1. Recursively break down the output into chunks, ask it for a summary of each chunk
1. Ask OpenAI for a summary-of-summaries to get a final answer about what this command did## more examples
Prompt: `Your goal is to execute a verbose port scan of amazon.com.`
The bot replies with _nmap -v amazon.com_. nmap is not installed; we return the failure to the AI, which then installs it and continues.
https://user-images.githubusercontent.com/5905628/227047932-1a87e7e7-43f9-48e0-aab2-bc83126b3be1.mp4
Prompt: `Your goal is to install a ngircd server.` (an IRC server software)
Installs the software, helpfully allows port 6667 through the firewall, then tries to run _sudo -i_ and gets stuck.
# Todo
- There's no success criteria- the program doesn't know when to stop. The flag `-limit` controls how many commands are run (default 30)
- The AI cannot give input to running programs. For example, if you ask it to SSH into a server using a password, it will hang at the password prompt. For `apt-get`, i've hacked around this issue by injecting `-y` to prevent asking the user for input.
- The terminal output handling is imperfect. Some commands, like wget, use \\r to write the progress bar... I rewrite that as a \\n instead. I also don't have any support for terminal colors, which i'm suppressing with `ansi2txt`