Skip to content

safekeys/integration-python-sdk [built] ​

The Python Agent SDK is a token-only client for teams building agents, shipping LangChain and LangGraph tools first. create_secret and resolve_for_tool accept and return only capability tokens and folder paths — plaintext is unrepresentable in the API surface, so an agent cannot accidentally route a value through model context.

Status: built

Why this exists ​

Agent developers will do whatever is easiest, so the safest path has to be the easy path. A SDK whose types make plaintext impossible to pass or receive removes the opportunity for the most common mistake — and it is what Python-first agent teams already expect from a tool integration.

Design decisions ​

python-first [accepted] ​

Decision: Ship the Python SDK as the first language binding, with LangChain and LangGraph tools.

Rationale: Python is still the default for people building agents, and those teams expect framework-native tools rather than a raw client. It is also one of the three MVP harness integrations named in the blueprint.

unrepresentable-plaintext [accepted] ​

Decision: Design the API so plaintext cannot be passed or received.

Rationale: A type surface that cannot express a value is a stronger guarantee than documentation asking developers not to pass one.

delegate-all-crypto [accepted] ​

Decision: Keep the SDK free of decryption and key handling.

Rationale: Duplicating crypto in every SDK multiplies the audit surface on the most sensitive path; the sidecar exists precisely so clients do not need it.

zero-dependency-core [accepted] ​

Decision: Keep the core SDK dependency-free; make LangChain/LangGraph an optional extra.

Rationale: A caller who only needs create_secret and resolve_for_tool should pull in nothing. Every dependency in a security-sensitive client is another supply-chain surface and another reason not to adopt it, and the core surface is a Unix socket and json — the standard library is sufficient.

Alternatives considered:

  • Require langchain-core — rejected: Forces a large, fast-moving dependency on callers who only want the token-only primitives, and pins the SDK to one framework's release cadence.

Consequences: The tools ship framework-neutral TOOL_SPECS (JSON Schema) so any runtime can register them; build_langchain_tools raises a clear error when the extra is absent rather than degrading silently.

Date: 2026-09-23

value-becomes-a-temp-file [accepted] ​

Decision: Even the in-process value parameter is written to a 0600 temp file that the sidecar reads, rather than being sent over the socket.

Rationale: It keeps the wire protocol uniform — the sidecar only ever reads a named source — so there is exactly one code path on the create boundary and it is the one already tested. It also means no value ever sits in a socket buffer.

Consequences: create_secret(value=...) writes and shreds a temp file. Agent-facing code should still use source_file; value exists for trusted in-process callers such as a CLI reading stdin.

Date: 2026-09-23

return-type-is-the-guarantee [accepted] ​

Decision: Rely on return types (CreatedSecret, ResolveResult, ObjectMetadata) having no value-bearing field, rather than on documentation.

Rationale: A type with nowhere to put a plaintext is a stronger guarantee than a rule saying not to include one. A test asserts every public method's return annotation is one of the value-free types, so adding a value-bearing return is a deliberate, visible act.

Date: 2026-09-23

How it works ​

Create a secret via the SDK tool (create-secret-tool) ​

The agent creates a secret and receives a token.

  1. Receive — Agent calls create_secret with metadata and a non-context value source such as a file path.
  2. Send — SDK hands the value to the local sidecar over the Unix socket.
  3. Receive — SDK returns a capability token and folder path.
  4. Observe — The agent transcript contains no plaintext.

Resolve a secret for a tool call (resolve-for-tool) ​

The agent requests use of a secret without receiving the value.

  1. Receive — Agent calls resolve_for_tool with a token and the target tool or command.
  2. Send — SDK forwards the request to the sidecar, which injects into the consumer.
  3. Receive — SDK returns a success status or placeholder.
  4. Observe — The value never enters the Python process hosting the agent.

Guarantees ​

token-only-surface ​

The SDK's public API accepts and returns tokens and paths, never values.

Acceptance criteria:

  • [ ] No public function returns a resolved plaintext value
  • [ ] create_secret returns a token, not the value
  • [ ] resolve_for_tool returns a status or placeholder

no-plaintext-in-context ​

Using the SDK cannot place plaintext into model context.

Acceptance criteria:

  • [ ] Values are read from the sidecar channel, not passed as literals from the agent
  • [ ] Tool call arguments carry tokens
  • [ ] The SDK's docstrings and examples never suggest pasting a value

sidecar-is-the-transport ​

The SDK delegates all resolution to the sidecar rather than implementing crypto.

Acceptance criteria:

  • [ ] The SDK contains no decryption or key handling code
  • [ ] Communication is over the local Unix socket
  • [ ] Failure to reach the sidecar is surfaced as an error, never a fallback

langchain-tool-parity ​

The LangChain and LangGraph tools behave identically to the raw SDK calls.

Acceptance criteria:

  • [ ] Tool definitions wrap the same SDK functions
  • [ ] Tool schemas expose tokens and paths only
  • [ ] Tool outputs never include values

Test specifications ​

create-returns-token-not-value ​

Given:

  • value_source: "file"
  • secret_value: "sdk-test-secret"

When: create-secret-tool

Then:

  • assertion: the return value is a token and path
  • assertion: the return value does not contain the secret

Contracts verified: token-only-surface

resolve-returns-status-only ​

Given:

  • token: "safekey://v1/demo"

When: resolve-for-tool

Then:

  • assertion: the return value is a status or placeholder
  • assertion: no plaintext is returned to the agent process

Contracts verified: token-only-surface, no-plaintext-in-context

sdk-has-no-crypto ​

Given:

  • static_check: true

When: create-secret-tool

Then:

  • assertion: the SDK imports no decryption or key-handling primitives
  • assertion: all resolution goes through the sidecar socket

Contracts verified: sidecar-is-the-transport

langgraph-agent-transcript-clean ​

Given:

  • agent: "langgraph"

When: create-secret-tool

Then:

  • assertion: the agent transcript contains no plaintext
  • assertion: the agent holds only a token afterwards

Contracts verified: no-plaintext-in-context, langchain-tool-parity

Implementation ​

  • Primary: packages/sdk-python/safekeys/client.py
  • Test code: packages/sdk-python/tests/test_sdk.py
  • Test code status: manual

See Also ​

  • safekeys/secret-creation
  • safekeys/sidecar-resolution
  • safekeys/mcp-server
  • safekeys/exec-wrapper