OpenShell¶
Backend¶
openshell
¶
OpenShell sandbox backend for agentic-ci.
OpenShellBackend(workdir='.', image=None, policy=None, extra_env=None, approval_mode=None, memory=None, cpu=None, gpu=None, *, harness, sandbox_profile=None)
¶
Bases: Backend
Runs an AI agent inside an OpenShell sandbox.
OpenShell provides security-focused sandboxing with network policy enforcement, filesystem isolation, and Landlock-based access control. Authentication is handled through the OpenShell google-cloud provider, which injects GCP credentials via the supervisor proxy. The agent uses its native Vertex AI integration directly.
Unlike PodmanBackend, which bind-mounts the workdir so changes are
visible immediately on the host, OpenShellBackend copies the workdir
into the sandbox on setup() and copies it back after run() completes.
Only changes inside the workdir are reflected back to the host; files
written elsewhere in the sandbox (e.g. /tmp) are not retrieved. The
host's git control files (.git/config, hooks, info/) are restored
after the download, so the agent's git config never runs on the host.
sandbox_profile (see :mod:agentic_ci.sandbox_profile) is stored on
the backend. In this release only its resources take effect: they
size the sandbox wherever the caller did not pass memory, cpu or
gpu explicitly.
Source code in src/agentic_ci/backends/openshell/__init__.py
Gateway¶
gateway
¶
OpenShell gateway lifecycle management.
is_running()
¶
Check if the OpenShell gateway is registered and healthy.
Source code in src/agentic_ci/backends/openshell/gateway.py
start()
¶
Start the OpenShell gateway with the podman driver.
Starts the podman API socket, generates TLS certificates for sandbox JWT auth, writes a gateway config, launches openshell-gateway in the background, registers it with the CLI, and blocks until the health endpoint responds.
If any step fails after processes have been spawned, cleanup is performed automatically to avoid orphaned processes.
Source code in src/agentic_ci/backends/openshell/gateway.py
stop()
¶
Terminate the gateway and podman service processes.
Deregisters the gateway from the CLI first, then discovers and kills
processes by port and socket rather than requiring stored handles, so
this works across process boundaries (e.g. a separate
agentic-ci stop invocation).
Source code in src/agentic_ci/backends/openshell/gateway.py
Sandbox¶
sandbox
¶
OpenShell sandbox lifecycle management.
exists()
¶
create(image=None, policy_path=None, otel_port=None, workdir='.', approval_mode=None, auth_mode=None, memory=None, cpu=None, gpu=None)
¶
Create a persistent sandbox with the CI provider attached, if auth_mode uses one.
The sandbox is created first, then the network policy is applied
via openshell policy update --wait to ensure the supervisor
has compiled and activated the rules before the agent starts.
memory, cpu and gpu size the sandbox. All three default to
None, which passes no resource flag and leaves the effective limits to
the compute driver and host configuration. An agent that exceeds a memory
limit is OOM-killed by the cgroup, and from inside the sandbox that looks
like the sandbox simply vanishing: the supervisor's log stops mid-line and
the next command reports sandbox is not ready.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str | None
|
Sandbox image to create from. |
None
|
policy_path
|
str | None
|
Path to a network policy file to merge in. |
None
|
otel_port
|
int | None
|
Port for the OTEL collector on the host. |
None
|
workdir
|
str
|
Directory the policy file is resolved relative to. |
'.'
|
approval_mode
|
str | None
|
Enables agent policy proposals when set. |
None
|
memory
|
str | None
|
Memory limit, e.g. |
None
|
cpu
|
str | None
|
CPU limit, e.g. |
None
|
gpu
|
int | None
|
GPU count to request, e.g. |
None
|
Source code in src/agentic_ci/backends/openshell/sandbox.py
upload(local_path)
¶
download(sandbox_path, local_dest)
¶
Download a path from the sandbox to a local destination.
exec_cmd(cmd)
¶
Run a command inside the sandbox. Returns the CompletedProcess.
exec_cmd_streaming(cmd)
¶
Run a command inside the sandbox with stdout piped. Returns a Popen.
Source code in src/agentic_ci/backends/openshell/sandbox.py
Policy¶
policy
¶
Policy resolution for OpenShell sandbox.
resolve_endpoints(flag_path=None, workdir='.', auth_mode=None)
¶
Resolve the endpoint list to use for policy update.
Merges the built-in defaults and endpoints required by auth_mode with extra endpoints from, in priority order:
- Explicit
--policyflag path .agentic-ci/openshell-policy.ymlin workdir
Returns a list of endpoint strings for openshell policy update --add-endpoint.
Source code in src/agentic_ci/backends/openshell/policy.py
build_credential_binding_patch(policy_get_output, provider_name=PROVIDER_NAME)
¶
Patch a policy to add credential_binding on GCP endpoints.
Takes the JSON output of openshell policy get --base -o json
(which wraps the policy under a policy key), extracts the raw
policy, adds credential_binding.provider to GCP endpoints, and
returns the raw policy dict suitable for openshell policy set.
Returns None if no changes are needed.