feat(kit): add redis-agent mixin with Redis 7 and cache.py helper - #129
Open
N4si wants to merge 2 commits into
Open
feat(kit): add redis-agent mixin with Redis 7 and cache.py helper#129N4si wants to merge 2 commits into
N4si wants to merge 2 commits into
Conversation
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>
…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>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
redis-agent, a mixin kit that runs Redis 7 inside the sandbox viaDocker-in-Docker and gives any agent a pre-wired
cache.pyhelper.The kit layers on top of any agent that provides a Docker daemon —
claude,pi,hermes-agent— without replacing it:Includes:
redis:7-alpinepulled and started automatically at sandbox creationredis-pywith thehiredisC extension installed in an isolated venv at/opt/redis-agentcache.pyhelper 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.mdwith working code examples for all three patternsSpec 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-alpineinside 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.0within 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.sh—profile.dand.bashrcare not sourced in non-interactive shells. AI agents run bash tool calls non-interactively, so writing the venv PATH export tosandbox-persistent.sh(sourced viaBASH_ENVin every shell context) is the correct mechanism.profile.dis 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-agentpasses (24s)KIT_UNDER_TEST="$PWD/redis-agent" go test -tags=e2e -v -timeout 25m -count=1 -run TestE2EKit ./tck/...pythonresolves to venv in non-interactive shell (confirmed viasandbox-persistent.sh)set/getwith JSON serialization and TTL verifiedenqueue/dequeuetask queue verifiedpublishverified (0 subscribers expected in single-process test)