How to Integrate AutoGen for banking with Docker for AI agents
Opening
If you’re building banking agents, you need two things working together: a policy-aware orchestration layer and an execution environment you can trust. AutoGen for banking handles the agent workflow, while Docker gives you isolated, reproducible sandboxes for running code, tools, and bank-specific workflows.
The useful pattern here is simple: let AutoGen decide what to do, then hand off execution to a Docker container with strict runtime boundaries. That gives you agentic automation without letting every tool call touch your host machine.
Prerequisites
- •Python 3.10+
- •Docker Engine installed and running
- •An AutoGen for banking package installed in your environment
- •A valid bank sandbox or test environment configured
- •Access credentials for any banking APIs you plan to call
- •
pip,venv, and permission to run Docker containers locally
Install the core packages:
pip install pyautogen docker
If your banking setup uses a custom AutoGen extension package, install that too:
pip install autogen-banking
Integration Steps
1) Create a Docker client in Python
Start by connecting to the local Docker daemon. This is the execution layer your agents will use for isolated tasks.
import docker
client = docker.from_env()
# Quick sanity check
print(client.ping())
If client.ping() returns True, your Python process can talk to Docker.
2) Define a container runner for agent tasks
AutoGen should not execute arbitrary code directly on the host. Wrap container execution in a small helper that runs a command inside an ephemeral container.
import docker
client = docker.from_env()
def run_in_container(image: str, command: str) -> str:
container = client.containers.run(
image=image,
command=["/bin/sh", "-lc", command],
detach=True,
remove=True,
network_mode="bridge",
)
result = container.wait()
logs = container.logs().decode("utf-8")
if result["StatusCode"] != 0:
raise RuntimeError(f"Container failed: {logs}")
return logs
output = run_in_container("python:3.11-slim", "python -c 'print(\"hello from docker\")'")
print(output)
This is the pattern you want in production: short-lived containers, explicit commands, no shared filesystem by default.
3) Configure the AutoGen banking agent with a Docker-backed tool
Now wire AutoGen to call the container runner as a tool. In AutoGen-style workflows, you typically expose functions as callable tools and let the assistant decide when to use them.
from autogen import AssistantAgent, UserProxyAgent
def validate_payment_batch(batch_json: str) -> str:
return run_in_container(
"python:3.11-slim",
f"python - <<'PY'\nimport json\nbatch = json.loads({batch_json!r})\nprint('records:', len(batch['payments']))\nPY"
)
llm_config = {
"model": "gpt-4o-mini",
"api_key": "YOUR_OPENAI_API_KEY",
}
assistant = AssistantAgent(
name="banking_assistant",
llm_config=llm_config,
)
user_proxy = UserProxyAgent(
name="banking_operator",
human_input_mode="NEVER",
code_execution_config=False,
)
assistant.register_for_llm(name="validate_payment_batch", description="Validate payment batch in Docker")(validate_payment_batch)
user_proxy.register_for_execution(name="validate_payment_batch")(validate_payment_batch)
The key piece here is that the agent gets a tool, but the actual work happens inside Docker. That keeps validation logic isolated from the host process.
4) Add a banking workflow step that calls an API from inside Docker
For regulated environments, keep network access controlled and inject credentials at runtime. Here’s a pattern where the container runs a Python script that calls a banking sandbox API.
import os
import textwrap
BANK_API_TOKEN = os.environ["BANK_API_TOKEN"]
script = textwrap.dedent(f"""
import os
import requests
token = "{BANK_API_TOKEN}"
resp = requests.get(
"https://sandbox.bank.example.com/v1/accounts",
headers={{"Authorization": f"Bearer {{token}}"}}
)
print(resp.status_code)
print(resp.text[:500])
""")
result = run_in_container(
"python:3.11-slim",
f"pip install requests >/dev/null 2>&1 && python - <<'PY'\n{script}\nPY"
)
print(result)
In production, I’d mount secrets instead of embedding tokens in strings. The important part is that your agent can orchestrate the call while Docker enforces runtime isolation.
5) Orchestrate both layers in one agent loop
Now combine planning and execution. The assistant proposes an action, and the user proxy executes it through Docker-backed functions.
task = """
Check whether this payment batch is structurally valid before submission:
{"payments": [{"id": "p1", "amount": 125.50}, {"id": "p2", "amount": 88.00}]}
"""
response = user_proxy.initiate_chat(
assistant,
message=task,
)
print(response.summary)
In real deployments, you would replace the toy validation with actual bank controls:
- •schema checks
- •limit checks
- •sanctions screening hooks
- •reconciliation jobs
- •report generation
Testing the Integration
Use a minimal smoke test that proves both pieces are connected: AutoGen can call a tool, and that tool runs inside Docker.
test_batch = '{"payments":[{"id":"a1","amount":10},{"id":"a2","amount":20}]}'
print(validate_payment_batch(test_batch))
Expected output:
records: 2
If you want stronger verification, assert on both Docker connectivity and tool execution:
assert client.ping() is True
assert "records: 2" in validate_payment_batch(test_batch)
print("integration ok")
Expected output:
integration ok
Real-World Use Cases
- •
Payment batch pre-validation
- •An AutoGen agent reviews incoming batches, then sends schema and business-rule checks into a Docker container before anything reaches core banking systems.
- •
KYC document processing
- •The agent extracts fields from uploaded documents, then runs OCR or parsing jobs inside containers with controlled dependencies and no host contamination.
- •
Reconciliation and exception handling
- •AutoGen identifies mismatches across ledger exports, while Docker runs deterministic reconciliation scripts against pinned library versions.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit