Skip to main content

Pydantic AI toolset for inis.run sandboxes

Project description

inis-pydantic-ai

Pydantic AI toolset and capability for inis.run sandboxes.

PyPI License: MIT Python

Beta. Supported Pydantic AI range: >=1.71,<3 (1.71 is the first release with the capabilities API).

Install

pip install inis-pydantic-ai

Quickstart: inis_toolset()

Your app creates (or attaches to) the session and owns INIS_API_KEY; inis_toolset() just hands the model a bounded execution/file surface for it.

import asyncio

from inis import AsyncClient
from inis_pydantic_ai import inis_toolset
from pydantic_ai import Agent

async def main() -> None:
    client = AsyncClient()
    session = await client.sessions.create(egress_default="deny")
    toolset = inis_toolset(session_id=session.session_id)

    agent = Agent(
        "openai:gpt-4o",
        toolsets=[toolset],
        system_prompt="Run Python in the sandbox instead of guessing.",
    )

    try:
        result = await agent.run("What is 19 * 23? Use Python.")
        print(result.output)
    finally:
        await toolset.aclose()  # releases the toolset's local HTTP transport
        await session.destroy()  # this app owns the session; clean it up when done

asyncio.run(main())

session_id is required and inis_toolset() never creates, destroys, or discovers a session on its own — one agent thread maps to one session. To attach to a session another part of your app already owns instead of creating one, pass its ID the same way; this call never destroys it.

What it provides

Tool Description
execute_python Run Python in the sandbox. Raises InisError on non-zero exit.
execute_shell Run a shell command in the persistent session. Raises InisError on non-zero exit.
read_file / write_file File I/O under /workspace.
list_files List a directory (defaults to /workspace).

Opt-in: session administration and one-shot sandboxes

Import from inis_pydantic_ai.lifecycle (not exported at the top level) only if you want the model itself to control these:

from inis_pydantic_ai.lifecycle import inis_ephemeral_toolset, inis_lifecycle_toolset

agent = Agent(
    "openai:gpt-4o",
    toolsets=[
        inis_toolset(session_id=session.session_id),
        inis_lifecycle_toolset(session_id=session.session_id),  # pause/resume/checkpoint/restore/expose/capture
    ],
)
Toolset Tools Hands the model
inis_lifecycle_toolset(session_id=...) pause, resume, checkpoint, restore, expose_port, capture_artifacts Session administration
inis_ephemeral_toolset() execute_once Unbounded throwaway one-shot sandboxes, no session_id needed

InisSandbox capability

A capability (Agent(capabilities=[...])) following the pydantic-ai-harness sandbox contract — run_command, read_file, write_file, list_directory. Binds to one session for the life of the Agent instance rather than creating a fresh sandbox per run.

from inis import AsyncClient
from inis_pydantic_ai.sandbox import InisSandbox
from pydantic_ai import Agent

client = AsyncClient()
session = await client.sessions.create(egress_default="deny")

sandbox = InisSandbox(session=session)
agent = Agent("anthropic:claude-sonnet-5", capabilities=[sandbox])

try:
    result = await agent.run("Write a script that prints the first 10 primes and run it.")
    print(result.output)
finally:
    await sandbox.aclose()  # no-op here — `session` is host-owned
    await session.destroy()

Configuration

inis_toolset(
    session_id="ses_...",         # required
    api_key="inis_...",           # or $INIS_API_KEY
    base_url="https://api.inis.run",
)

Links

Built and run in the EU. Your code and data never leave Europe.

License

MIT — see LICENSE.

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

inis_pydantic_ai-0.1.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

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

inis_pydantic_ai-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file inis_pydantic_ai-0.1.0.tar.gz.

File metadata

  • Download URL: inis_pydantic_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for inis_pydantic_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 422f0d00cbf5ec36b4136577da206f1f1e3cb096f6d67b0fdc2b1c371e3feffe
MD5 c31f66f4a762db80cd68b6d33fa8188b
BLAKE2b-256 80c50089404250ef98e875ab31f66a07a60f6f8a32a03027d1dc864014d124ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for inis_pydantic_ai-0.1.0.tar.gz:

Publisher: sdk-pydantic-ai-publish.yml on 4ver/inis.run

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file inis_pydantic_ai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for inis_pydantic_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff723adc314090ef89a5a12b34685338567c2450fcdd34de7374e5438a486a6a
MD5 77d7da22a8a765620e79abb29707a46d
BLAKE2b-256 cdf6ddba2444d42d1fd0dba2befc2fca4e08c45fef493f34301ee31180922726

See more details on using hashes here.

Provenance

The following attestation bundles were made for inis_pydantic_ai-0.1.0-py3-none-any.whl:

Publisher: sdk-pydantic-ai-publish.yml on 4ver/inis.run

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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