chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
FROM ubuntu:22.04
|
||||
RUN set -eux \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
ca-certificates curl wget gnupg unzip \
|
||||
fuse3 libfuse3-3 nfs-common \
|
||||
&& wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg \
|
||||
&& set -eu; . /etc/os-release; \
|
||||
case "$ID:$VERSION_CODENAME" in \
|
||||
debian:trixie) ms_dist="debian/12/prod"; ms_suite="bookworm" ;; \
|
||||
debian:*) ms_dist="debian/${VERSION_ID%%.*}/prod"; ms_suite="${VERSION_CODENAME:-stable}" ;; \
|
||||
ubuntu:*) ms_dist="ubuntu/${VERSION_ID}/prod"; ms_suite="${VERSION_CODENAME}" ;; \
|
||||
*) ms_dist="ubuntu/22.04/prod"; ms_suite="jammy" ;; \
|
||||
esac; \
|
||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/microsoft.gpg] " \
|
||||
"https://packages.microsoft.com/${ms_dist} ${ms_suite} main" \
|
||||
> /etc/apt/sources.list.d/microsoft-prod.list \
|
||||
&& apt-get update \
|
||||
&& if ! apt-get install -y --no-install-recommends blobfuse2; then \
|
||||
echo "blobfuse2 missing in distro repo; falling back to ubuntu/22.04 repo" >&2; \
|
||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/microsoft.gpg] " \
|
||||
"https://packages.microsoft.com/ubuntu/22.04/prod jammy main" \
|
||||
> /etc/apt/sources.list.d/microsoft-prod.list; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends blobfuse2; \
|
||||
fi \
|
||||
&& arch="$(dpkg --print-architecture)" \
|
||||
&& case "$arch" in \
|
||||
amd64) mp_arch="x86_64" ;; \
|
||||
arm64) mp_arch="arm64" ;; \
|
||||
*) echo "unsupported mount-s3 arch: $arch" >&2; exit 1 ;; \
|
||||
esac \
|
||||
&& url="https://s3.amazonaws.com/mountpoint-s3-release/latest/${mp_arch}/mount-s3.deb" \
|
||||
&& wget -O /tmp/mount-s3.deb "$url" \
|
||||
&& size="$(stat -c %s /tmp/mount-s3.deb)" \
|
||||
&& if [ "$size" -lt 100000 ]; then echo "download too small: $size bytes from $url" >&2; exit 1; fi \
|
||||
&& apt-get install -y /tmp/mount-s3.deb || (apt-get -f install -y && apt-get install -y /tmp/mount-s3.deb) \
|
||||
&& mount-s3 --version \
|
||||
&& curl -fsSL https://amazon-efs-utils.aws.com/efs-utils-installer.sh | sh -s -- --install \
|
||||
&& mount.s3files --version \
|
||||
&& curl -fsSL https://rclone.org/install.sh | bash \
|
||||
&& rclone version \
|
||||
&& touch /etc/fuse.conf \
|
||||
&& grep -qxF 'user_allow_other' /etc/fuse.conf || echo 'user_allow_other' >> /etc/fuse.conf \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/mount-s3.deb
|
||||
@@ -0,0 +1 @@
|
||||
# Docker-specific sandbox examples.
|
||||
@@ -0,0 +1,165 @@
|
||||
"""
|
||||
Start here if you are new to Docker-backed sandbox examples.
|
||||
|
||||
This file keeps the flow explicit:
|
||||
|
||||
1. Build a manifest for the files that should appear in the sandbox workspace.
|
||||
2. Create a sandbox agent that can inspect that workspace through one shell tool.
|
||||
3. Start a Docker-backed sandbox session, stream the run, and print what happens.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from docker import from_env as docker_from_env # type: ignore[import-untyped]
|
||||
from openai.types.responses import ResponseTextDeltaEvent
|
||||
|
||||
from agents import ModelSettings, Runner
|
||||
from agents.run import RunConfig
|
||||
from agents.sandbox import SandboxAgent, SandboxRunConfig
|
||||
from agents.sandbox.config import DEFAULT_PYTHON_SANDBOX_IMAGE
|
||||
from agents.sandbox.sandboxes.docker import DockerSandboxClient, DockerSandboxClientOptions
|
||||
|
||||
if __package__ is None or __package__ == "":
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
|
||||
|
||||
from examples.sandbox.misc.example_support import text_manifest, tool_call_name
|
||||
from examples.sandbox.misc.workspace_shell import WorkspaceShellCapability
|
||||
|
||||
DEFAULT_QUESTION = "Summarize this sandbox project in 2 sentences."
|
||||
MAX_STREAM_TOOL_OUTPUT_CHARS = 2000
|
||||
|
||||
|
||||
def _format_tool_arguments(raw_item: object) -> str | None:
|
||||
arguments = raw_item.get("arguments") if isinstance(raw_item, dict) else None
|
||||
if isinstance(arguments, str) and arguments:
|
||||
return arguments
|
||||
|
||||
action = raw_item.get("action") if isinstance(raw_item, dict) else None
|
||||
commands = action.get("commands") if isinstance(action, dict) else None
|
||||
if isinstance(commands, list):
|
||||
return "; ".join(command for command in commands if isinstance(command, str))
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def _format_tool_call(raw_item: object) -> str:
|
||||
name = tool_call_name(raw_item) or "tool"
|
||||
arguments = _format_tool_arguments(raw_item)
|
||||
if arguments:
|
||||
return f"[tool call] {name}: {arguments}"
|
||||
return f"[tool call] {name}"
|
||||
|
||||
|
||||
def _format_tool_output(output: object) -> str:
|
||||
output_text = str(output)
|
||||
if len(output_text) > MAX_STREAM_TOOL_OUTPUT_CHARS:
|
||||
output_text = f"{output_text[:MAX_STREAM_TOOL_OUTPUT_CHARS]}..."
|
||||
if output_text:
|
||||
return f"[tool output]\n{output_text}"
|
||||
return "[tool output]"
|
||||
|
||||
|
||||
async def main(model: str, question: str) -> None:
|
||||
# A manifest is the starting file tree for the sandbox workspace.
|
||||
# Each key is a path inside the workspace and each value is the file content.
|
||||
# `text_manifest()` keeps small text examples readable by hiding the bytes boilerplate.
|
||||
manifest = text_manifest(
|
||||
{
|
||||
"README.md": (
|
||||
"# Demo Project\n\n"
|
||||
"This sandbox contains a tiny demo project for the sandbox runner.\n"
|
||||
"The goal is to show how Runner can prepare a Docker-backed workspace.\n"
|
||||
),
|
||||
"src/app.py": 'def greet(name: str) -> str:\n return f"Hello, {name}!"\n',
|
||||
"docs/notes.md": (
|
||||
"# Notes\n\n"
|
||||
"- The example is intentionally minimal.\n"
|
||||
"- The model should inspect files through the shell tool.\n"
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
agent = SandboxAgent(
|
||||
name="Docker Sandbox Assistant",
|
||||
model=model,
|
||||
instructions=(
|
||||
"Answer questions about the sandbox workspace. Inspect the project before answering, "
|
||||
"and keep the response concise. "
|
||||
"Do not guess file names like package.json or pyproject.toml. "
|
||||
"This demo intentionally contains a tiny workspace."
|
||||
),
|
||||
# `default_manifest` tells the sandbox agent which workspace it should expect.
|
||||
default_manifest=manifest,
|
||||
# `WorkspaceShellCapability()` exposes one shell tool so the model can inspect files.
|
||||
capabilities=[WorkspaceShellCapability()],
|
||||
# `tool_choice="required"` makes the demo more deterministic by forcing the model
|
||||
# to look at the workspace instead of answering from prior assumptions.
|
||||
model_settings=ModelSettings(tool_choice="required"),
|
||||
)
|
||||
|
||||
# The Docker client owns the container lifecycle for the sandbox session.
|
||||
docker_client = DockerSandboxClient(docker_from_env())
|
||||
|
||||
# `create()` allocates a fresh sandbox session backed by a Docker container.
|
||||
# We pass the same manifest here so the container knows which files to materialize.
|
||||
sandbox = await docker_client.create(
|
||||
manifest=manifest,
|
||||
options=DockerSandboxClientOptions(image=DEFAULT_PYTHON_SANDBOX_IMAGE),
|
||||
)
|
||||
try:
|
||||
# `async with sandbox` keeps the example on the public session lifecycle API.
|
||||
# `Runner` reuses the already-running session without starting it a second time.
|
||||
async with sandbox:
|
||||
# `Runner.run_streamed()` drives the model and yields text and tool events in real time.
|
||||
result = Runner.run_streamed(
|
||||
agent,
|
||||
question,
|
||||
run_config=RunConfig(sandbox=SandboxRunConfig(session=sandbox)),
|
||||
)
|
||||
saw_text_delta = False
|
||||
saw_any_text = False
|
||||
|
||||
# The stream contains raw text deltas from the assistant plus structured tool events.
|
||||
async for event in result.stream_events():
|
||||
if event.type == "raw_response_event" and isinstance(
|
||||
event.data, ResponseTextDeltaEvent
|
||||
):
|
||||
if not saw_text_delta:
|
||||
print("assistant> ", end="", flush=True)
|
||||
saw_text_delta = True
|
||||
print(event.data.delta, end="", flush=True)
|
||||
saw_any_text = True
|
||||
continue
|
||||
|
||||
if event.type != "run_item_stream_event":
|
||||
continue
|
||||
|
||||
if event.name == "tool_called" and event.item.type == "tool_call_item":
|
||||
if saw_text_delta:
|
||||
print()
|
||||
saw_text_delta = False
|
||||
print(_format_tool_call(event.item.raw_item))
|
||||
elif event.name == "tool_output" and event.item.type == "tool_call_output_item":
|
||||
if saw_text_delta:
|
||||
print()
|
||||
saw_text_delta = False
|
||||
print(_format_tool_output(event.item.output))
|
||||
|
||||
if saw_text_delta:
|
||||
print()
|
||||
if not saw_any_text:
|
||||
print(result.final_output)
|
||||
finally:
|
||||
# The client still owns deleting the underlying Docker container.
|
||||
await docker_client.delete(sandbox)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--model", default="gpt-5.6-sol", help="Model name to use.")
|
||||
parser.add_argument("--question", default=DEFAULT_QUESTION, help="Prompt to send to the agent.")
|
||||
args = parser.parse_args()
|
||||
asyncio.run(main(args.model, args.question))
|
||||
@@ -0,0 +1 @@
|
||||
# Docker mount smoke-test examples.
|
||||
@@ -0,0 +1,84 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
if __package__ is None or __package__ == "":
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[4]))
|
||||
|
||||
from agents.sandbox.entries import (
|
||||
AzureBlobMount,
|
||||
DockerVolumeMountStrategy,
|
||||
FuseMountPattern,
|
||||
InContainerMountStrategy,
|
||||
RcloneMountPattern,
|
||||
)
|
||||
from examples.sandbox.docker.mounts.mount_smoke import (
|
||||
MountSmokeCase,
|
||||
require_env,
|
||||
run_mount_smoke_test,
|
||||
)
|
||||
|
||||
|
||||
def _mount_cases() -> list[MountSmokeCase]:
|
||||
account = require_env("AZURE_STORAGE_ACCOUNT")
|
||||
container = require_env("AZURE_STORAGE_CONTAINER")
|
||||
endpoint = os.getenv("AZURE_STORAGE_ENDPOINT")
|
||||
identity_client_id = os.getenv("AZURE_CLIENT_ID")
|
||||
account_key = os.getenv("AZURE_STORAGE_ACCOUNT_KEY")
|
||||
|
||||
return [
|
||||
MountSmokeCase(
|
||||
name="docker_volume/rclone",
|
||||
mount_dir="azure-docker-volume-rclone",
|
||||
mount=AzureBlobMount(
|
||||
account=account,
|
||||
container=container,
|
||||
endpoint=endpoint,
|
||||
identity_client_id=identity_client_id,
|
||||
account_key=account_key,
|
||||
mount_strategy=DockerVolumeMountStrategy(driver="rclone"),
|
||||
read_only=False,
|
||||
),
|
||||
),
|
||||
MountSmokeCase(
|
||||
name="in_container/rclone",
|
||||
mount_dir="azure-in-container-rclone",
|
||||
mount=AzureBlobMount(
|
||||
account=account,
|
||||
container=container,
|
||||
endpoint=endpoint,
|
||||
identity_client_id=identity_client_id,
|
||||
account_key=account_key,
|
||||
mount_strategy=InContainerMountStrategy(pattern=RcloneMountPattern()),
|
||||
read_only=False,
|
||||
),
|
||||
),
|
||||
MountSmokeCase(
|
||||
name="in_container/fuse",
|
||||
mount_dir="azure-in-container-fuse",
|
||||
mount=AzureBlobMount(
|
||||
account=account,
|
||||
container=container,
|
||||
endpoint=endpoint,
|
||||
identity_client_id=identity_client_id,
|
||||
account_key=account_key,
|
||||
mount_strategy=InContainerMountStrategy(pattern=FuseMountPattern()),
|
||||
read_only=False,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_mount_smoke_test(
|
||||
provider="azure",
|
||||
agent_name="Azure Blob Mount Smoke Test",
|
||||
mount_cases=_mount_cases(),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,100 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
if __package__ is None or __package__ == "":
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[4]))
|
||||
|
||||
from agents.sandbox.entries import (
|
||||
DockerVolumeMountStrategy,
|
||||
GCSMount,
|
||||
InContainerMountStrategy,
|
||||
MountpointMountPattern,
|
||||
RcloneMountPattern,
|
||||
)
|
||||
from examples.sandbox.docker.mounts.mount_smoke import (
|
||||
MountSmokeCase,
|
||||
require_env,
|
||||
run_mount_smoke_test,
|
||||
)
|
||||
|
||||
|
||||
def _mount_cases() -> list[MountSmokeCase]:
|
||||
bucket = require_env("GCS_MOUNT_BUCKET")
|
||||
access_id = os.getenv("GCS_ACCESS_ID")
|
||||
secret_access_key = os.getenv("GCS_SECRET_ACCESS_KEY")
|
||||
prefix = os.getenv("GCS_MOUNT_PREFIX")
|
||||
region = os.getenv("GCS_REGION")
|
||||
endpoint_url = os.getenv("GCS_ENDPOINT_URL")
|
||||
service_account_file = os.getenv("GCS_SERVICE_ACCOUNT_FILE")
|
||||
service_account_credentials = os.getenv("GCS_SERVICE_ACCOUNT_CREDENTIALS")
|
||||
access_token = os.getenv("GCS_ACCESS_TOKEN")
|
||||
|
||||
return [
|
||||
MountSmokeCase(
|
||||
name="docker_volume/rclone",
|
||||
mount_dir="gcs-docker-volume-rclone",
|
||||
mount=GCSMount(
|
||||
bucket=bucket,
|
||||
access_id=access_id,
|
||||
secret_access_key=secret_access_key,
|
||||
prefix=prefix,
|
||||
region=region,
|
||||
endpoint_url=endpoint_url,
|
||||
service_account_file=service_account_file,
|
||||
service_account_credentials=service_account_credentials,
|
||||
access_token=access_token,
|
||||
mount_strategy=DockerVolumeMountStrategy(driver="rclone"),
|
||||
read_only=False,
|
||||
),
|
||||
),
|
||||
MountSmokeCase(
|
||||
name="in_container/rclone",
|
||||
mount_dir="gcs-in-container-rclone",
|
||||
mount=GCSMount(
|
||||
bucket=bucket,
|
||||
access_id=access_id,
|
||||
secret_access_key=secret_access_key,
|
||||
prefix=prefix,
|
||||
region=region,
|
||||
endpoint_url=endpoint_url,
|
||||
service_account_file=service_account_file,
|
||||
service_account_credentials=service_account_credentials,
|
||||
access_token=access_token,
|
||||
mount_strategy=InContainerMountStrategy(pattern=RcloneMountPattern()),
|
||||
read_only=False,
|
||||
),
|
||||
),
|
||||
MountSmokeCase(
|
||||
name="in_container/mountpoint",
|
||||
mount_dir="gcs-in-container-mountpoint",
|
||||
mount=GCSMount(
|
||||
bucket=bucket,
|
||||
access_id=access_id,
|
||||
secret_access_key=secret_access_key,
|
||||
prefix=prefix,
|
||||
region=region,
|
||||
endpoint_url=endpoint_url,
|
||||
service_account_file=service_account_file,
|
||||
service_account_credentials=service_account_credentials,
|
||||
access_token=access_token,
|
||||
mount_strategy=InContainerMountStrategy(pattern=MountpointMountPattern()),
|
||||
read_only=False,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_mount_smoke_test(
|
||||
provider="gcs",
|
||||
agent_name="GCS Mount Smoke Test",
|
||||
mount_cases=_mount_cases(),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,153 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import uuid
|
||||
from collections.abc import Sequence
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import docker # type: ignore[import-untyped]
|
||||
|
||||
from agents import ModelSettings, Runner
|
||||
from agents.run import RunConfig
|
||||
from agents.sandbox import Manifest, SandboxAgent, SandboxRunConfig
|
||||
from agents.sandbox.entries import Mount
|
||||
from agents.sandbox.errors import MountCommandError
|
||||
from agents.sandbox.sandboxes.docker import (
|
||||
DockerSandboxClient,
|
||||
DockerSandboxClientOptions,
|
||||
)
|
||||
from agents.sandbox.session.sandbox_session import SandboxSession
|
||||
from examples.sandbox.misc.workspace_shell import WorkspaceShellCapability
|
||||
|
||||
IMAGE = "agents-sandbox-docker-mount-example:latest"
|
||||
DOCKERFILE = Path(__file__).resolve().parent.parent / "Dockerfile.mount"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class MountSmokeCase:
|
||||
"""One mount target to verify inside a shared Docker sandbox session."""
|
||||
|
||||
name: str
|
||||
mount_dir: str
|
||||
mount: Mount
|
||||
|
||||
|
||||
def require_env(name: str) -> str:
|
||||
"""Return a required environment variable or stop with a clear message."""
|
||||
|
||||
value = os.getenv(name)
|
||||
if not value:
|
||||
raise SystemExit(f"Missing required environment variable: {name}")
|
||||
return value
|
||||
|
||||
|
||||
def ensure_mount_image() -> None:
|
||||
"""Build the Docker image with the in-container mount CLIs if it is missing."""
|
||||
|
||||
docker_client = docker.from_env()
|
||||
try:
|
||||
docker_client.images.get(IMAGE)
|
||||
return
|
||||
except docker.errors.ImageNotFound:
|
||||
pass
|
||||
|
||||
print(f"building {IMAGE} from {DOCKERFILE.name}...")
|
||||
docker_client.images.build(
|
||||
path=str(DOCKERFILE.parent),
|
||||
dockerfile=DOCKERFILE.name,
|
||||
tag=IMAGE,
|
||||
rm=True,
|
||||
)
|
||||
|
||||
|
||||
def build_agent(name: str, manifest: Manifest) -> SandboxAgent:
|
||||
"""Create the minimal shell-only agent used by these mount smoke tests."""
|
||||
|
||||
return SandboxAgent(
|
||||
name=name,
|
||||
model=os.getenv("OPENAI_MODEL", "gpt-5.6-sol"),
|
||||
instructions=(
|
||||
"Use the shell tool only. Write the requested exact content to the requested exact "
|
||||
"path, read the file back with cat, and then reply with only `done`."
|
||||
),
|
||||
default_manifest=manifest,
|
||||
capabilities=[WorkspaceShellCapability()],
|
||||
model_settings=ModelSettings(tool_choice="required"),
|
||||
)
|
||||
|
||||
|
||||
async def _check_case(
|
||||
sandbox: SandboxSession,
|
||||
agent: SandboxAgent,
|
||||
provider: str,
|
||||
mount_case: MountSmokeCase,
|
||||
) -> None:
|
||||
key = f"docker-{provider}-mount-example-{mount_case.mount_dir}-{uuid.uuid4().hex}.txt"
|
||||
path = Path("/workspace") / mount_case.mount_dir / key
|
||||
expected = f"hello from {mount_case.name} {uuid.uuid4().hex}"
|
||||
|
||||
result = await Runner.run(
|
||||
agent,
|
||||
(
|
||||
f"Write exactly this content to {path} with `printf %s`, not `echo`: {expected}\n"
|
||||
f"Then read {path} back with cat."
|
||||
),
|
||||
run_config=RunConfig(
|
||||
sandbox=SandboxRunConfig(session=sandbox),
|
||||
workflow_name=f"Docker {provider} mount smoke test ({mount_case.name})",
|
||||
),
|
||||
)
|
||||
print(result.final_output)
|
||||
|
||||
read_back = await sandbox.read(path)
|
||||
actual = read_back.read()
|
||||
if not isinstance(actual, bytes):
|
||||
raise TypeError(f"Expected bytes from session.read(), got {type(actual)!r}")
|
||||
|
||||
actual_text = actual.decode("utf-8")
|
||||
if actual_text == f"{expected}\n":
|
||||
actual_text = expected
|
||||
|
||||
assert actual_text == expected, f"read back {actual!r}, expected {expected!r}"
|
||||
print(f"{mount_case.name}: ok")
|
||||
|
||||
|
||||
async def run_mount_smoke_test(
|
||||
*,
|
||||
provider: str,
|
||||
agent_name: str,
|
||||
mount_cases: Sequence[MountSmokeCase],
|
||||
) -> None:
|
||||
"""Start one Docker sandbox session and verify read/write on every mount target."""
|
||||
|
||||
ensure_mount_image()
|
||||
|
||||
manifest = Manifest(
|
||||
entries={mount_case.mount_dir: mount_case.mount for mount_case in mount_cases},
|
||||
)
|
||||
agent = build_agent(agent_name, manifest)
|
||||
client = DockerSandboxClient(docker.from_env())
|
||||
|
||||
try:
|
||||
sandbox = await client.create(
|
||||
manifest=manifest,
|
||||
options=DockerSandboxClientOptions(image=IMAGE),
|
||||
)
|
||||
except docker.errors.NotFound as exc:
|
||||
if 'plugin "rclone" not found' in str(exc):
|
||||
raise SystemExit("rclone Docker volume plugin not found") from exc
|
||||
raise
|
||||
|
||||
try:
|
||||
await sandbox.start()
|
||||
except MountCommandError as exc:
|
||||
print(f"mount command: {exc.context.get('command')}")
|
||||
print(f"mount stderr: {exc.context.get('stderr')}")
|
||||
raise
|
||||
|
||||
try:
|
||||
for mount_case in mount_cases:
|
||||
await _check_case(sandbox, agent, provider, mount_case)
|
||||
finally:
|
||||
await client.delete(sandbox)
|
||||
@@ -0,0 +1,72 @@
|
||||
"""Smoke-test an Amazon S3 Files file-system mount in Docker.
|
||||
|
||||
Required:
|
||||
|
||||
S3_FILES_FILE_SYSTEM_ID=fs-...
|
||||
|
||||
Common optional settings:
|
||||
|
||||
S3_FILES_MOUNT_TARGET_IP=10.0.0.123
|
||||
AWS_REGION=us-east-1
|
||||
S3_FILES_ACCESS_POINT=fsap-...
|
||||
S3_FILES_SUBPATH=/path/in/file-system
|
||||
|
||||
Example:
|
||||
|
||||
S3_FILES_FILE_SYSTEM_ID=fs-... \
|
||||
S3_FILES_MOUNT_TARGET_IP=10.0.0.123 \
|
||||
AWS_REGION=us-east-1 \
|
||||
uv run python examples/sandbox/docker/mounts/s3_files_mount_read_write.py
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
if __package__ is None or __package__ == "":
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[4]))
|
||||
|
||||
from agents.sandbox.entries import (
|
||||
InContainerMountStrategy,
|
||||
S3FilesMount,
|
||||
S3FilesMountPattern,
|
||||
)
|
||||
from examples.sandbox.docker.mounts.mount_smoke import (
|
||||
MountSmokeCase,
|
||||
require_env,
|
||||
run_mount_smoke_test,
|
||||
)
|
||||
|
||||
|
||||
def _mount_cases() -> list[MountSmokeCase]:
|
||||
file_system_id = require_env("S3_FILES_FILE_SYSTEM_ID")
|
||||
return [
|
||||
MountSmokeCase(
|
||||
name="in_container/s3files",
|
||||
mount_dir="s3-files-in-container",
|
||||
mount=S3FilesMount(
|
||||
file_system_id=file_system_id,
|
||||
subpath=os.getenv("S3_FILES_SUBPATH"),
|
||||
mount_target_ip=os.getenv("S3_FILES_MOUNT_TARGET_IP"),
|
||||
access_point=os.getenv("S3_FILES_ACCESS_POINT"),
|
||||
region=os.getenv("AWS_REGION") or os.getenv("AWS_DEFAULT_REGION"),
|
||||
mount_strategy=InContainerMountStrategy(pattern=S3FilesMountPattern()),
|
||||
read_only=False,
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_mount_smoke_test(
|
||||
provider="s3-files",
|
||||
agent_name="S3 Files Mount Smoke Test",
|
||||
mount_cases=_mount_cases(),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,85 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
if __package__ is None or __package__ == "":
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[4]))
|
||||
|
||||
from agents.sandbox.entries import (
|
||||
DockerVolumeMountStrategy,
|
||||
InContainerMountStrategy,
|
||||
MountpointMountPattern,
|
||||
RcloneMountPattern,
|
||||
S3Mount,
|
||||
)
|
||||
from examples.sandbox.docker.mounts.mount_smoke import (
|
||||
MountSmokeCase,
|
||||
require_env,
|
||||
run_mount_smoke_test,
|
||||
)
|
||||
|
||||
|
||||
def _mount_cases() -> list[MountSmokeCase]:
|
||||
bucket = require_env("S3_MOUNT_BUCKET")
|
||||
return [
|
||||
MountSmokeCase(
|
||||
name="docker_volume/rclone",
|
||||
mount_dir="s3-docker-volume-rclone",
|
||||
mount=S3Mount(
|
||||
bucket=bucket,
|
||||
access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
|
||||
secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
|
||||
session_token=os.getenv("AWS_SESSION_TOKEN"),
|
||||
prefix=os.getenv("S3_MOUNT_PREFIX"),
|
||||
region=os.getenv("AWS_REGION") or os.getenv("AWS_DEFAULT_REGION"),
|
||||
endpoint_url=os.getenv("S3_ENDPOINT_URL"),
|
||||
mount_strategy=DockerVolumeMountStrategy(driver="rclone"),
|
||||
read_only=False,
|
||||
),
|
||||
),
|
||||
MountSmokeCase(
|
||||
name="in_container/rclone",
|
||||
mount_dir="s3-in-container-rclone",
|
||||
mount=S3Mount(
|
||||
bucket=bucket,
|
||||
access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
|
||||
secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
|
||||
session_token=os.getenv("AWS_SESSION_TOKEN"),
|
||||
prefix=os.getenv("S3_MOUNT_PREFIX"),
|
||||
region=os.getenv("AWS_REGION") or os.getenv("AWS_DEFAULT_REGION"),
|
||||
endpoint_url=os.getenv("S3_ENDPOINT_URL"),
|
||||
mount_strategy=InContainerMountStrategy(pattern=RcloneMountPattern()),
|
||||
read_only=False,
|
||||
),
|
||||
),
|
||||
MountSmokeCase(
|
||||
name="in_container/mountpoint",
|
||||
mount_dir="s3-in-container-mountpoint",
|
||||
mount=S3Mount(
|
||||
bucket=bucket,
|
||||
access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
|
||||
secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
|
||||
session_token=os.getenv("AWS_SESSION_TOKEN"),
|
||||
prefix=os.getenv("S3_MOUNT_PREFIX"),
|
||||
region=os.getenv("AWS_REGION") or os.getenv("AWS_DEFAULT_REGION"),
|
||||
endpoint_url=os.getenv("S3_ENDPOINT_URL"),
|
||||
mount_strategy=InContainerMountStrategy(pattern=MountpointMountPattern()),
|
||||
read_only=False,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_mount_smoke_test(
|
||||
provider="s3",
|
||||
agent_name="S3 Mount Smoke Test",
|
||||
mount_cases=_mount_cases(),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user