Skip to main content

ECI-backed sandbox manager with an Agent interface.

Project description

English | 简体中文

eci-as-sandbox

ECI-backed sandbox manager built on alibabacloud-eci20180808 with a lightweight API for managing container-group sandboxes.

Install

pdm add eci-as-sandbox

Environment

The client auto-loads a .env file (searching upward from the working directory). You can also pass env_file=... or explicit credentials.

Required Alibaba Cloud credentials:

set ALIBABA_CLOUD_ACCESS_KEY_ID=...
set ALIBABA_CLOUD_ACCESS_KEY_SECRET=...
set ALIBABA_CLOUD_REGION_ID=cn-shanghai

Optional overrides:

set ECI_SANDBOX_ACCESS_KEY_ID=...
set ECI_SANDBOX_ACCESS_KEY_SECRET=...
set ECI_SANDBOX_REGION_ID=cn-shanghai
set ECI_SANDBOX_ENDPOINT=eci.cn-shanghai.aliyuncs.com
set ECI_SANDBOX_TIMEOUT_MS=60000

If you use a private image, configure registry credentials in ECI.

Quick start (sync)

from eci_as_sandbox import EciSandbox

client = EciSandbox()
result = client.create(
    image="registry.cn-hangzhou.aliyuncs.com/eci_open/nginx:latest",
    name="sandbox-demo",
    cpu=1.0,
    memory=2.0,
    v_switch_id="vsw-xxx",
    security_group_id="sg-xxx",
    ports=[{"port": 8080, "protocol": "TCP"}],
)

if result.success and result.sandbox:
    sandbox = result.sandbox
    info = sandbox.info()
    print(info.data.status)
    sandbox.delete()

Async quick start

import asyncio
from eci_as_sandbox import AsyncEciSandbox


async def main() -> None:
    client = AsyncEciSandbox()
    result = await client.create(
        image="registry.cn-hangzhou.aliyuncs.com/eci_open/nginx:latest",
        name="sandbox-demo",
        cpu=1.0,
        memory=2.0,
        v_switch_id="vsw-xxx",
        security_group_id="sg-xxx",
    )
    if result.success and result.sandbox:
        info = await result.sandbox.info()
        print(info.data.status)


asyncio.run(main())

Command helpers

exec_command runs a list-form command. timeout is in seconds and controls the API read timeout. When sync=True and timeout is set, the command is wrapped to capture output into /tmp, so a timeout still returns the captured output (tailing up to 200 lines).

result = sandbox.exec_command(
    ["/bin/sh", "-c", "for i in 1 2 3; do echo tick-$i; sleep 2; done"],
    timeout=3,
)
print(result.output)

bash runs a shell command via bash -lc and supports exec_dir.

result = sandbox.bash(
    command="pwd; ls -la",
    exec_dir="/tmp",
    timeout=5,
)
print(result.output)

Listing

result = client.list(limit=10, status="Running")
print(result.sandbox_ids)

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

eci_as_sandbox-0.1.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

eci_as_sandbox-0.1.1-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file eci_as_sandbox-0.1.1.tar.gz.

File metadata

  • Download URL: eci_as_sandbox-0.1.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for eci_as_sandbox-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ffa94afba45d56f0c7e7932d39f3cd6396539086f27da114e179dc8f18179864
MD5 fc2eeb505109f72bc79a2cc1817445dd
BLAKE2b-256 91ed9fdd42fbd3ac0b1ba178ddd5d5fbbbca1d8228a619532b7fc6d0f9d262f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for eci_as_sandbox-0.1.1.tar.gz:

Publisher: publish.yml on AndersonBY/eci-as-sandbox

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

File details

Details for the file eci_as_sandbox-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: eci_as_sandbox-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for eci_as_sandbox-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7be46837266376714c4a6a1d286071fee294e3a7b7d39f49addc90c1088aa67
MD5 66575cf1a0e8f93dff91db55a72e1e78
BLAKE2b-256 88eea60afba7715f7a1353c55f08151b1414d3514f8f3f4953a710370e16f933

See more details on using hashes here.

Provenance

The following attestation bundles were made for eci_as_sandbox-0.1.1-py3-none-any.whl:

Publisher: publish.yml on AndersonBY/eci-as-sandbox

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