Skip to main content

Virtual bash environment for AI agents, backed by Supermemory.

Project description

supermemory-bash

A virtual bash environment for AI agents, backed by your Supermemory container. Files persist across sessions, and a built-in sgrep command does semantic search across the entire filesystem.

Contents

Install

pip install supermemory-bash
# or
uv add supermemory-bash

You'll need a Supermemory API key. Get one at supermemory.ai.

Quickstart

import asyncio
from supermemory_bash import create_bash

async def main():
    result = await create_bash(
        api_key="sm-...",
        container_tag="user_42",
    )
    bash = result.bash

    # Run any shell command:
    r = await bash.exec("echo 'hello' > /a.md && cat /a.md")
    print(r.stdout)  # "hello\n"

    # Files persist across sessions, even from a fresh process:
    r2 = await bash.exec("cat /a.md")
    print(r2.stdout)  # "hello\n"

    # Semantic search across the whole container:
    r3 = await bash.exec("sgrep 'authentication tokens'")
    print(r3.stdout)
    # /work/auth.md:OAuth implementation handles token refresh and session management.
    # /notes/security.md:Two-factor authentication via TOTP is required for admin accounts.

asyncio.run(main())

Hand the bash tool to your LLM

create_bash returns a tool_description field. It's the package's opinionated description of the bash tool (sgrep guidance, persistence semantics, eventual-consistency notes, what's not supported), shipped so the agent doesn't have to discover any of it on its own. Drop it into the description field of your tool schema.

The same string is also exported as the named constant TOOL_DESCRIPTION if you'd rather import it directly (from supermemory_bash import TOOL_DESCRIPTION). Either form works. Examples below use the result field for consistency.

The agent gets:

  • All standard shell commands: cat, ls, mkdir, rm, mv, cp, grep, head, tail, wc, sed, pipes, redirects.
  • A custom sgrep command for semantic search across every file in the container.
  • A read-only /profile.md virtual file with memories synthesized from the container's content.
  • Files persist: writes are durable, reads work across sessions.

OpenAI

from openai import AsyncOpenAI
from supermemory_bash import create_bash

result = await create_bash(api_key="sm-...", container_tag="user_42")

client = AsyncOpenAI()
response = await client.chat.completions.create(
    model="gpt-5.5",
    messages=[{"role": "user", "content": "Search my notes for authentication."}],
    tools=[{
        "type": "function",
        "function": {
            "name": "bash",
            "description": result.tool_description,
            "parameters": {
                "type": "object",
                "properties": {"cmd": {"type": "string"}},
                "required": ["cmd"],
            },
        },
    }],
)

# In your tool-use loop, call `await result.bash.exec(cmd)` and feed the result back.

Anthropic

from anthropic import AsyncAnthropic
from supermemory_bash import create_bash

result = await create_bash(api_key="sm-...", container_tag="user_42")

client = AsyncAnthropic()
response = await client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=4096,
    tools=[{
        "name": "bash",
        "description": result.tool_description,
        "input_schema": {
            "type": "object",
            "properties": {"cmd": {"type": "string"}},
            "required": ["cmd"],
        },
    }],
    messages=[{"role": "user", "content": "Find my notes about authentication and summarize."}],
)

# In your tool-use loop, call `await result.bash.exec(cmd)` and feed the result back.

Options

await create_bash(
    api_key="sm-...",
    container_tag="user_42",        # one container per user / project
    base_url=None,                  # API override
    eager_load=True,                # default: True (warm path_index at construction)
    eager_content=True,             # default: True (also warm content cache)
    cache_ttl_ms=150_000,           # default: 150_000 (2.5 min). None = never expires (single-writer). 0 = no cache.
    cwd="/",                        # default working directory
    env=None,                       # extra environment variables
)

For very large containers (10k+ docs), set eager_content=False to skip the content warm and pay HTTP per cat. Path resolution stays warm.

cache_ttl_ms controls how long the in-memory content cache trusts itself. The default (2.5 min) assumes other writers exist (other agent sessions, dashboard uploads, webhooks). Single-writer apps can pass None for max speed.

What's not supported

  • chmod, utimes, symlinks (ln -s, readlink). Supermemory has no permission or symlink model; these throw ENOSYS.
  • /dev/null redirects. /dev/null exists as a directory marker but isn't a writable target. Use 2>/tmp/discard.log if you need to discard output.
  • Truly binary uploads. Content gets text-extracted server-side; raw binary write is not supported in this version.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supermemory_bash-0.0.2.tar.gz (69.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supermemory_bash-0.0.2-py3-none-any.whl (64.2 kB view details)

Uploaded Python 3

File details

Details for the file supermemory_bash-0.0.2.tar.gz.

File metadata

  • Download URL: supermemory_bash-0.0.2.tar.gz
  • Upload date:
  • Size: 69.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for supermemory_bash-0.0.2.tar.gz
Algorithm Hash digest
SHA256 09daa9efd4185ec120ff074472fe85858de754205c7c448ea52b184f0c0f1fd9
MD5 ab1621716136df5c67a1e71cfa5d405e
BLAKE2b-256 b4e4a00948cfb2e24c9b6e91f8869bf6a1308b349839f18aa57e553b6bb20237

See more details on using hashes here.

File details

Details for the file supermemory_bash-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for supermemory_bash-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d59e071491a72151b3f05865e8f4e6d8bdffbd2ec817ec7898ab71732f37d37
MD5 1ffa1892a06d8a24a2f021ada8e5c7d9
BLAKE2b-256 a98d71694906f09a3eb9ddc09b389c03f0f5cce60329a8575136bd610be1ead6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page