Class Overview
Desktop Class
Desktop Class
Arguments:
- name (str): A unique name for the container. Defaults to
"newdesktop"
. This should be unique for different containers - docker_image (str): The Docker image name to pull/run if not already available. Defaults to
"spongebox/spongecake:latest"
. - vnc_port (int): The host port mapped to the container’s VNC server. Defaults to 5900.
- api_port (int): The host port mapped to the container’s internal API. Defaults to 8000.
- openai_api_key (str): An optional API key for OpenAI. If not provided, the class attempts to read
OPENAI_API_KEY
from the environment.
- SpongecakeException if any port is in use.
- SpongecakeException if no OpenAI API key is supplied.
Functions
start()
start()
start()
- Starts the docker container thats initialized in the Desktop() constructor
- Checks if a container with the specified
name
already exists. - If the container exists but is not running, it starts it.
Note: In this case, it will not pull the latest image - If the container does not exist, the method attempts to run it:
- It will attempt to pull the latest image before starting the container
- Waits a short time (2 seconds) for services to initialize.
- Returns the running container object.
- A Docker
Container
object representing the running container.
- RuntimeError if it fails to find or pull the specified image
- docker.errors.APIError For any issue with running the container
stop()
stop()
stop()
- Stops + removes the container.
- Prints a status message.
- If the container does not exist, prints a warning.
None
exec(command)
exec(command)
exec(command)
- command (str): The shell command to execute.
- Runs a shell command in the docker container
- Captures stdout and stderr.
- Logs the command output.