What the agent does
The agent reads how the app runs before it writes an image for it. In a repository shaped like streamlit/llm-examples, Chatbot.py at the root is the entry page and pages/ holds five more, from 1_File_Q&A.py to 5_Chat_with_user_feedback.py, which Streamlit turns into the sidebar navigation by filename. requirements.txt pins streamlit>=1.28, langchain==0.0.350, langchain-community==0.0.3, openai>=1.2, anthropic>=0.3.0, duckduckgo-search, trubrics>=1.4.3 and streamlit-feedback; requirements-dev.txt adds black, mypy, pre-commit, watchdog and pytest. There is no Dockerfile, no .dockerignore and no .streamlit/config.toml.
Two files say how the app is already run elsewhere. .devcontainer/devcontainer.json uses the python:3.11-bullseye image, forwards port 8501, installs requirements.txt after create and starts streamlit run Chatbot.py with CORS and XSRF protection switched off for the Codespaces proxy. .github/workflows/app-testing.yml runs on Python 3.11 with streamlit/streamlit-app-action pointed at Chatbot.py, with ruff and pytest, and app_test.py drives the chatbot through streamlit.testing.v1.AppTest with the OpenAI client patched. API keys are typed into the sidebar at runtime through st.text_input with type="password", and .gitignore already excludes secrets.toml, so the image must not bake a key in.
The agent writes a Dockerfile on python:3.11-slim, matching the Python the CI and the devcontainer use: a layer that copies requirements.txt and installs it, so a code change does not reinstall LangChain, then the app files, a non-root user, EXPOSE 8501, a HEALTHCHECK that fetches Streamlit's /_stcore/health endpoint, and a CMD of streamlit run Chatbot.py --server.port=8501 --server.address=0.0.0.0. It adds a .dockerignore with .git, .venv, __pycache__, secrets.toml and the devcontainer, a .streamlit/config.toml that sets headless = true and leaves CORS and XSRF protection on, and a compose.yaml with the one service, the port mapping and an optional env_file for OPENAI_API_KEY and ANTHROPIC_API_KEY so a key can come from the environment instead of the sidebar. The dev dependencies stay out of the image.
Then it runs what it wrote. docker build has to finish, docker run has to start, and /_stcore/health has to answer ok before the container reports healthy. The agent opens the running app in the sandbox's browser and visits each of the six pages to confirm they render without a missing module, since langchain-community and streamlit-feedback are imported only on the pages that use them. It runs pytest app_test.py in the sandbox against the same code to confirm the test still passes, and adds a short section to README.md with the build and run commands.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Containerize this Streamlit app. Read Chatbot.py, every file under pages/, requirements.txt, requirements-dev.txt, app_test.py, .devcontainer/devcontainer.json, .github/workflows/app-testing.yml, .ruff.toml and .gitignore first, and note the Python version, the entry page, the port and how API keys reach the app. Write a Dockerfile on python:3.11-slim with the requirements installed in their own cached layer, a non-root user, EXPOSE 8501, a HEALTHCHECK on /_stcore/health and a CMD that runs streamlit run Chatbot.py bound to 0.0.0.0 on 8501. Add a .dockerignore, a .streamlit/config.toml with headless mode and CORS and XSRF protection left on, and a compose.yaml with the service, the port and an optional env_file for the API keys. Do not put a key in the image. Build the image, run it, wait for the health endpoint, open every page in the browser and confirm each renders, run pytest app_test.py, add a Docker section to README.md, and open a pull request with the image size and the commands to run it.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
What comes back is a pull request on its own branch with five files: Dockerfile, .dockerignore, .streamlit/config.toml, compose.yaml and a Docker section in README.md. No Python file changes, requirements.txt is untouched, and the devcontainer and the app-testing workflow keep working as before. The description shows the build and run commands, the image size the build reported, and which pages the agent opened.
The checks and the record are the proof. The repository's App testing workflow still runs on the pull request, since the Python files did not change. The run's trajectory at GET /o/{org}/sessions/{id}/messages keeps the docker build output, the health endpoint's answer, the page visits in the sandbox browser and the pytest result beside the commands that produced them, so a reviewer sees the container answered on 8501 from a clean image rather than from a laptop that already had the packages installed.
Before merging, a reviewer decides whether keys should come from env_file, from the sidebar, or both, checks the base image against the Python their platform supports, and confirms the .dockerignore excludes anything else they keep locally. Nothing is deployed until the pull request merges.
Run it on every new Streamlit app without a Dockerfile
A team with several Streamlit apps starts one run per repository: a POST /o/{org}/sessions with that repository in resources and this prompt, and a request_id per repository so a retried request returns the run it already started rather than a second one. Each run gets its own sandbox with its own Docker daemon and its own port 8501, so several builds run at once without sharing a layer cache.
A webhook_url on the API key receives run.completed or run.failed for each turn, with data.session_url to read for the pull request link. Up to the key's max_concurrent runs proceed in parallel; the rest answer 202 with status: "queued" and start, oldest first, as each Streamlit build finishes.
The use case this job follows, with its automation and trigger: Hand off a long task.
Why run it on Rush?
The slow part of this job is the loop: build, start, watch a page fail on an import that only that page uses, change a line, build again. On a laptop that loop fills the Docker cache with LangChain layers and competes with the dev server already on port 8501. In a Rush sandbox the agent has its own daemon, its own ports and a browser to open each page in, and the sandbox parks when the turn ends, so nothing is left running on your machine.
The pull request carries its own proof. The build output, the health check answer, the page visits and the pytest result are in the transcript beside the commands that produced them, so a reviewer can see the app served all six pages from a clean image before they pull it.
Frequently asked questions
Where do the OpenAI and Anthropic keys go?
Nowhere in the image. The app reads them from the sidebar at runtime through st.text_input with type="password", and that keeps working in the container. The compose.yaml adds an optional env_file so OPENAI_API_KEY and ANTHROPIC_API_KEY can come from the environment instead, and .dockerignore keeps secrets.toml out of the build context.
Why python:3.11-slim rather than the devcontainer's image?
Because .github/workflows/app-testing.yml and .devcontainer/devcontainer.json both run Python 3.11, so 3.11 is the version the app is known to work on, and the slim variant leaves out the compilers and tooling the devcontainer carries for editing. The agent reports the image size in the pull request so you can judge the trade-off.
Does it keep the devcontainer's CORS and XSRF flags?
No. The devcontainer switches both off because Codespaces proxies the port; a container you run yourself does not need that, so .streamlit/config.toml leaves them on and sets headless = true so Streamlit does not try to open a browser. If you put the container behind a proxy that needs the flags, they are two lines in that file.
Will the pages that use LangChain still work?
Yes, and the agent checks each one. requirements.txt pins langchain==0.0.350 and langchain-community==0.0.3, which are installed in the image, and the agent opens all six pages in the sandbox browser so an import that only 3_Langchain_Quickstart.py makes is caught before the pull request opens.
Does the existing test run inside the container?
No. pytest is in requirements-dev.txt, which stays out of the image, so the agent runs pytest app_test.py in the sandbox against the same files. The App testing workflow runs it in CI as before, since no Python file changes.
More Streamlit jobs
The same job on other stacks
- Dockerize a SvelteKit App (SvelteKit)
- Dockerize a Symfony App (Symfony)
- Dockerize a Temporal TypeScript Worker (Temporal)