Skip to content

feat(kit): add redis-agent mixin with Redis 7 and cache.py helper - #129

Open
N4si wants to merge 2 commits into
docker:mainfrom
N4si:feat/redis-agent
Open

feat(kit): add redis-agent mixin with Redis 7 and cache.py helper#129
N4si wants to merge 2 commits into
docker:mainfrom
N4si:feat/redis-agent

Conversation

@N4si

@N4si N4si commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Adds redis-agent, a mixin kit that runs Redis 7 inside the sandbox via
Docker-in-Docker and gives any agent a pre-wired cache.py helper.

The kit layers on top of any agent that provides a Docker daemon — claude,
pi, hermes-agent — without replacing it:

sbx run --kit "git+https://github.com/docker/sbx-kits-contrib.git#dir=redis-agent" claude

Includes:

  • redis:7-alpine pulled and started automatically at sandbox creation
  • redis-py with the hiredis C extension installed in an isolated venv at /opt/redis-agent
  • cache.py helper covering the three patterns AI agents use most: key-value caching with optional TTL, blocking task queues (enqueue/dequeue), and pub/sub messaging (publish/subscribe/listen)
  • REDIS.md with working code examples for all three patterns

Spec choices worth flagging for review

kind: mixin — Redis is a backing service, not an agent. The mixin model lets developers layer Redis on top of whatever agent they are already running rather than replacing it with a new entrypoint.

Docker daemon dependency — the startup command runs docker run redis:7-alpine inside the sandbox, which requires the target agent to provide a Docker daemon. This works with shell-docker based agents (claude, pi, hermes-agent). It will not work with agents that use a plain base image without Docker.

redis:7-alpine — minimal image (~40 MB compressed). No persistence flags; data lives in memory only, which matches the ephemeral sandbox lifecycle.

No authentication — Redis publishes on 0.0.0.0 within the microVM but is isolated by the sandbox network boundary. A password would add no meaningful security and would require passing credentials through env vars.

PATH via /etc/sandbox-persistent.shprofile.d and .bashrc are not sourced in non-interactive shells. AI agents run bash tool calls non-interactively, so writing the venv PATH export to sandbox-persistent.sh (sourced via BASH_ENV in every shell context) is the correct mechanism. profile.d is kept as a belt-and-suspenders fallback for login shells.

Docker Hub allowedDomains — four domains required to pull the Redis image: registry-1.docker.io, auth.docker.io, production.cloudflare.docker.com, index.docker.io. Plus pip and apt domains for the Python install. All discovered by probing under deny-all.

Origin

Community contribution. Redis for ephemeral agent state, caching, and agent-to-agent messaging.

Test plan

  • sbx kit validate ./redis-agent/ passes
  • ./scripts/test-kit.sh redis-agent passes (24s)
  • e2e passes (58s) — run directly with KIT_UNDER_TEST="$PWD/redis-agent" go test -tags=e2e -v -timeout 25m -count=1 -run TestE2EKit ./tck/...
  • Manual smoke test on Apple Silicon (arm64, macOS):
    • Redis 7-alpine boots inside microVM
    • python resolves to venv in non-interactive shell (confirmed via sandbox-persistent.sh)
    • set/get with JSON serialization and TTL verified
    • enqueue/dequeue task queue verified
    • publish verified (0 subscribers expected in single-process test)

Adds redis-agent, a mixin that runs Redis 7 inside the sandbox via
Docker-in-Docker and gives any agent a pre-wired cache.py helper.

Includes:
- redis:7-alpine started automatically at sandbox creation
- redis-py with hiredis installed in an isolated venv at /opt/redis-agent
- PATH wired via /etc/sandbox-persistent.sh for non-interactive agent shells
- cache.py helper covering key-value caching (with TTL), task queues
  (enqueue/dequeue), and pub/sub (publish/subscribe)
- REDIS.md with usage examples for all three patterns

Spec choices:
- kind: mixin — Redis is infrastructure, not an agent; layers on top of
  claude, pi, hermes-agent, or any other agent
- shell-docker base image provides the Docker daemon for DinD
- redis:7-alpine chosen for minimal image size
- No authentication — Redis only binds to localhost inside the microVM;
  the sandbox network boundary provides isolation
- sandbox-persistent.sh for PATH — profile.d and .bashrc are not sourced
  in non-interactive shells, which is how AI agents run bash tool calls

Test plan:
- sbx kit validate passes
- TCK passes in 24s
- e2e passes in 58s
- Manual smoke: set/get with TTL+JSON, enqueue/dequeue, all verified

Signed-off-by: Nasi Chaudhari <chaudharinasi@gmail.com>
@N4si
N4si requested a review from a team as a code owner July 6, 2026 22:30
…JSON

publish() JSON-encodes messages but the subscribe path had no corresponding
decode step, so msg["data"] returned a raw JSON string instead of a dict.
Adds a listen() generator that wraps ps.listen() and applies json.loads,
giving symmetric encode/decode across all three cache patterns.

Signed-off-by: Nasi Chaudhari <chaudharinasi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant