Metadata-Version: 2.4
Name: agent-framework-plimsoll
Version: 0.29.0
Summary: A Microsoft Agent Framework shell tool and code tool that run agent-written commands and code in plimsoll, a self-hosted sandbox that refuses to run below the isolation you require
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/plimsollmark/plimsoll/tree/main/clients/python/agent-framework-plimsoll
Project-URL: Source, https://github.com/plimsollmark/plimsoll/tree/main/clients/python/agent-framework-plimsoll
Project-URL: Issues, https://github.com/plimsollmark/plimsoll/issues
Keywords: agent-framework,microsoft agent framework,shell,sandbox,code execution,agents,gvisor
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: agent-framework-core==1.26.0
Requires-Dist: agent-framework-tools==1.0.0b261112
Requires-Dist: plimsoll-client==0.29.0
Dynamic: license-file

# agent-framework-plimsoll

An agent with a shell runs whatever commands its model writes. Microsoft Agent Framework's own `LocalShellTool` runs them
on your machine ("arbitrary commands run on the host with the agent's privileges", in its own error message), and
`DockerShellTool` runs them in a container on the agent's machine. This package runs them in plimsoll instead, a
sandbox service you run yourself, possibly somewhere else, and it has no fallback: if the sandbox is weaker than you
asked for, nothing runs.

It has two parts:

- **`PlimsollShellTool`**, the agent's shell over one plimsoll session: the files a command writes, the shell's
  directory and its exported variables are there for the next command.
- **`plimsoll_code_tool`**, a tool that runs each call's Python or JavaScript in a fresh sandbox.

## Install

```sh
pip install agent-framework-plimsoll
```

It needs a running `plimsolld`, the plimsoll daemon, reachable from the agent
([getting started (EXTERNAL · source repo ↗)](https://github.com/plimsollmark/plimsoll/blob/main/docs/getting-started.md)).
The shell tool needs a provider with sessions: docker (with a project image), E2B or OpenShell today
([which providers (EXTERNAL · source repo ↗)](https://github.com/plimsollmark/plimsoll/blob/main/docs/sessions.md#which-providers)).
Sessions are off until the daemon is started with `SANDBOX_MAX_SESSIONS` set (for example `SANDBOX_MAX_SESSIONS=4`);
without it entering `PlimsollShellTool` raises plimsoll's `UnsupportedError`, saying the daemon has no sessions.
Python 3.11 or later, as Agent Framework requires.

## Use the shell tool

```python
from agent_framework import create_harness_agent
from agent_framework_plimsoll import Client, PlimsollShellTool

async with PlimsollShellTool(Client("https://plimsoll.internal:8746", token=TOKEN),
                             minimum_isolation="kernel") as shell:
    agent = create_harness_agent(chat_client, shell_executor=shell, disable_file_memory=True)
    session = agent.create_session()
    print(await agent.run("Count the lines in every .py file here.", session=session))
```

`disable_file_memory=True` is there because the harness otherwise keeps a file memory in `./agent-file-memory/` on
the machine the agent runs on, outside the sandbox; drop it if you want that memory.

The tool is Agent Framework's shell executor (`start`, `run`, `close`, `as_function`), so the harness gives it to the
model as its `run_shell` tool and its environment provider runs a few commands through it to tell the model what shell it
has. With an agent of your own, `client.get_shell_tool(func=shell.as_function())` is the same tool.

**The chat client has to carry a shell tool.** `create_harness_agent` gives the model the shell only when the chat client
implements Agent Framework's `SupportsShellTool`; otherwise it logs "Shell tool not available" as a warning, leaves the shell
out, and the agent answers without running anything in plimsoll. `OpenAIChatClient` (OpenAI's Responses API) and
`AnthropicClient` carry it, and so do the clients built on them (Foundry, Azure AI, and Anthropic on Bedrock, Foundry and
Vertex); `OpenAIChatCompletionClient` and the Ollama, Gemini, Bedrock and GitHub Copilot clients do not (read from those
packages' source as published on 2026-11-22). Check with `isinstance(chat_client, SupportsShellTool)` before relying on it.

What the shell tool needs and does:

- **The floor is yours to set.** `minimum_isolation` (`process`, `container`, `kernel` or `vm`) has no default. When the
  session opens, its tier is checked against the floor before any command is sent; below it, the session is closed and
  `InsufficientIsolationError` is raised.
- **One session for the conversation.** A process left running in the background is stopped when its command ends. A
  session left idle is suspended by the daemon and resumes, files kept, on its next command. Once the session has ended
  (its lifetime ran out, the daemon closed it, or you closed the tool), every later command raises `SessionEndedError`;
  the tool never opens a fresh sandbox in its place, because the agent would take it for the one holding its files.
- **A refusal raises, and a command that may have run stops the run.** A command plimsoll refused before anything ran,
  and a command on an ended session, raise plimsoll's own exceptions, and the model is shown the framework's error result
  ("Error: Function failed.", with the detail only if you set the framework's `include_detailed_errors`), never a refusal
  dressed as command output. A command that may have run without an answer to show for it (the answer was lost, the
  run ended without the command's report, or any error plimsoll cannot vouch ran nothing) ends the agent's run instead: `agent.run` raises Agent Framework's
  `MiddlewareFailure`, whose `__cause__` is plimsoll's error, so the model never gets the chance to run it again. They are plimsoll's exceptions, not Agent Framework's own shell errors, because its
  environment provider reads a probe that raises one of those as a command that is not installed. A command that runs
  and fails, and one past its time budget, are normal results.
- **No human approval by default.** The tool's `approval_mode` is `never_require`: the sandbox, not a person, is the
  boundary. Microsoft's own `LocalShellTool` and `DockerShellTool` default to `always_require`, which asks a person to
  approve each command, so swapping one of them for this tool drops that step unless you keep it:
  `PlimsollShellTool(client, minimum_isolation="kernel", approval_mode="always_require")`.
- **Every command has a budget,** 120 seconds unless you set `timeout`; `max_timeout` caps any budget. plimsoll enforces
  it: the daemon stops the command and kills whatever it left running.
- **The shell is the image's.** On plimsoll's docker images that is BusyBox `sh`, not bash; the tool's description tells
  the model so.
- **The environment provider describes the agent's machine, not the sandbox.** Agent Framework's
  `ShellEnvironmentProvider` tells the model it is "operating a POSIX shell session on" a description of the operating
  system it reads with Python's `platform.platform()` in the agent's own process, which names the agent's host, not
  plimsoll's Alpine image or the sandbox's kernel. Its `instructions_formatter` option replaces that text.

## Use the code tool

```python
from agent_framework import Agent
from agent_framework_plimsoll import Client, CodeExecutor, plimsoll_code_tool

tool = plimsoll_code_tool(CodeExecutor(Client("https://plimsoll.internal:8746", token=TOKEN)))
agent = Agent(client=chat_client, tools=[tool])
```

The model gets back JSON saying whether the code ran (yes, no with the reason, or unknown), the output, the exit code,
whether anything was cut short or timed out, the isolation tier the code ran behind, and the SHA-256 of the run's
record. The tool never raises: a refusal is information for the model, and Agent Framework ends a request after three
tool errors in a row. `CodeExecutor` requires the `kernel` tier by default. The tool's default language is Python,
which on docker needs a project image with `python3` in it (`SANDBOX_DOCKER_PROJECT_IMAGE=plimsoll/sandbox-python:latest`):
on the default image every Python call comes back refused.

**One web API, if you grant one.** `CodeExecutor(client, grant_profile="lights", api_description=...)`, with a profile
the operator configured on the daemon and the description `plimsoll-specgen` wrote for it, lets the code tool's code call
that profile's routes, and nothing else, through plimsoll's broker, which adds the API's key outside the sandbox.
JavaScript works on every provider that gives a project run a grant; Python too on docker and openshell, through
`import plimsoll_host` (pass `languages=("javascript",)` for a daemon elsewhere: the default, Python, is refused there
when the tool is built). The tool reads the daemon's answer when it is built, offers only the languages that can call
the API there, and tells the model the routes; the model never names a profile. The code can do whatever an allowed
route permits and read whatever it returns
([capability grants (EXTERNAL · source repo ↗)](https://github.com/plimsollmark/plimsoll/blob/main/docs/capability-grants.md#from-an-agent-kits-code-tool)).
The shell tool's session takes no grant.

## What reaches your application

Each command's answer carries what plimsoll states about the call, and nothing of it comes from what the command printed:

- **`await shell.run(command)`** returns a `PlimsollShellResult`, Agent Framework's own `ShellResult` with the tier the
  command ran at (`isolation`), the sentence the provider states beside the tier (`isolation_qualification`, empty when
  it states none), how the run ended (`outcome`), the SHA-256 of the run record the client checked (`record_sha256`)
  and the checked result itself (`result`, whose `record` is the record).
- **Through an agent**, each command's function result keeps the model's text, and its text item's
  `additional_properties` carry the five fields Microsoft's own shell tool puts there (`stdout`, `stderr`, `exit_code`,
  `truncated`, `timed_out`) and plimsoll's labels: `plimsoll_dispatched` (`yes`, `no`, or `unknown` when an error left
  it open), `plimsoll_refused` (the reason, when nothing ran), `plimsoll_outcome`, `plimsoll_isolation`,
  `plimsoll_isolation_qualification` and `plimsoll_record_sha256`. The code tool's function result carries the same
  labels. Each value is checked against the values plimsoll can state and left out if it does not match.
- **A refusal**, which the shell tool raises, reaches a function middleware of yours as the exception itself, with its
  reason in `not_dispatched`; `call_labels(exception)` gives the same labels.

```python
from agent_framework import function_middleware
from agent_framework_plimsoll import call_labels

@function_middleware
async def record_plimsoll(context, call_next):
    try:
        await call_next()
    except Exception as e:
        log.info("refused or lost: %s", call_labels(e))
        raise
    log.info("ran: %s", context.result[0].additional_properties)

agent = create_harness_agent(chat_client, shell_executor=shell, middleware=[record_plimsoll])
```

## Retries

Agent Framework does not run a failed tool call again by itself: a tool's exception becomes one error result for the
model, and three in a row end the request. After a refusal the model may ask for the same command again, which is safe,
since nothing ran; after a command that may have run, the run has already stopped. If you add a retry of your own,
ask `plimsoll_client.retry_on(exception)` first: it says yes only to a refusal plimsoll marked as having run nothing,
when another try may pass (the daemon was at capacity, or could not be reached before anything was sent). Every other
error may have followed the command running, and a second run could repeat what it did.

## Tracing

When Agent Framework's OpenTelemetry instrumentation is on (it is by default) and your application has an OpenTelemetry
SDK recording spans, the framework opens a span for each tool call, and both tools add plimsoll's labels to it as
attributes named `plimsoll.dispatched`, `plimsoll.refused`, `plimsoll.outcome`, `plimsoll.isolation`,
`plimsoll.isolation_qualification` and `plimsoll.record_sha256`, on results and on refusals alike. They never add the
command, the code or the output. Whether the framework itself records a tool's arguments and result on that span is the
framework's own sensitive-data setting, not this package's.

## What it is not

- **Not a hosted service.** You run `plimsolld` on your own machine or cluster, with a provider you pick
  ([isolation tiers (EXTERNAL · source repo ↗)](https://github.com/plimsollmark/plimsoll/blob/main/docs/isolation-tiers.md)).
- **Not attestation.** A reported tier is the daemon's configuration and provider evidence plus a startup check, not
  hardware proof.
- **Not supported:** an interactive terminal; a session reattached from another process (the tool holds its session in
  the process that opened it); a CodeAct provider (Agent Framework's other way to run code, as Microsoft's Hyperlight
  and Monty packages do).

## Versions

This package's version moves with plimsoll's releases, and each version requires the `plimsoll-client` release of the
same number, which holds the code (`plimsoll_client.agent_framework`). `Client`, `CodeExecutor`, `PlimsollShellTool`,
`PlimsollShellResult`, `plimsoll_code_tool` and `call_labels` here are plimsoll-client's own names, gathered so an agent
imports from one place. It is tested with, and installs with, exactly `agent-framework-core` 1.26.0 and exactly
`agent-framework-tools` 1.0.0b261112, the framework's shell tools, a beta released about weekly: pip installs those
versions beside it and refuses others, and each new release of either is tested before its pin moves. The tool marks itself as the agent's shell with a constant from a private module of Agent
Framework (`agent_framework._tools.SHELL_TOOL_KIND_VALUE`), as Microsoft's own `DockerShellTool` does; a framework release
that moves it breaks the import with a message saying so.

Licensed under the Apache License 2.0. Source:
[plimsoll on GitHub (EXTERNAL · source repo ↗)](https://github.com/plimsollmark/plimsoll/tree/main/clients/python/agent-framework-plimsoll).
